From a9237cff750549a272933e230b5f2b55a90d87f5 Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 22 Feb 2022 14:18:52 -0800 Subject: [PATCH] Fix Mob Spawner logic with CustomSpawnRules. Closes #8398 --- .../net/minecraft/world/level/BaseSpawner.java.patch | 10 ++++++---- .../net/minecraftforge/event/ForgeEventFactory.java | 8 +++++++- .../event/entity/living/LivingSpawnEvent.java | 8 +++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch b/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch index e9df4d2f66..3beb06444a 100644 --- a/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch +++ b/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch @@ -1,16 +1,18 @@ --- a/net/minecraft/world/level/BaseSpawner.java +++ b/net/minecraft/world/level/BaseSpawner.java -@@ -125,11 +_,12 @@ +@@ -125,11 +_,15 @@ entity.m_7678_(entity.m_20185_(), entity.m_20186_(), entity.m_20189_(), p_151312_.f_46441_.nextFloat() * 360.0F, 0.0F); if (entity instanceof Mob) { Mob mob = (Mob)entity; -- if (this.f_45444_.m_186574_().isEmpty() && !mob.m_5545_(p_151312_, MobSpawnType.SPAWNER) || !mob.m_6914_(p_151312_)) { -+ if (!net.minecraftforge.event.ForgeEventFactory.canEntitySpawnSpawner(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this)) { ++ net.minecraftforge.eventbus.api.Event.Result res = net.minecraftforge.event.ForgeEventFactory.canEntitySpawn(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER); ++ if (res == net.minecraftforge.eventbus.api.Event.Result.DENY) continue; ++ if (res == net.minecraftforge.eventbus.api.Event.Result.DEFAULT) + if (this.f_45444_.m_186574_().isEmpty() && !mob.m_5545_(p_151312_, MobSpawnType.SPAWNER) || !mob.m_6914_(p_151312_)) { continue; } if (this.f_45444_.m_186567_().m_128440_() == 1 && this.f_45444_.m_186567_().m_128425_("id", 8)) { -+ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(mob, p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER)) ++ if (!net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn(mob, (LevelAccessor)p_151312_, (float)entity.m_20185_(), (float)entity.m_20186_(), (float)entity.m_20189_(), this, MobSpawnType.SPAWNER)) ((Mob)entity).m_6518_(p_151312_, p_151312_.m_6436_(entity.m_142538_()), MobSpawnType.SPAWNER, (SpawnGroupData)null, (CompoundTag)null); } } diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index 3338162993..f3c0e89671 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -204,6 +204,7 @@ public class ForgeEventFactory return event.getResult(); } + @Deprecated(forRemoval = true, since = "1.18.1") public static boolean canEntitySpawnSpawner(Mob entity, Level world, float x, float y, float z, BaseSpawner spawner) { Result result = canEntitySpawn(entity, world, x, y, z, spawner, MobSpawnType.SPAWNER); @@ -213,7 +214,12 @@ public class ForgeEventFactory return result == Result.ALLOW; } + @Deprecated(forRemoval = true, since = "1.18.1") public static boolean doSpecialSpawn(Mob entity, Level world, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason) + { + return doSpecialSpawn(entity, (LevelAccessor)world, x, y, z, spawner, spawnReason); + } + public static boolean doSpecialSpawn(Mob entity, LevelAccessor world, float x, float y, float z, BaseSpawner spawner, MobSpawnType spawnReason) { return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnReason)); } @@ -255,7 +261,7 @@ public class ForgeEventFactory MinecraftForge.EVENT_BUS.post(event); return event.getDisplayname(); } - + public static Component getPlayerTabListDisplayName(Player player) { PlayerEvent.TabListNameFormat event = new PlayerEvent.TabListNameFormat(player); 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 dff78bf5e5..1405512855 100644 --- a/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/living/LivingSpawnEvent.java @@ -118,7 +118,7 @@ public class LivingSpawnEvent extends LivingEvent * 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 ForgeEventFactory#doSpecialSpawn(Mob, Level, float, float, float, BaseSpawner, MobSpawnType)}.
+ * This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(Mob, LevelAccessor, float, float, float, BaseSpawner, MobSpawnType)}.
*
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.
* If this event is canceled, the Entity is not spawned.
@@ -137,7 +137,13 @@ public class LivingSpawnEvent extends LivingEvent /** * @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any */ + @Deprecated(forRemoval = true, since = "1.18.1") public SpecialSpawn(Mob entity, Level world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason) + { + this(entity, (LevelAccessor)world, x, y, z, spawner, spawnReason); + } + + public SpecialSpawn(Mob entity, LevelAccessor world, double x, double y, double z, @Nullable BaseSpawner spawner, MobSpawnType spawnReason) { super(entity, world, x, y, z); this.spawner = spawner;