Added maxCanSpawnInChunk event to allow overriding of creature chunk spawn cap

This commit is contained in:
Tarion 2013-03-19 21:43:37 -03:00 committed by Christian
parent a44bd6dadf
commit aa202878e2
3 changed files with 39 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.living.LivingMaxCanSpawnEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
@ -67,4 +68,11 @@ public class ForgeEventFactory
}
return event.list;
}
public static int getMaxSpawnedInChunk(EntityLiving entity)
{
LivingMaxCanSpawnEvent maxCanSpawnEvent = new LivingMaxCanSpawnEvent(entity);
MinecraftForge.EVENT_BUS.post(maxCanSpawnEvent);
return maxCanSpawnEvent.getResult() == Result.ALLOW ? maxCanSpawnEvent.maxSpawnInChunk : entity.getMaxSpawnedInChunk();
}
}

View file

@ -0,0 +1,23 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLiving;
import net.minecraftforge.event.Event.HasResult;
@HasResult
public class LivingMaxCanSpawnEvent extends LivingEvent
{
/**
* This event is fired when the spawning system tries to determine the
* maximum amount of the entity can spawn in a chunk.
*
* If you set the result to 'ALLOW', it means that you want to return
* the value of maxSpawnInChunk as the maximum amount allowed in the
* chunk.
*/
public int maxSpawnInChunk;
public LivingMaxCanSpawnEvent(EntityLiving entity)
{
super(entity);
}
}

View file

@ -33,7 +33,7 @@
label110:
while (iterator.hasNext())
@@ -169,7 +178,8 @@
@@ -169,13 +178,14 @@
entityliving.setLocationAndAngles((double)f, (double)f1, (double)f2, par0WorldServer.rand.nextFloat() * 360.0F, 0.0F);
@ -43,6 +43,13 @@
{
++j2;
par0WorldServer.spawnEntityInWorld(entityliving);
creatureSpecificInit(entityliving, par0WorldServer, f, f1, f2);
- if (j2 >= entityliving.getMaxSpawnedInChunk())
+ if (j2 >= ForgeEventFactory.getMaxSpawnedInChunk(entityliving))
{
continue label110;
}
@@ -221,7 +231,8 @@
else
{