diff --git a/patchwork-event-dispatcher/build.gradle b/patchwork-event-dispatcher/build.gradle new file mode 100644 index 00000000..d0b5d7e7 --- /dev/null +++ b/patchwork-event-dispatcher/build.gradle @@ -0,0 +1,10 @@ +archivesBaseName = "patchwork-event-dispatcher" +version = getSubprojectVersion(project, "0.1.0") + +dependencies { + compile project(path: ':patchwork-events-entity', configuration: 'dev') + compile project(path: ':patchwork-events-lifecycle', configuration: 'dev') + compile project(path: ':patchwork-events-rendering', configuration: 'dev') + compile project(path: ':patchwork-events-world', configuration: 'dev') + compile project(path: ':patchwork-fml', configuration: 'dev') +} diff --git a/patchwork-event-dispatcher/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/client/ForgeHooksClient.java new file mode 100644 index 00000000..8a8c8d9a --- /dev/null +++ b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -0,0 +1,47 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.client; + +import java.util.Set; + +import net.minecraft.client.color.block.BlockColors; +import net.minecraft.client.color.item.ItemColors; +import net.minecraft.client.texture.SpriteAtlasTexture; +import net.minecraft.util.Identifier; + +import net.patchworkmc.impl.event.render.RenderEvents; + +public class ForgeHooksClient { + public static void onBlockColorsInit(BlockColors blockColors) { + RenderEvents.onBlockColorsInit(blockColors); + } + + public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) { + RenderEvents.onItemColorsInit(itemColors, blockColors); + } + + public static void onTextureStitchedPre(SpriteAtlasTexture map, Set resourceLocations) { + RenderEvents.onTextureStitchPre(map, resourceLocations); + } + + public static void onTextureStitchedPost(SpriteAtlasTexture map) { + RenderEvents.onTextureStitchPost(map); + } +} diff --git a/patchwork-event-dispatcher/src/main/java/net/minecraftforge/common/ForgeHooks.java b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/common/ForgeHooks.java new file mode 100644 index 00000000..ab53e5d8 --- /dev/null +++ b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -0,0 +1,107 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.common; + +import java.util.List; + +import javax.annotation.Nullable; + +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.eventbus.api.Event.Result; + +import net.minecraft.entity.EntityCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.level.LevelInfo; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnType; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.world.IWorld; +import net.minecraft.world.MobSpawnerLogic; + +import net.patchworkmc.impl.event.entity.EntityEvents; +import net.patchworkmc.impl.event.world.WorldEvents; + +public class ForgeHooks { + public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) { + Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason); + return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1; + } + + // TODO: onInteractEntityAt + + public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) { + return EntityEvents.onInteractEntity(player, entity, hand); + } + + public static boolean onLivingDeath(LivingEntity entity, DamageSource src) { + return EntityEvents.onLivingDeath(entity, src); + } + + public static boolean onLivingUpdate(LivingEntity entity) { + return EntityEvents.onLivingUpdateEvent(entity); + } + + // TODO: forge calls the equivilant to this in LivingEntity, but patchwork only calls the equivilant to onPlayerAttack + public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) { + return entity instanceof PlayerEntity || onPlayerAttack(entity, src, amount); + } + + public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) { + return !EntityEvents.onLivingAttack(entity, src, amount); + } + + // optifine wants this? O.o + public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) { + EntityEvents.onLivingSetAttackTarget(entity, target); + } + + public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount) { + return EntityEvents.onLivingHurt(entity, src, amount); + } + + @Nullable + public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) { + return EntityEvents.onLivingFall(entity, distance, damageMultiplier); + } + + public static float onLivingDamage(LivingEntity entity, DamageSource src, float amount) { + return EntityEvents.onLivingDamage(entity, src, amount); + } + + public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) { + return EntityEvents.attackEntity(player, target); + } + + public static boolean onCreateWorldSpawn(World world, LevelInfo settings) { + return WorldEvents.onCreateWorldSpawn(world, settings); + } + + @Nullable + public static List getPotentialSpawns(IWorld world, EntityCategory type, BlockPos pos, List oldList) { + return WorldEvents.getPotentialSpawns(world, type, pos, oldList); + } +} diff --git a/patchwork-event-dispatcher/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/event/ForgeEventFactory.java new file mode 100644 index 00000000..fcdeefed --- /dev/null +++ b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -0,0 +1,49 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.event; + +import net.minecraftforge.eventbus.api.Event.Result; + +import net.minecraft.entity.SpawnType; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.IWorld; +import net.minecraft.world.MobSpawnerLogic; +import net.minecraft.world.World; + +import net.patchworkmc.impl.event.entity.EntityEvents; + +public class ForgeEventFactory { + public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) { + return EntityEvents.canEntitySpawn(entity, world, x, y, z, spawner, spawnReason); + } + + public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner) { + return EntityEvents.canEntitySpawnFromSpawner(entity, world, x, y, z, spawner); + } + + public static void onPlayerFall(PlayerEntity player, float distance, float multiplier) { + EntityEvents.onFlyablePlayerFall(player, distance, multiplier); + } + + public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, MobSpawnerLogic spawner, SpawnType spawnReason) { + return EntityEvents.doSpecialSpawn(entity, world, x, y, z, spawner, spawnReason); + } +} diff --git a/patchwork-event-dispatcher/src/main/java/net/minecraftforge/fml/hooks/BasicEventHooks.java b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/fml/hooks/BasicEventHooks.java new file mode 100644 index 00000000..63dbec24 --- /dev/null +++ b/patchwork-event-dispatcher/src/main/java/net/minecraftforge/fml/hooks/BasicEventHooks.java @@ -0,0 +1,101 @@ +/* + * Minecraft Forge, Patchwork Project + * Copyright (c) 2016-2020, 2019-2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.fml.hooks; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.World; + +import net.patchworkmc.impl.event.entity.EntityEvents; +import net.patchworkmc.impl.event.lifecycle.LifecycleEvents; + +public class BasicEventHooks { + // public static void firePlayerChangedDimensionEvent(PlayerEntity player, DimensionType fromDim, DimensionType toDim) { + // + // } + + public static void firePlayerLoggedIn(PlayerEntity player) { + EntityEvents.onPlayerLoggedIn(player); + } + + // public static void firePlayerLoggedOut(PlayerEntity player) { + // + // } + + // public static void firePlayerRespawnEvent(PlayerEntity player, boolean endConquered) { + // + // } + + // public static void firePlayerItemPickupEvent(PlayerEntity player, ItemEntity item, ItemStack clone) { + // + // } + + // public static void firePlayerCraftingEvent(PlayerEntity player, ItemStack crafted, Inventory craftMatrix) { + // + // } + + // public static void firePlayerSmeltedEvent(PlayerEntity player, ItemStack smelted) { + // + // } + + // public static void onRenderTickStart(float timer) { + // + // } + + // public static void onRenderTickEnd(float timer) { + // + // } + + public static void onPlayerPreTick(PlayerEntity player) { + LifecycleEvents.onPlayerPreTick(player); + } + + public static void onPlayerPostTick(PlayerEntity player) { + LifecycleEvents.onPlayerPostTick(player); + } + + public static void onPreWorldTick(World world) { + LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, world); + } + + public static void onPostWorldTick(World world) { + LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.END, world); + } + + // TODO: unlike almost everything else in this class, this doesn't delegate to a module specific method implementation. + public static void onPreClientTick() { + MinecraftForge.EVENT_BUS.post(new TickEvent.ClientTickEvent(TickEvent.Phase.START)); + } + + // TODO: unlike almost everything else in this class, this doesn't delegate to a module specific method implementation. + public static void onPostClientTick() { + MinecraftForge.EVENT_BUS.post(new TickEvent.ClientTickEvent(TickEvent.Phase.END)); + } + + // public static void onPreServerTick() { + // + // } + + // public static void onPostServerTick() { + // + // } +} diff --git a/patchwork-event-dispatcher/src/main/resources/assets.patchwork-event-dispatcher/icon.png b/patchwork-event-dispatcher/src/main/resources/assets.patchwork-event-dispatcher/icon.png new file mode 100644 index 00000000..de75d2fb Binary files /dev/null and b/patchwork-event-dispatcher/src/main/resources/assets.patchwork-event-dispatcher/icon.png differ diff --git a/patchwork-event-dispatcher/src/main/resources/fabric.mod.json b/patchwork-event-dispatcher/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..2153399f --- /dev/null +++ b/patchwork-event-dispatcher/src/main/resources/fabric.mod.json @@ -0,0 +1,27 @@ +{ + "schemaVersion": 1, + "id": "patchwork-event-dispatcher", + "name": "Patchwork Event Dispatcher", + "version": "${version}", + "description": "Implements ForgeHooks, ForgeEventFactory, and more.", + "environment": "*", + "license": "LGPL-2.1-only", + "icon": "assets/patchwork-event-dispatcher/icon.png", + "contact": { + "issues": "https://github.com/PatchworkMC/patchwork-api/issues", + "sources": "https://github.com/PatchworkMC/patchwork-api" + }, + "authors": [ + "PatchworkMC" + ], + "depends": { + "fabricloader": ">=0.8.4", + "patchwork-fml": "*", + "patchwork-events-entity": "*", + "patchwork-events-lifecycle": "*" + }, + "custom": { + "modmenu:api": true, + "modmenu:parent": "patchwork" + } +} diff --git a/patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/EntityEvents.java b/patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/EntityEvents.java index 3c753fd4..d16a4799 100644 --- a/patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/EntityEvents.java +++ b/patchwork-events-entity/src/main/java/net/patchworkmc/impl/event/entity/EntityEvents.java @@ -49,7 +49,6 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.world.IWorld; @@ -92,7 +91,7 @@ public static void onEnteringChunk(Entity entity, int newChunkX, int newChunkZ, } // PlayerEvents - public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) { + public static void onPlayerLoggedIn(PlayerEntity playerEntity) { MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity)); } diff --git a/patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java b/patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java index 9f194790..75e57381 100644 --- a/patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java +++ b/patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java @@ -21,6 +21,8 @@ import net.minecraft.server.MinecraftServer; +import net.patchworkmc.impl.event.lifecycle.LifecycleEvents; + /** * This is a stub of the ServerLifecycleHooks class in Forge for mods that use getCurrentServer. */ @@ -30,4 +32,18 @@ public class ServerLifecycleHooks { public static MinecraftServer getCurrentServer() { return currentServer; } + + public static boolean handleServerAboutToStart(final MinecraftServer server) { + LifecycleEvents.handleServerAboutToStart(server); + return true; // patchwork does not allow you to cancel server startup. + } + + public static boolean handleServerStarting(final MinecraftServer server) { + LifecycleEvents.handleServerStarting(server); + return true; // patchwork does not allow you to cancel server startup. + } + + public static void handleServerStarted(final MinecraftServer server) { + LifecycleEvents.handleServerStarted(server); + } } diff --git a/settings.gradle b/settings.gradle index 4237a3d1..19f8da24 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,6 +17,7 @@ include 'patchwork-capabilities' include 'patchwork-data-generators' include 'patchwork-dispatcher' include 'patchwork-enum-hacks' +include 'patchwork-event-dispatcher' include 'patchwork-events-entity' include 'patchwork-events-input' include 'patchwork-events-lifecycle'