2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/item/ItemLeash.java
|
|
|
|
+++ b/net/minecraft/world/item/ItemLeash.java
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -16,6 +16,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) {
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -32,7 +37,7 @@
|
2022-10-02 00:07:14 +02:00
|
|
|
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);
|
2024-04-23 17:15:00 +02:00
|
|
|
@@ -41,7 +46,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;
|
|
|
|
double d0 = 7.0D;
|
2024-04-23 17:15:00 +02:00
|
|
|
int i = blockposition.getX();
|
2024-04-27 23:27:16 +02:00
|
|
|
@@ -54,19 +59,50 @@
|
2024-04-23 17:15:00 +02:00
|
|
|
|
|
|
|
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);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2024-04-23 17:15:00 +02:00
|
|
|
+ // 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);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2024-04-23 17:15:00 +02:00
|
|
|
+ if (event.isCancelled()) {
|
|
|
|
+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause
|
|
|
|
+ return EnumInteractionResult.PASS;
|
2021-06-11 07:00:00 +02:00
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
2024-04-23 17:15:00 +02:00
|
|
|
entityleash.playPlacementSound();
|
2021-06-11 07:00:00 +02:00
|
|
|
}
|
2024-04-23 17:15:00 +02:00
|
|
|
+
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
|
2024-04-27 23:27:16 +02:00
|
|
|
+ iterator.remove();
|
|
|
|
+ continue;
|
2024-04-23 17:15:00 +02:00
|
|
|
+ }
|
2024-04-27 23:27:16 +02:00
|
|
|
+
|
|
|
|
+ entityinsentient.setLeashedTo(entityleash, true);
|
2024-04-23 17:15:00 +02:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
2022-10-02 00:07:14 +02:00
|
|
|
|
2024-04-23 17:15:00 +02:00
|
|
|
if (!list.isEmpty()) {
|
2024-04-27 23:27:16 +02:00
|
|
|
world.gameEvent((Holder) GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman));
|
|
|
|
return EnumInteractionResult.SUCCESS;
|
|
|
|
} else {
|
|
|
|
+ // CraftBukkit start- remove leash if we do not leash any entity because of the cancelled event
|
|
|
|
+ if (entityleash != null) {
|
|
|
|
+ entityleash.discard(null);
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2024-04-23 17:15:00 +02:00
|
|
|
return EnumInteractionResult.PASS;
|
|
|
|
}
|
2022-10-02 00:07:14 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // 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
|
|
|
|
}
|