diff --git a/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch b/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch index c3a15235c8..75f0f9b3ad 100644 --- a/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch +++ b/patches/minecraft/net/minecraft/world/level/BaseSpawner.java.patch @@ -14,14 +14,16 @@ ((Mob)entity).m_6518_(p_151312_, p_151312_.m_6436_(entity.m_142538_()), MobSpawnType.SPAWNER, (SpawnGroupData)null, (CompoundTag)null); } } -@@ -271,5 +_,10 @@ - +@@ -272,4 +_,12 @@ public double m_45474_() { return this.f_45446_; -+ } + } + + @Nullable + public Entity getSpawnerEntity() { + return null; - } ++ } ++ ++ @Nullable ++ public net.minecraft.world.level.block.entity.BlockEntity getSpawnerBlockEntity(){ return null; } } diff --git a/patches/minecraft/net/minecraft/world/level/block/entity/SpawnerBlockEntity.java.patch b/patches/minecraft/net/minecraft/world/level/block/entity/SpawnerBlockEntity.java.patch new file mode 100644 index 0000000000..b43991b7b0 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/level/block/entity/SpawnerBlockEntity.java.patch @@ -0,0 +1,12 @@ +--- a/net/minecraft/world/level/block/entity/SpawnerBlockEntity.java ++++ b/net/minecraft/world/level/block/entity/SpawnerBlockEntity.java +@@ -25,6 +_,9 @@ + } + + } ++ ++ @javax.annotation.Nullable ++ public net.minecraft.world.level.block.entity.BlockEntity getSpawnerBlockEntity(){ return SpawnerBlockEntity.this; } + }; + + public SpawnerBlockEntity(BlockPos p_155752_, BlockState p_155753_) { diff --git a/src/test/java/net/minecraftforge/debug/entity/CheckSpawnEventTest.java b/src/test/java/net/minecraftforge/debug/entity/CheckSpawnEventTest.java new file mode 100644 index 0000000000..782004bae2 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/entity/CheckSpawnEventTest.java @@ -0,0 +1,42 @@ +package net.minecraftforge.debug.entity; + +import net.minecraft.world.entity.vehicle.MinecartSpawner; +import net.minecraft.world.level.block.entity.SpawnerBlockEntity; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.LivingSpawnEvent; +import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@Mod("check_spawn_event_test") +public class CheckSpawnEventTest +{ + public static final boolean ENABLE = true; + public static final Logger LOGGER = LogManager.getLogger(); + + public CheckSpawnEventTest() + { + if (ENABLE) + MinecraftForge.EVENT_BUS.register(this); + } + + @SubscribeEvent + public void checkSpawn(LivingSpawnEvent.CheckSpawn event) + { + if (event.isSpawner()) + { + if (event.getSpawner().getSpawnerBlockEntity() instanceof SpawnerBlockEntity) + { + LOGGER.info("Stopped {} from spawning from Spawner Block Entity : {}", event.getEntity(), event.getSpawner().getSpawnerBlockEntity()); + event.setResult(Event.Result.DENY); + } + if (event.getSpawner().getSpawnerEntity() instanceof MinecartSpawner) + { + LOGGER.info("Stopped {} from spawning from Minecart Spawner : {}", event.getEntity(), event.getSpawner().getSpawnerEntity()); + event.setResult(Event.Result.DENY); + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index f3cde6fec2..4ca74069c9 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -144,5 +144,7 @@ license="LGPL v2.1" modId="send_datapacks_to_client" [[mods]] modId="tag_based_tool_types" +[[mods]] + modId="check_spawn_event_test" # ADD ABOVE THIS LINE