2011-01-08 12:18:05 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-01-08 12:18:05 +01:00
|
|
|
public class ItemBoat extends Item {
|
|
|
|
|
|
|
|
public ItemBoat(int i) {
|
|
|
|
super(i);
|
2011-01-29 22:50:29 +01:00
|
|
|
this.maxStackSize = 1;
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) {
|
2011-01-08 12:18:05 +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 12:18:05 +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, true);
|
2011-01-08 12:18:05 +01:00
|
|
|
|
|
|
|
if (movingobjectposition == null) {
|
|
|
|
return itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2012-03-01 11:49:23 +01:00
|
|
|
Vec3D vec3d2 = entityhuman.f(f);
|
2011-11-20 09:01:14 +01:00
|
|
|
boolean flag = false;
|
|
|
|
float f9 = 1.0F;
|
2012-01-12 16:27:39 +01:00
|
|
|
List list = world.getEntities(entityhuman, entityhuman.boundingBox.a(vec3d2.a * d3, vec3d2.b * d3, vec3d2.c * d3).grow((double) f9, (double) f9, (double) f9));
|
2011-11-20 09:01:14 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
|
|
Entity entity = (Entity) list.get(i);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (entity.o_()) {
|
2011-11-20 09:01:14 +01:00
|
|
|
float f10 = entity.j_();
|
2012-01-12 16:27:39 +01:00
|
|
|
AxisAlignedBB axisalignedbb = entity.boundingBox.grow((double) f10, (double) f10, (double) f10);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (axisalignedbb.a(vec3d)) {
|
|
|
|
flag = true;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
return itemstack;
|
|
|
|
} else {
|
|
|
|
if (movingobjectposition.type == EnumMovingObjectType.TILE) {
|
|
|
|
int j = movingobjectposition.b;
|
|
|
|
int k = movingobjectposition.c;
|
|
|
|
int l = movingobjectposition.d;
|
|
|
|
|
|
|
|
if (!world.isStatic) {
|
|
|
|
// CraftBukkit start - Boat placement
|
2012-07-22 08:18:00 +02:00
|
|
|
org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(entityhuman, org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK, j, k, l, movingobjectposition.face, itemstack);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
if (world.getTypeId(j, k, l) == Block.SNOW.id) {
|
|
|
|
--k;
|
|
|
|
}
|
|
|
|
|
|
|
|
world.addEntity(new EntityBoat(world, (double) ((float) j + 0.5F), (double) ((float) k + 1.0F), (double) ((float) l + 0.5F)));
|
2011-05-26 14:48:22 +02:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
if (!entityhuman.abilities.canInstantlyBuild) {
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
2011-01-23 13:23:13 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-11-20 09:01:14 +01:00
|
|
|
return itemstack;
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|