2021-06-12 23:45:00 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Thu, 2 Aug 2018 08:44:35 -0500
|
|
|
|
Subject: [PATCH] Add hand to bucket events
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Cow.java b/src/main/java/net/minecraft/world/entity/animal/Cow.java
|
2021-11-23 15:04:41 +00:00
|
|
|
index 0f601ad4629bda75ec90612ad27fdec9ce62f83d..425c6da0de40983b0870c9fd1b53f16b6a11c34c 100644
|
2021-06-12 23:45:00 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Cow.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Cow.java
|
|
|
|
@@ -87,7 +87,7 @@ public class Cow extends Animal {
|
|
|
|
|
|
|
|
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
|
|
|
|
// CraftBukkit start - Got milk?
|
|
|
|
- org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level, player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET);
|
|
|
|
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level, player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand); // Paper - add enumHand
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return InteractionResult.PASS;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
|
2022-03-01 05:43:03 +00:00
|
|
|
index 8017953b623454593fbddbbcf90806c6e07c0974..8618790938f182e4aa0e27ea79dea1d35a36ec6e 100644
|
2021-06-12 23:45:00 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -177,7 +177,7 @@ public class Goat extends Animal {
|
2021-06-12 23:45:00 +00:00
|
|
|
|
|
|
|
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
|
|
|
|
// CraftBukkit start - Got milk?
|
|
|
|
- org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level, player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET);
|
|
|
|
+ org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level, player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand); // Paper - add enumHand
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return InteractionResult.PASS;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/BucketItem.java b/src/main/java/net/minecraft/world/item/BucketItem.java
|
2021-11-23 15:04:41 +00:00
|
|
|
index 25f1567660682a122fcb63318f51ec45ffdf0d3b..5406acd65d4e1146f3bd7340ff9a1954a5c39ddb 100644
|
2021-06-12 23:45:00 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/BucketItem.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/BucketItem.java
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -70,7 +70,7 @@ public class BucketItem extends Item implements DispensibleContainerItem {
|
2021-06-12 23:45:00 +00:00
|
|
|
// CraftBukkit start
|
|
|
|
ItemStack dummyFluid = ifluidsource.pickupBlock(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
|
2021-08-25 07:59:26 +00:00
|
|
|
if (dummyFluid.isEmpty()) return InteractionResultHolder.fail(itemstack); // Don't fire event if the bucket won't be filled.
|
2021-06-12 23:45:00 +00:00
|
|
|
- PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) world, user, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem());
|
|
|
|
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) world, user, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), hand); // Paper - add enumhand
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
((ServerPlayer) user).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -101,7 +101,7 @@ public class BucketItem extends Item implements DispensibleContainerItem {
|
2021-06-12 23:45:00 +00:00
|
|
|
iblockdata = world.getBlockState(blockposition);
|
|
|
|
BlockPos blockposition2 = iblockdata.getBlock() instanceof LiquidBlockContainer && this.content == Fluids.WATER ? blockposition : blockposition1;
|
|
|
|
|
2021-11-23 15:04:41 +00:00
|
|
|
- if (this.emptyContents(user, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack)) { // CraftBukkit
|
2021-06-12 23:45:00 +00:00
|
|
|
+ if (this.emptyContents(user, world, blockposition2, movingobjectpositionblock, movingobjectpositionblock.getDirection(), blockposition, itemstack, hand)) { // CraftBukkit // Paper - add enumhand
|
|
|
|
this.checkExtraContent(user, world, itemstack, blockposition2);
|
|
|
|
if (user instanceof ServerPlayer) {
|
|
|
|
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) user, blockposition2, itemstack);
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -128,10 +128,12 @@ public class BucketItem extends Item implements DispensibleContainerItem {
|
2021-06-12 23:45:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean emptyContents(@Nullable Player player, Level world, BlockPos pos, @Nullable BlockHitResult hitResult) {
|
2021-11-23 15:04:41 +00:00
|
|
|
- return this.emptyContents(player, world, pos, hitResult, null, null, null);
|
2021-06-12 23:45:00 +00:00
|
|
|
+ // Paper start - add enumHand
|
|
|
|
+ return emptyContents(player, world, pos, hitResult, null, null, null, null);
|
|
|
|
}
|
|
|
|
|
2021-11-23 15:04:41 +00:00
|
|
|
- public boolean emptyContents(Player entityhuman, Level world, BlockPos blockposition, @Nullable BlockHitResult movingobjectpositionblock, Direction enumdirection, BlockPos clicked, ItemStack itemstack) {
|
2021-06-12 23:45:00 +00:00
|
|
|
+ public boolean emptyContents(Player entityhuman, Level world, BlockPos blockposition, @Nullable BlockHitResult movingobjectpositionblock, Direction enumdirection, BlockPos clicked, ItemStack itemstack, InteractionHand enumhand) {
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit end
|
|
|
|
if (!(this.content instanceof FlowingFluid)) {
|
|
|
|
return false;
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -144,7 +146,7 @@ public class BucketItem extends Item implements DispensibleContainerItem {
|
2021-06-12 23:45:00 +00:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
if (flag1 && entityhuman != null) {
|
|
|
|
- PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) world, entityhuman, blockposition, clicked, enumdirection, itemstack);
|
|
|
|
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) world, entityhuman, blockposition, clicked, enumdirection, itemstack, enumhand); // Paper - add enumhand
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
((ServerPlayer) entityhuman).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-4238: needed when looking through entity
|
|
|
|
((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
|
2021-11-23 15:04:41 +00:00
|
|
|
@@ -153,7 +155,7 @@ public class BucketItem extends Item implements DispensibleContainerItem {
|
2021-06-12 23:45:00 +00:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
if (!flag1) {
|
2021-11-23 15:04:41 +00:00
|
|
|
- return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (BlockHitResult) null, enumdirection, clicked, itemstack); // CraftBukkit
|
|
|
|
+ return movingobjectpositionblock != null && this.emptyContents(entityhuman, world, movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()), (BlockHitResult) null, enumdirection, clicked, itemstack, enumhand); // CraftBukkit // Paper
|
|
|
|
} else if (world.dimensionType().ultraWarm() && this.content.is(FluidTags.WATER)) {
|
2021-06-12 23:45:00 +00:00
|
|
|
int i = blockposition.getX();
|
|
|
|
int j = blockposition.getY();
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-06-03 04:26:56 +00:00
|
|
|
index 8620c065e7709bf8a366760073d58f902215d1c0..6f9498a7064c41e61f7e50cbe6b4a8d6384f902c 100644
|
2021-06-12 23:45:00 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-02-12 13:20:33 +00:00
|
|
|
@@ -422,6 +422,20 @@ public class CraftEventFactory {
|
2021-06-12 23:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, ServerLevel world, net.minecraft.world.entity.player.Player who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, net.minecraft.world.item.Item item) {
|
|
|
|
+ // Paper start - add enumHand
|
|
|
|
+ return getPlayerBucketEvent(isFilling, world, who, changed, clicked, clickedFace, itemstack, item, null);
|
|
|
|
+ }
|
|
|
|
+
|
2021-11-15 19:01:19 +00:00
|
|
|
+ public static PlayerBucketEmptyEvent callPlayerBucketEmptyEvent(ServerLevel world, net.minecraft.world.entity.player.Player who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, InteractionHand enumHand) {
|
2021-06-12 23:45:00 +00:00
|
|
|
+ return (PlayerBucketEmptyEvent) getPlayerBucketEvent(false, world, who, changed, clicked, clickedFace, itemstack, Items.BUCKET, enumHand);
|
|
|
|
+ }
|
|
|
|
+
|
2021-11-15 19:01:19 +00:00
|
|
|
+ public static PlayerBucketFillEvent callPlayerBucketFillEvent(ServerLevel world, net.minecraft.world.entity.player.Player who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemInHand, net.minecraft.world.item.Item bucket, InteractionHand enumHand) {
|
2021-06-12 23:45:00 +00:00
|
|
|
+ return (PlayerBucketFillEvent) getPlayerBucketEvent(true, world, who, clicked, changed, clickedFace, itemInHand, bucket, enumHand);
|
|
|
|
+ }
|
|
|
|
+
|
2021-11-15 19:01:19 +00:00
|
|
|
+ private static PlayerEvent getPlayerBucketEvent(boolean isFilling, ServerLevel world, net.minecraft.world.entity.player.Player who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, net.minecraft.world.item.Item item, InteractionHand enumHand) {
|
2021-06-12 23:45:00 +00:00
|
|
|
+ // Paper end
|
|
|
|
Player player = (Player) who.getBukkitEntity();
|
|
|
|
CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
|
|
|
|
Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());
|
2022-02-12 13:20:33 +00:00
|
|
|
@@ -434,10 +448,10 @@ public class CraftEventFactory {
|
2021-06-12 23:45:00 +00:00
|
|
|
|
|
|
|
PlayerEvent event;
|
|
|
|
if (isFilling) {
|
|
|
|
- event = new PlayerBucketFillEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
|
|
|
|
+ event = new PlayerBucketFillEvent(player, block, blockClicked, blockFace, bucket, itemInHand, enumHand == null ? null : enumHand == InteractionHand.OFF_HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); // Paper - add enumHand
|
|
|
|
((PlayerBucketFillEvent) event).setCancelled(!CraftEventFactory.canBuild(world, player, changed.getX(), changed.getZ()));
|
|
|
|
} else {
|
|
|
|
- event = new PlayerBucketEmptyEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
|
|
|
|
+ event = new PlayerBucketEmptyEvent(player, block, blockClicked, blockFace, bucket, itemInHand, enumHand == null ? null : enumHand == InteractionHand.OFF_HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); // Paper - add enumHand
|
|
|
|
((PlayerBucketEmptyEvent) event).setCancelled(!CraftEventFactory.canBuild(world, player, changed.getX(), changed.getZ()));
|
|
|
|
}
|
|
|
|
|