Update to Minecraft 1.21

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-06-14 01:05:00 +10:00
parent 7c6204e1a9
commit eed041d629
255 changed files with 3585 additions and 3261 deletions

View File

@@ -1,18 +1,19 @@
--- a/net/minecraft/world/item/ItemLeash.java
+++ b/net/minecraft/world/item/ItemLeash.java
@@ -16,6 +16,11 @@
@@ -19,6 +19,12 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.hanging.HangingPlaceEvent;
+// CraftBukkit end
+
public class ItemLeash extends Item {
public ItemLeash(Item.Info item_info) {
@@ -32,7 +37,7 @@
@@ -35,7 +41,7 @@
EntityHuman entityhuman = itemactioncontext.getPlayer();
if (!world.isClientSide && entityhuman != null) {
@@ -21,28 +22,28 @@
}
return EnumInteractionResult.sidedSuccess(world.isClientSide);
@@ -41,7 +46,7 @@
@@ -44,7 +50,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,19 +59,50 @@
List<Leashable> list = leashableInArea(world, blockposition, (leashable) -> {
return leashable.getLeashHolder() == entityhuman;
@@ -52,22 +58,55 @@
EntityInsentient entityinsentient;
Leashable leashable;
- for (Iterator iterator = list.iterator(); iterator.hasNext(); entityinsentient.setLeashedTo(entityleash, true)) {
- for (Iterator iterator = list.iterator(); iterator.hasNext(); leashable.setLeashedTo(entityleash, true)) {
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop
entityinsentient = (EntityInsentient) iterator.next();
leashable = (Leashable) 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);
+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, CraftBlock.at(world, blockposition), org.bukkit.block.BlockFace.SELF, hand);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
@@ -54,12 +55,14 @@
}
+
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) {
+ iterator.remove();
+ continue;
+ if (leashable instanceof Entity leashed) {
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(leashed, entityleash, entityhuman, enumhand).isCancelled()) {
+ iterator.remove();
+ continue;
+ }
+ }
+
+ entityinsentient.setLeashedTo(entityleash, true);
+ leashable.setLeashedTo(entityleash, true);
+ // CraftBukkit end
}
@@ -75,10 +78,13 @@
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
}
+
public static List<Leashable> leashableInArea(World world, BlockPosition blockposition, Predicate<Leashable> predicate) {
double d0 = 7.0D;
int i = blockposition.getX();