From debe0ffdf8d85a4f87368743b144533ba33e731e Mon Sep 17 00:00:00 2001 From: LexManos Date: Sat, 28 May 2016 20:13:03 -0700 Subject: [PATCH] Fire LivingSpawnEvents for MobSpawners. Closes #2079 --- .../tileentity/MobSpawnerBaseLogic.java.patch | 18 ++++++++++++++++ .../event/ForgeEventFactory.java | 2 ++ .../event/entity/living/LivingSpawnEvent.java | 21 +++++++++---------- 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch diff --git a/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch b/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch new file mode 100644 index 0000000000..f20307a0cb --- /dev/null +++ b/patches/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java.patch @@ -0,0 +1,18 @@ +--- ../src-base/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java ++++ ../src-work/minecraft/net/minecraft/tileentity/MobSpawnerBaseLogic.java +@@ -117,10 +117,14 @@ + EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null; + entity.func_70012_b(entity.field_70165_t, entity.field_70163_u, entity.field_70161_v, world.field_73012_v.nextFloat() * 360.0F, 0.0F); + +- if (entityliving == null || entityliving.func_70601_bi() && entityliving.func_70058_J()) ++ net.minecraftforge.fml.common.eventhandler.Event.Result canSpawn = net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(entityliving, this.func_98271_a(), (float)entity.field_70165_t, (float)entity.field_70163_u, (float)entity.field_70161_v); ++ boolean force = canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW || ++ (canSpawn == net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT && (entityliving.func_70601_bi() && entityliving.func_70058_J())); ++ if (entityliving == null || force) + { + if (this.field_98282_f.func_185277_b().func_186856_d() == 1 && this.field_98282_f.func_185277_b().func_150297_b("id", 8) && entity instanceof EntityLiving) + { ++ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(entityliving, this.func_98271_a(), (float)entity.field_70165_t, (float)entity.field_70163_u, (float)entity.field_70161_v)) + ((EntityLiving)entity).func_180482_a(world.func_175649_E(new BlockPos(entity)), (IEntityLivingData)null); + } + diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index df9a87497e..e0c99129b2 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -135,6 +135,8 @@ public class ForgeEventFactory public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z) { + if (entity == null) + return Result.DEFAULT; LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z); MinecraftForge.EVENT_BUS.post(event); return event.getResult(); diff --git a/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java b/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java index 6a538b21b0..168e67fedb 100644 --- a/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java @@ -6,8 +6,8 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.world.World; /** - * LivingSpawnEvent is fired whenever a living Entity is spawned.
- * If a method utilizes this {@link Event} as its parameter, the method will + * LivingSpawnEvent is fired for any events associated with Living Enttnies spawn status.
+ * If a method utilizes this {@link Event} as its parameter, the method will * receive every child event of this class.
*
* {@link #world} contains the world in which this living Entity is being spawned.
@@ -23,7 +23,7 @@ public class LivingSpawnEvent extends LivingEvent private final float x; private final float y; private final float z; - + public LivingSpawnEvent(EntityLiving entity, World world, float x, float y, float z) { super(entity); @@ -39,7 +39,7 @@ public class LivingSpawnEvent extends LivingEvent public float getZ() { return z; } /** * Fires before mob spawn events. - * + * * Result is significant: * DEFAULT: use vanilla spawn rules * ALLOW: allow the spawn @@ -56,9 +56,8 @@ public class LivingSpawnEvent extends LivingEvent } /** - * SpecialSpawn is fired when an Entity is to be spawned from a mob spawner.
- * This event is fired whenever an Entity is spawned in a mob spawner in
- * SpawnerAnimals#findChunksForSpawning(WorldServer, boolean, boolean, boolean).
+ * SpecialSpawn is fired when an Entity is to be spawned.
+ * This allows you to do special inializers in the new entity.
*
* This event is fired via the {@link ForgeHooks#doSpecialSpawn(EntityLiving, World, float, float, float)}.
*
@@ -77,17 +76,17 @@ public class LivingSpawnEvent extends LivingEvent super(entity, world, x, y, z); } } - + /** * Fired each tick for despawnable mobs to allow control over despawning. * {@link Result#DEFAULT} will pass the mob on to vanilla despawn mechanics. * {@link Result#ALLOW} will force the mob to despawn. * {@link Result#DENY} will force the mob to remain. * This is fired every tick for every despawnable entity. Be efficient in your handlers. - * + * * Note: this is not fired if the mob is definitely going to otherwise despawn. It is fired to check if * the mob can be allowed to despawn. See {@link EntityLiving#despawnEntity} - * + * * @author cpw * */ @@ -98,6 +97,6 @@ public class LivingSpawnEvent extends LivingEvent { super(entity, entity.worldObj, (float)entity.posX, (float)entity.posY, (float)entity.posZ); } - + } } \ No newline at end of file