2011-01-08 11:49:42 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-03-16 16:13:42 +01:00
|
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
2011-01-15 22:29:17 +01:00
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2011-03-16 16:13:42 +01:00
|
|
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
|
|
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-08 11:49:42 +01:00
|
|
|
|
|
|
|
public class ItemBucket extends Item {
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
private Block a;
|
2011-01-08 11:49:42 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public ItemBucket(Block block) {
|
2011-01-29 22:50:29 +01:00
|
|
|
this.maxStackSize = 1;
|
2013-11-04 14:07:38 +01:00
|
|
|
this.a = block;
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(CreativeModeTab.f);
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
2013-11-04 14:07:38 +01:00
|
|
|
boolean flag = this.a == Blocks.AIR;
|
2011-11-20 09:01:14 +01:00
|
|
|
MovingObjectPosition movingobjectposition = this.a(world, entityhuman, flag);
|
2011-01-08 11:49:42 +01:00
|
|
|
|
|
|
|
if (movingobjectposition == null) {
|
|
|
|
return itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (movingobjectposition.type == EnumMovingObjectType.BLOCK) {
|
2011-01-29 22:50:29 +01:00
|
|
|
int i = movingobjectposition.b;
|
|
|
|
int j = movingobjectposition.c;
|
|
|
|
int k = movingobjectposition.d;
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!world.a(entityhuman, i, j, k)) {
|
|
|
|
return itemstack;
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (flag) {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!entityhuman.a(i, j, k, movingobjectposition.face, itemstack)) {
|
2011-09-15 02:23:52 +02:00
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
Material material = world.getType(i, j, k).getMaterial();
|
|
|
|
int l = world.getData(i, j, k);
|
|
|
|
|
|
|
|
if (material == Material.WATER && l == 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit start
|
2013-11-04 14:07:38 +01:00
|
|
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Items.WATER_BUCKET);
|
2011-03-27 21:57:46 +02:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit end
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setAir(i, j, k);
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.a(itemstack, entityhuman, Items.WATER_BUCKET, event.getItemStack()); // CraftBukkit - added Event stack
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (material == Material.LAVA && l == 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit start
|
2013-11-04 14:07:38 +01:00
|
|
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Items.LAVA_BUCKET);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
2011-01-08 11:49:42 +01:00
|
|
|
return itemstack;
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
// CraftBukkit end
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setAir(i, j, k);
|
2013-11-04 14:07:38 +01:00
|
|
|
return this.a(itemstack, entityhuman, Items.LAVA_BUCKET, event.getItemStack()); // CraftBukkit - added Event stack
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.a == Blocks.AIR) {
|
2011-03-16 16:13:42 +01:00
|
|
|
// CraftBukkit start
|
2011-04-20 19:05:14 +02:00
|
|
|
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, i, j, k, movingobjectposition.face, itemstack);
|
2011-03-16 16:13:42 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2012-12-17 08:31:41 +01:00
|
|
|
return CraftItemStack.asNMSCopy(event.getItemStack());
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-05-14 16:29:42 +02:00
|
|
|
|
|
|
|
int clickedX = i, clickedY = j, clickedZ = k;
|
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 0) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--j;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 1) {
|
2011-01-29 22:50:29 +01:00
|
|
|
++j;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 2) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--k;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 3) {
|
2011-01-29 22:50:29 +01:00
|
|
|
++k;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 4) {
|
2011-01-29 22:50:29 +01:00
|
|
|
--i;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.face == 5) {
|
2011-01-29 22:50:29 +01:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (!entityhuman.a(i, j, k, movingobjectposition.face, itemstack)) {
|
2011-09-15 02:23:52 +02:00
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2012-08-03 19:07:04 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clickedX, clickedY, clickedZ, movingobjectposition.face, itemstack);
|
2011-03-16 16:13:42 +01:00
|
|
|
|
2012-08-03 19:07:04 +02:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.a(world, i, j, k) && !entityhuman.abilities.canInstantlyBuild) {
|
2012-12-17 08:31:41 +01:00
|
|
|
return CraftItemStack.asNMSCopy(event.getItemStack()); // CraftBukkit
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return itemstack;
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
// 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 if (--itemstack.count <= 0) {
|
|
|
|
return CraftItemStack.asNMSCopy(result); // CraftBukkit
|
|
|
|
} else {
|
|
|
|
if (!entityhuman.inventory.pickup(CraftItemStack.asNMSCopy(result))) { // CraftBukkit
|
|
|
|
entityhuman.drop(CraftItemStack.asNMSCopy(result), false); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public boolean a(World world, int i, int j, int k) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this.a == Blocks.AIR) {
|
2012-07-29 09:33:13 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
Material material = world.getType(i, j, k).getMaterial();
|
2013-07-09 01:43:37 +02:00
|
|
|
boolean flag = !material.isBuildable();
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (!world.isEmpty(i, j, k) && !flag) {
|
|
|
|
return false;
|
2012-07-29 09:33:13 +02:00
|
|
|
} else {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.worldProvider.f && this.a == Blocks.WATER) {
|
2013-07-01 13:03:00 +02:00
|
|
|
world.makeSound((double) ((float) i + 0.5F), (double) ((float) j + 0.5F), (double) ((float) k + 0.5F), "random.fizz", 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
for (int l = 0; l < 8; ++l) {
|
|
|
|
world.addParticle("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
} else {
|
2013-07-09 01:43:37 +02:00
|
|
|
if (!world.isStatic && flag && !material.isLiquid()) {
|
|
|
|
world.setAir(i, j, k, true);
|
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, this.a, 0, 3);
|
2013-07-01 13:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
}
|
|
|
|
}
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|