2011-01-08 12:18:05 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start
|
2011-01-23 13:23:13 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.CraftWorld;
|
2011-01-15 22:40:18 +01:00
|
|
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
2011-01-15 22:29:17 +01:00
|
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
2011-01-23 13:23:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2011-01-08 12:18:05 +01:00
|
|
|
import org.bukkit.event.Event.Type;
|
|
|
|
import org.bukkit.event.player.PlayerItemEvent;
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
2011-01-08 12:18:05 +01:00
|
|
|
|
|
|
|
public class ItemBoat extends Item {
|
|
|
|
|
|
|
|
public ItemBoat(int i) {
|
|
|
|
super(i);
|
2011-01-14 14:31:10 +01:00
|
|
|
bb = 1;
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack a(ItemStack itemstack, World world, EntityPlayer entityplayer) {
|
|
|
|
float f = 1.0F;
|
|
|
|
float f1 = entityplayer.y + (entityplayer.w - entityplayer.y) * f;
|
|
|
|
float f2 = entityplayer.x + (entityplayer.v - entityplayer.x) * f;
|
|
|
|
double d = entityplayer.m + (entityplayer.p - entityplayer.m) * (double) f;
|
|
|
|
double d1 = (entityplayer.n + (entityplayer.q - entityplayer.n) * (double) f + 1.6200000000000001D) - (double) entityplayer.H;
|
|
|
|
double d2 = entityplayer.o + (entityplayer.r - entityplayer.o) * (double) f;
|
|
|
|
Vec3D vec3d = Vec3D.b(d, d1, d2);
|
|
|
|
float f3 = MathHelper.b(-f2 * 0.01745329F - 3.141593F);
|
|
|
|
float f4 = MathHelper.a(-f2 * 0.01745329F - 3.141593F);
|
|
|
|
float f5 = -MathHelper.b(-f1 * 0.01745329F);
|
|
|
|
float f6 = MathHelper.a(-f1 * 0.01745329F);
|
|
|
|
float f7 = f4 * f5;
|
|
|
|
float f8 = f6;
|
|
|
|
float f9 = f3 * f5;
|
|
|
|
double d3 = 5D;
|
|
|
|
Vec3D vec3d1 = vec3d.c((double) f7 * d3, (double) f8 * d3, (double) f9 * d3);
|
|
|
|
MovingObjectPosition movingobjectposition = world.a(vec3d, vec3d1, true);
|
|
|
|
|
|
|
|
if (movingobjectposition == null) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
2011-01-14 14:31:10 +01:00
|
|
|
if (movingobjectposition.a == EnumMovingObjectType.a) {
|
2011-01-08 12:18:05 +01:00
|
|
|
int i = movingobjectposition.b;
|
|
|
|
int j = movingobjectposition.c;
|
|
|
|
int k = movingobjectposition.d;
|
|
|
|
|
|
|
|
if (!world.z) {
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit start - Boat placement
|
2011-01-23 13:23:13 +01:00
|
|
|
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
|
|
|
CraftServer craftServer = ((WorldServer) world).getServer();
|
|
|
|
|
|
|
|
Type eventType = Type.PLAYER_ITEM;
|
|
|
|
Player who = (entityplayer == null)?null:(Player)entityplayer.getBukkitEntity();
|
|
|
|
org.bukkit.inventory.ItemStack itemInHand = new CraftItemStack(itemstack);
|
|
|
|
org.bukkit.block.Block blockClicked = craftWorld.getBlockAt(i, j, k);
|
|
|
|
BlockFace blockFace = CraftBlock.notchToBlockFace(movingobjectposition.e);
|
|
|
|
|
|
|
|
PlayerItemEvent pie = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
|
|
|
|
craftServer.getPluginManager().callEvent(pie);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-23 13:23:13 +01:00
|
|
|
if (pie.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
world.a(((Entity) (new EntityBoat(world, (float) i + 0.5F, (float) j + 1.5F, (float) k + 0.5F))));
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
|
|
|
itemstack.a--;
|
|
|
|
}
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
}
|