2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/item/ItemLeash.java
|
|
|
|
+++ b/net/minecraft/world/item/ItemLeash.java
|
2022-10-02 00:07:14 +02:00
|
|
|
@@ -15,6 +15,11 @@
|
2022-06-07 18:00:00 +02:00
|
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.phys.AxisAlignedBB;
|
2014-11-25 22:32:16 +01:00
|
|
|
|
2022-10-02 00:07:14 +02:00
|
|
|
+// CraftBukkit start
|
|
|
|
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
|
|
|
+import org.bukkit.event.hanging.HangingPlaceEvent;
|
|
|
|
+// CraftBukkit end
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
public class ItemLeash extends Item {
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
public ItemLeash(Item.Info item_info) {
|
2022-10-02 00:07:14 +02:00
|
|
|
@@ -31,7 +36,7 @@
|
|
|
|
EntityHuman entityhuman = itemactioncontext.getPlayer();
|
|
|
|
|
|
|
|
if (!world.isClientSide && entityhuman != null) {
|
|
|
|
- bindPlayerMobs(entityhuman, world, blockposition);
|
|
|
|
+ bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand
|
|
|
|
}
|
|
|
|
|
2023-03-14 17:30:00 +01:00
|
|
|
return EnumInteractionResult.sidedSuccess(world.isClientSide);
|
|
|
|
@@ -40,7 +45,7 @@
|
2022-10-02 00:07:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- 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;
|
|
|
|
boolean flag = false;
|
|
|
|
double d0 = 7.0D;
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -56,9 +61,26 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
if (entityinsentient.getLeashHolder() == entityhuman) {
|
2014-11-25 22:32:16 +01:00
|
|
|
if (entityleash == null) {
|
2021-11-21 23:00:00 +01:00
|
|
|
entityleash = EntityLeash.getOrCreateKnot(world, blockposition);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ // CraftBukkit start - fire HangingPlaceEvent
|
2022-10-02 00:07:14 +02:00
|
|
|
+ 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);
|
2021-06-11 13:33:49 +02:00
|
|
|
+ world.getCraftServer().getPluginManager().callEvent(event);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
|
|
|
+ if (event.isCancelled()) {
|
2024-02-21 10:55:34 +01:00
|
|
|
+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause
|
2019-12-10 23:00:00 +01:00
|
|
|
+ return EnumInteractionResult.PASS;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-11-21 23:00:00 +01:00
|
|
|
entityleash.playPlacementSound();
|
2021-06-11 07:00:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit start
|
2022-10-02 00:07:14 +02:00
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ continue;
|
2021-06-11 07:00:00 +02:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
+
|
2021-11-21 23:00:00 +01:00
|
|
|
entityinsentient.setLeashedTo(entityleash, true);
|
2014-11-25 22:32:16 +01:00
|
|
|
flag = true;
|
2021-06-11 07:00:00 +02:00
|
|
|
}
|
2023-03-14 17:30:00 +01:00
|
|
|
@@ -70,4 +92,10 @@
|
2022-10-02 00:07:14 +02:00
|
|
|
|
|
|
|
return flag ? EnumInteractionResult.SUCCESS : 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
|
|
|
|
}
|