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.Location;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
private int a;
|
|
|
|
|
|
|
|
public ItemBucket(int i, int j) {
|
|
|
|
super(i);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.maxStackSize = 1;
|
|
|
|
this.a = j;
|
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) {
|
2011-01-08 11:49:42 +01:00
|
|
|
float f = 1.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
float f1 = entityhuman.lastPitch + (entityhuman.pitch - entityhuman.lastPitch) * f;
|
|
|
|
float f2 = entityhuman.lastYaw + (entityhuman.yaw - entityhuman.lastYaw) * f;
|
|
|
|
double d0 = entityhuman.lastX + (entityhuman.locX - entityhuman.lastX) * (double) f;
|
|
|
|
double d1 = entityhuman.lastY + (entityhuman.locY - entityhuman.lastY) * (double) f + 1.62D - (double) entityhuman.height;
|
|
|
|
double d2 = entityhuman.lastZ + (entityhuman.locZ - entityhuman.lastZ) * (double) f;
|
2011-04-20 19:05:14 +02:00
|
|
|
Vec3D vec3d = Vec3D.create(d0, d1, d2);
|
|
|
|
float f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
|
|
|
|
float f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
|
|
|
|
float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
|
|
|
float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
2011-01-08 11:49:42 +01:00
|
|
|
float f7 = f4 * f5;
|
2011-01-29 22:50:29 +01:00
|
|
|
float f8 = f3 * f5;
|
|
|
|
double d3 = 5.0D;
|
2011-04-20 19:05:14 +02:00
|
|
|
Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
|
|
|
|
MovingObjectPosition movingobjectposition = world.rayTrace(vec3d, vec3d1, this.a == 0);
|
2011-01-08 11:49:42 +01:00
|
|
|
|
|
|
|
if (movingobjectposition == null) {
|
|
|
|
return itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (movingobjectposition.type == EnumMovingObjectType.TILE) {
|
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
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (this.a == 0) {
|
2011-09-15 02:23:52 +02:00
|
|
|
if (!entityhuman.c(i, j, k)) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getMaterial(i, j, k) == Material.WATER && world.getData(i, j, k) == 0) {
|
|
|
|
// CraftBukkit start
|
2011-03-16 16:13:42 +01:00
|
|
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.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
|
|
|
}
|
2011-03-16 16:13:42 +01:00
|
|
|
|
|
|
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
|
|
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
2011-01-29 22:50:29 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeId(i, j, k, 0);
|
2011-03-16 16:13:42 +01:00
|
|
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.getMaterial(i, j, k) == Material.LAVA && world.getData(i, j, k) == 0) {
|
|
|
|
// CraftBukkit start
|
2011-03-27 21:57:46 +02:00
|
|
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, i, j, k, -1, itemstack, Item.LAVA_BUCKET);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
2011-01-08 11:49:42 +01:00
|
|
|
return itemstack;
|
|
|
|
}
|
2011-03-16 16:13:42 +01:00
|
|
|
|
|
|
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
|
|
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeId(i, j, k, 0);
|
2011-05-14 16:29:42 +02:00
|
|
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data); // CraftBukkit
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this.a < 0) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
|
|
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
2011-05-14 16:29:42 +02:00
|
|
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
if (!entityhuman.c(i, j, k)) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (world.isEmpty(i, j, k) || !world.getMaterial(i, j, k).isBuildable()) {
|
2011-03-16 16:13:42 +01:00
|
|
|
// CraftBukkit start
|
2011-04-20 19:05:14 +02:00
|
|
|
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clickedX, clickedY, clickedZ, movingobjectposition.face, itemstack);
|
2011-03-16 16:13:42 +01:00
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-03-27 21:57:46 +02:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (world.worldProvider.d && this.a == Block.WATER.id) {
|
|
|
|
world.makeSound(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, "random.fizz", 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
for (int l = 0; l < 8; ++l) {
|
|
|
|
world.a("largesmoke", (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
world.setTypeIdAndData(i, j, k, this.a, 0);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-15 18:36:27 +02:00
|
|
|
if (entityhuman.abilities.canInstantlyBuild) {
|
2011-09-15 02:23:52 +02:00
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
2011-03-16 16:13:42 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
|
|
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
2011-05-14 16:29:42 +02:00
|
|
|
|
|
|
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
|
2011-03-16 16:13:42 +01:00
|
|
|
// CraftBukkit end
|
2011-01-08 11:49:42 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-20 19:05:14 +02:00
|
|
|
} else if (this.a == 0 && movingobjectposition.entity instanceof EntityCow) {
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit start - This codepath seems to be *NEVER* called
|
2011-04-20 19:05:14 +02:00
|
|
|
Location loc = movingobjectposition.entity.getBukkitEntity().getLocation();
|
2011-03-16 16:13:42 +01:00
|
|
|
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), -1, itemstack, Item.MILK_BUCKET);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
|
|
|
|
CraftItemStack itemInHand = (CraftItemStack) event.getItemStack();
|
|
|
|
byte data = itemInHand.getData() == null ? (byte) 0 : itemInHand.getData().getData();
|
2011-05-14 16:29:42 +02:00
|
|
|
return new ItemStack(itemInHand.getTypeId(), itemInHand.getAmount(), data);
|
2011-03-16 16:13:42 +01:00
|
|
|
// CraftBukkit end
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|