3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 20:40:07 +01:00
Paper/nms-patches/ItemBucket.patch

111 Zeilen
6.4 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ItemBucket.java
+++ b/net/minecraft/server/ItemBucket.java
@@ -1,10 +1,17 @@
package net.minecraft.server;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
2018-07-15 02:00:00 +02:00
+import org.bukkit.craftbukkit.util.DummyGeneratorAccess;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
2016-05-10 13:47:39 +02:00
public class ItemBucket extends Item {
- private final FluidType a;
+ public final FluidType a; // PAIL: private->public
public ItemBucket(FluidType fluidtype, Item.Info item_info) {
super(item_info);
2018-07-15 02:00:00 +02:00
@@ -28,12 +35,20 @@
if (this.a == FluidTypes.a) {
iblockdata = world.getType(blockposition);
if (iblockdata.getBlock() instanceof IFluidSource) {
+ // CraftBukkit start
2018-07-22 04:00:00 +02:00
+ FluidType dummyFluid = ((IFluidSource) iblockdata.getBlock()).a(DummyGeneratorAccess.INSTANCE, blockposition, iblockdata);
2018-07-15 02:00:00 +02:00
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, dummyFluid.b());
+
+ if (event.isCancelled()) {
2016-02-29 22:32:46 +01:00
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ }
+ // CraftBukkit end
2018-07-22 04:00:00 +02:00
FluidType fluidtype = ((IFluidSource) iblockdata.getBlock()).a(world, blockposition, iblockdata);
2018-07-15 02:00:00 +02:00
if (fluidtype != FluidTypes.a) {
entityhuman.b(StatisticList.ITEM_USED.b(this));
entityhuman.a(fluidtype.a(TagsFluid.b) ? SoundEffects.ITEM_BUCKET_FILL_LAVA : SoundEffects.ITEM_BUCKET_FILL, 1.0F, 1.0F);
- ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b());
+ ItemStack itemstack1 = this.a(itemstack, entityhuman, fluidtype.b(), event.getItemStack()); // CraftBukkit
if (!world.isClientSide) {
CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.b()));
@@ -48,7 +63,7 @@
iblockdata = world.getType(blockposition);
BlockPosition blockposition1 = this.a(iblockdata, blockposition, movingobjectposition);
- if (this.a(entityhuman, world, blockposition1, movingobjectposition)) {
+ if (this.a(entityhuman, world, blockposition1, movingobjectposition, movingobjectposition.direction, blockposition, itemstack)) { // CraftBukkit
2018-07-15 02:00:00 +02:00
this.a(world, itemstack, blockposition1);
if (entityhuman instanceof EntityPlayer) {
CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition1, itemstack);
@@ -76,16 +91,19 @@
public void a(World world, ItemStack itemstack, BlockPosition blockposition) {}
2015-02-26 23:41:06 +01:00
- private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item) {
+ // CraftBukkit - added ob.ItemStack result - TODO: Is this... the right way to handle this?
+ private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item, org.bukkit.inventory.ItemStack result) {
if (entityhuman.abilities.canInstantlyBuild) {
return itemstack;
} else {
2016-11-17 02:41:03 +01:00
itemstack.subtract(1);
if (itemstack.isEmpty()) {
- return new ItemStack(item);
+ // CraftBukkit start
+ return CraftItemStack.asNMSCopy(result);
} else {
- if (!entityhuman.inventory.pickup(new ItemStack(item))) {
- entityhuman.drop(new ItemStack(item), false);
+ if (!entityhuman.inventory.pickup(CraftItemStack.asNMSCopy(result))) {
+ entityhuman.drop(CraftItemStack.asNMSCopy(result), false);
+ // CraftBukkit end
}
2016-11-17 02:41:03 +01:00
return itemstack;
2018-07-15 02:00:00 +02:00
@@ -93,7 +111,13 @@
2016-02-29 22:32:46 +01:00
}
}
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition) {
+ return a(entityhuman, world, blockposition, movingobjectposition, null, null, null);
2016-02-29 22:32:46 +01:00
+ }
+
+ public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPosition movingobjectposition, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
if (!(this.a instanceof FluidTypeFlowing)) {
2016-02-29 22:32:46 +01:00
return false;
} else {
@@ -103,8 +127,18 @@
boolean flag1 = material.isReplaceable();
2018-07-15 02:00:00 +02:00
if (!world.isEmpty(blockposition) && !flag && !flag1 && (!(iblockdata.getBlock() instanceof IFluidContainer) || !((IFluidContainer) iblockdata.getBlock()).a((IBlockAccess) world, blockposition, iblockdata, this.a))) {
- return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.a().shift(movingobjectposition.direction), (MovingObjectPosition) null);
+ return movingobjectposition == null ? false : this.a(entityhuman, world, movingobjectposition.a().shift(movingobjectposition.direction), (MovingObjectPosition) null, enumdirection, clicked, itemstack); // CraftBukkit
2016-02-29 22:32:46 +01:00
} else {
+ // CraftBukkit start
+ if (entityhuman != null) {
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clicked.getX(), clicked.getY(), clicked.getZ(), enumdirection, itemstack);
2016-02-29 22:32:46 +01:00
+ if (event.isCancelled()) {
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-4238: needed when looking through entity
2016-02-29 22:32:46 +01:00
+ // TODO: inventory not updated
+ return false;
+ }
+ }
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
if (world.worldProvider.isNether() && this.a.a(TagsFluid.a)) {
2016-02-29 22:32:46 +01:00
int i = blockposition.getX();
int j = blockposition.getY();