diff --git a/src/main/java/dev/latvian/mods/kubejs/entity/CheckLivingEntitySpawnKubeEvent.java b/src/main/java/dev/latvian/mods/kubejs/entity/CheckLivingEntitySpawnKubeEvent.java index 63889bedc..296b60adf 100644 --- a/src/main/java/dev/latvian/mods/kubejs/entity/CheckLivingEntitySpawnKubeEvent.java +++ b/src/main/java/dev/latvian/mods/kubejs/entity/CheckLivingEntitySpawnKubeEvent.java @@ -10,6 +10,7 @@ import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @Info(""" @@ -60,8 +61,8 @@ public MobSpawnType getType() { return type; } - @Info("The spawner that spawned the entity. Can be null if the entity was spawned by worldgen.") - @Nullable + @Info("The spawner that spawned the entity.") + @NotNull public SpawnerJS getSpawner() { if (spawner == null) { spawner = SpawnerJS.of(spawnerEither); diff --git a/src/main/java/dev/latvian/mods/kubejs/level/SpawnerJS.java b/src/main/java/dev/latvian/mods/kubejs/level/SpawnerJS.java index 81ef01298..55513c039 100644 --- a/src/main/java/dev/latvian/mods/kubejs/level/SpawnerJS.java +++ b/src/main/java/dev/latvian/mods/kubejs/level/SpawnerJS.java @@ -7,6 +7,10 @@ public record SpawnerJS(@Nullable Entity entity, @Nullable BlockContainerJS block) { public static SpawnerJS of(Either spawner) { + if (spawner == null) { + return new SpawnerJS(null, null); + } + var e = spawner.right().orElse(null); if (e != null) { @@ -21,4 +25,8 @@ public static SpawnerJS of(Either spawner) { return new SpawnerJS(null, null); } + + public boolean isWorldgen() { + return entity == null && block == null; + } } diff --git a/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java b/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java index 7b5da4336..655602f48 100644 --- a/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java +++ b/src/main/java/dev/latvian/mods/kubejs/server/KubeJSServerEventHandler.java @@ -5,6 +5,7 @@ import dev.latvian.mods.kubejs.bindings.event.ServerEvents; import dev.latvian.mods.kubejs.command.CommandRegistryKubeEvent; import dev.latvian.mods.kubejs.command.KubeJSCommands; +import dev.latvian.mods.kubejs.gui.chest.CustomChestMenu; import dev.latvian.mods.kubejs.level.SimpleLevelKubeEvent; import dev.latvian.mods.kubejs.script.PlatformWrapper; import dev.latvian.mods.kubejs.script.ScriptType; @@ -17,6 +18,7 @@ import net.minecraft.nbt.NbtAccounter; import net.minecraft.nbt.NbtIo; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.LevelResource; @@ -24,9 +26,11 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.loading.FMLEnvironment; +import net.neoforged.neoforge.common.util.TriState; import net.neoforged.neoforge.event.AddReloadListenerEvent; import net.neoforged.neoforge.event.CommandEvent; import net.neoforged.neoforge.event.RegisterCommandsEvent; +import net.neoforged.neoforge.event.entity.player.ItemEntityPickupEvent; import net.neoforged.neoforge.event.level.LevelEvent; import net.neoforged.neoforge.event.server.ServerAboutToStartEvent; import net.neoforged.neoforge.event.server.ServerStartingEvent; @@ -173,4 +177,13 @@ public static void command(CommandEvent event) { public static void addReloadListeners(AddReloadListenerEvent event) { event.addListener(new KubeJSReloadListener(event.getServerResources())); } + + @SubscribeEvent + public static void preventPickupDuringChestGUI(ItemEntityPickupEvent.Pre event) { + var e = event.getPlayer(); + + if (e instanceof ServerPlayer player && player.isAlive() && !player.hasDisconnected() && player.containerMenu instanceof CustomChestMenu) { + event.setCanPickup(TriState.FALSE); + } + } } \ No newline at end of file