Allow to check spawner block entity in events (#7941)

This commit is contained in:
StrikerRocker (Tharik Sherief) authored and GitHub committed 2021-08-18 02:15:57 -07:00
1 parent 1018b077dc
commit ce13efbac9
4 files changed
+62 -4

No files matched your search

@@ -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; }
}
@@ -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_) {
@@ -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);
}
}
}
}
+2
View File
@@ -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