From 95278079e2974043cf88498565944b6e91aa25d0 Mon Sep 17 00:00:00 2001 From: Samsuik Date: Sun, 24 Aug 2025 23:33:07 +0100 Subject: [PATCH] prevent placing spawn eggs inside blocks --- .../world/item/SpawnEggItem.java.patch | 40 +++++++++++++++++++ .../configuration/WorldConfiguration.java | 3 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 sakura-server/minecraft-patches/sources/net/minecraft/world/item/SpawnEggItem.java.patch diff --git a/sakura-server/minecraft-patches/sources/net/minecraft/world/item/SpawnEggItem.java.patch b/sakura-server/minecraft-patches/sources/net/minecraft/world/item/SpawnEggItem.java.patch new file mode 100644 index 0000000..8ec80ef --- /dev/null +++ b/sakura-server/minecraft-patches/sources/net/minecraft/world/item/SpawnEggItem.java.patch @@ -0,0 +1,40 @@ +--- a/net/minecraft/world/item/SpawnEggItem.java ++++ b/net/minecraft/world/item/SpawnEggItem.java +@@ -71,16 +_,18 @@ + } + + EntityType type = this.getType(level.registryAccess(), itemInHand); +- if (type.spawn( +- (ServerLevel)level, +- itemInHand, +- context.getPlayer(), +- blockPos, +- EntitySpawnReason.SPAWN_ITEM_USE, +- true, +- !Objects.equals(clickedPos, blockPos) && clickedFace == Direction.UP +- ) +- != null) { ++ // Sakura start - prevent placing spawn eggs inside blocks ++ final Entity entity = type.spawn( ++ (ServerLevel)level, ++ itemInHand, ++ context.getPlayer(), ++ blockPos, ++ EntitySpawnReason.SPAWN_ITEM_USE, ++ true, ++ !Objects.equals(clickedPos, blockPos) && clickedFace == Direction.UP ++ ); ++ if (entity != null && (!level.sakuraConfig().players.preventPlacingSpawnEggsInsideBlocks || level.noCollision(null, entity.getBoundingBox()))) { ++ // Sakura end - prevent placing spawn eggs inside blocks + itemInHand.shrink(1); + level.gameEvent(context.getPlayer(), GameEvent.ENTITY_PLACE, clickedPos); + } +@@ -103,7 +_,7 @@ + } else if (level.mayInteract(player, blockPos) && player.mayUseItemAt(blockPos, playerPovHitResult.getDirection(), itemInHand)) { + EntityType type = this.getType(serverLevel.registryAccess(), itemInHand); + Entity entity = type.spawn(serverLevel, itemInHand, player, blockPos, EntitySpawnReason.SPAWN_ITEM_USE, false, false); +- if (entity == null) { ++ if (entity == null || level.sakuraConfig().players.preventPlacingSpawnEggsInsideBlocks && !level.noCollision(null, entity.getBoundingBox())) { // Sakura - prevent placing spawn eggs inside blocks + return InteractionResult.PASS; + } else { + itemInHand.consume(1, player); diff --git a/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java index 5c8f0d1..620f6fc 100644 --- a/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java +++ b/sakura-server/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java @@ -186,9 +186,10 @@ public final class WorldConfiguration extends ConfigurationPart { public double shieldHitKnockback = 0.5; } - @Comment("Prevents players swimming using elytra or riptide to enter holes") + @Comment("Prevents players swimming, gliding or using riptide to enter small holes") public boolean posesShrinkCollisionBox = true; public boolean fishingHooksPullEntities = true; + public boolean preventPlacingSpawnEggsInsideBlocks = false; } public Entity entity;