PaperMC/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch
CraftBukkit/Spigot 65bc2541a3 Update to Minecraft 1.20.5
By: md_5 <git@md-5.net>
2024-04-24 01:15:00 +10:00

74 lines
3.4 KiB
Diff

--- a/net/minecraft/world/item/ItemLeash.java
+++ b/net/minecraft/world/item/ItemLeash.java
@@ -16,6 +16,11 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
+
public class ItemLeash extends Item {
public ItemLeash(Item.Info item_info) {
@@ -32,7 +37,7 @@
EntityHuman entityhuman = itemactioncontext.getPlayer();
if (!world.isClientSide && entityhuman != null) {
- bindPlayerMobs(entityhuman, world, blockposition);
+ bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand
}
return EnumInteractionResult.sidedSuccess(world.isClientSide);
@@ -41,7 +46,7 @@
}
}
- public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand
EntityLeash entityleash = null;
double d0 = 7.0D;
int i = blockposition.getX();
@@ -54,12 +59,29 @@
EntityInsentient entityinsentient;
- for (Iterator iterator = list.iterator(); iterator.hasNext(); entityinsentient.setLeashedTo(entityleash, true)) {
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop
entityinsentient = (EntityInsentient) iterator.next();
if (entityleash == null) {
entityleash = EntityLeash.getOrCreateKnot(world, blockposition);
+
+ // CraftBukkit start - fire HangingPlaceEvent
+ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand);
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause
+ return EnumInteractionResult.PASS;
+ }
+ // CraftBukkit end
entityleash.playPlacementSound();
}
+
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
+ entityinsentient.setLeashedTo(entityleash, true);
+ }
+ // CraftBukkit end
}
if (!list.isEmpty()) {
@@ -69,4 +91,10 @@
return EnumInteractionResult.PASS;
}
}
+
+ // CraftBukkit start
+ public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) {
+ return bindPlayerMobs(entityhuman, world, blockposition, net.minecraft.world.EnumHand.MAIN_HAND);
+ }
+ // CraftBukkit end
}