9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-28 03:09:07 +00:00

prevent placing spawn eggs inside blocks

This commit is contained in:
Samsuik
2025-08-24 23:33:07 +01:00
parent 6ebc6c8254
commit 95278079e2
2 changed files with 42 additions and 1 deletions

View File

@@ -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);

View File

@@ -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;