Fire LivingSpawnEvents for MobSpawners. Closes #2079

This commit is contained in:
LexManos 2016-05-28 20:13:03 -07:00
parent 357d2f8d86
commit debe0ffdf8
3 changed files with 30 additions and 11 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -6,8 +6,8 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
/**
* LivingSpawnEvent is fired whenever a living Entity is spawned. <br>
* 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. <br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the world in which this living Entity is being spawned.<br>
@ -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.<br>
* This event is fired whenever an Entity is spawned in a mob spawner in<br>
* SpawnerAnimals#findChunksForSpawning(WorldServer, boolean, boolean, boolean).<br>
* SpecialSpawn is fired when an Entity is to be spawned.<br>
* This allows you to do special inializers in the new entity.<br>
* <br>
* This event is fired via the {@link ForgeHooks#doSpecialSpawn(EntityLiving, World, float, float, float)}.<br>
* <br>
@ -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 <em>if</em> 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);
}
}
}