From aa202878e2e30994b055f744820fa19a57394671 Mon Sep 17 00:00:00 2001 From: Tarion Date: Tue, 19 Mar 2013 21:43:37 -0300 Subject: [PATCH] Added maxCanSpawnInChunk event to allow overriding of creature chunk spawn cap --- .../event/ForgeEventFactory.java | 8 +++++++ .../entity/living/LivingMaxCanSpawnEvent.java | 23 +++++++++++++++++++ .../minecraft/world/SpawnerAnimals.java.patch | 9 +++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 common/net/minecraftforge/event/entity/living/LivingMaxCanSpawnEvent.java diff --git a/common/net/minecraftforge/event/ForgeEventFactory.java b/common/net/minecraftforge/event/ForgeEventFactory.java index 48f774204..e78ac6b33 100644 --- a/common/net/minecraftforge/event/ForgeEventFactory.java +++ b/common/net/minecraftforge/event/ForgeEventFactory.java @@ -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(); + } } diff --git a/common/net/minecraftforge/event/entity/living/LivingMaxCanSpawnEvent.java b/common/net/minecraftforge/event/entity/living/LivingMaxCanSpawnEvent.java new file mode 100644 index 000000000..d41986958 --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/LivingMaxCanSpawnEvent.java @@ -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); + } +} diff --git a/patches/minecraft/net/minecraft/world/SpawnerAnimals.java.patch b/patches/minecraft/net/minecraft/world/SpawnerAnimals.java.patch index aab5f13a5..1d6b4ae23 100644 --- a/patches/minecraft/net/minecraft/world/SpawnerAnimals.java.patch +++ b/patches/minecraft/net/minecraft/world/SpawnerAnimals.java.patch @@ -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 {