PaperMC/paper-server/patches/sources/net/minecraft/world/item/EnderEyeItem.java.patch
2024-12-15 15:55:13 +01:00

56 lines
3.8 KiB
Diff

--- a/net/minecraft/world/item/EnderEyeItem.java
+++ b/net/minecraft/world/item/EnderEyeItem.java
@@ -42,6 +_,11 @@
return InteractionResult.SUCCESS;
} else {
BlockState blockState1 = blockState.setValue(EndPortalFrameBlock.HAS_EYE, Boolean.valueOf(true));
+ // Paper start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(context.getPlayer(), clickedPos, blockState1)) {
+ return InteractionResult.PASS;
+ }
+ // Paper end
Block.pushEntitiesUp(blockState, blockState1, level, clickedPos);
level.setBlock(clickedPos, blockState1, 2);
level.updateNeighbourForOutputSignal(clickedPos, Blocks.END_PORTAL_FRAME);
@@ -57,7 +_,27 @@
}
}
- level.globalLevelEvent(1038, blockPos.offset(1, 0, 1), 0);
+ // CraftBukkit start - Use relative location for far away sounds
+ // level.globalLevelEvent(1038, blockPos.offset(1, 0, 1), 0);
+ int viewDistance = level.getCraftServer().getViewDistance() * 16;
+ BlockPos soundPos = blockPos.offset(1, 0, 1);
+ final net.minecraft.server.level.ServerLevel serverLevel = (net.minecraft.server.level.ServerLevel) level; // Paper - respect global sound events gamerule - ensured by isClientSide check above
+ for (ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = soundPos.getX() - player.getX();
+ double deltaZ = soundPos.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ final double soundRadiusSquared = serverLevel.getGlobalSoundRangeSquared(config -> config.endPortalSoundRadius); // Paper - respect global sound events gamerule
+ if (!serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
+ double relativeZ = player.getZ() + (deltaZ / deltaLength) * viewDistance;
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(net.minecraft.world.level.block.LevelEvent.SOUND_END_PORTAL_SPAWN, new BlockPos((int) relativeX, (int) soundPos.getY(), (int) relativeZ), 0, true));
+ } else {
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelEventPacket(net.minecraft.world.level.block.LevelEvent.SOUND_END_PORTAL_SPAWN, soundPos, 0, true));
+ }
+ }
+ // CraftBukkit end
}
return InteractionResult.SUCCESS;
@@ -87,7 +_,11 @@
eyeOfEnder.setItem(itemInHand);
eyeOfEnder.signalTo(blockPos);
level.gameEvent(GameEvent.PROJECTILE_SHOOT, eyeOfEnder.position(), GameEvent.Context.of(player));
- level.addFreshEntity(eyeOfEnder);
+ // CraftBukkit start
+ if (!level.addFreshEntity(eyeOfEnder)) {
+ return InteractionResult.FAIL;
+ }
+ // CraftBukkit end
if (player instanceof ServerPlayer serverPlayer) {
CriteriaTriggers.USED_ENDER_EYE.trigger(serverPlayer, blockPos);
}