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-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;
|
|
|
|
Vec3D vec3d = Vec3D.b(d0, d1, d2);
|
|
|
|
float f3 = MathHelper.b(-f2 * 0.017453292F - 3.1415927F);
|
|
|
|
float f4 = MathHelper.a(-f2 * 0.017453292F - 3.1415927F);
|
|
|
|
float f5 = -MathHelper.b(-f1 * 0.017453292F);
|
|
|
|
float f6 = MathHelper.a(-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;
|
|
|
|
Vec3D vec3d1 = vec3d.c((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
|
2011-01-08 12:18:05 +01:00
|
|
|
MovingObjectPosition movingobjectposition = world.a(vec3d, vec3d1, true);
|
|
|
|
|
|
|
|
if (movingobjectposition == null) {
|
|
|
|
return itemstack;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
|
|
|
if (movingobjectposition.a == EnumMovingObjectType.TILE) {
|
|
|
|
int i = movingobjectposition.b;
|
|
|
|
int j = movingobjectposition.c;
|
|
|
|
int k = movingobjectposition.d;
|
|
|
|
|
|
|
|
if (!world.isStatic) {
|
|
|
|
// CraftBukkit start - Boat placement
|
|
|
|
CraftWorld craftWorld = ((WorldServer) world).getWorld();
|
|
|
|
CraftServer craftServer = ((WorldServer) world).getServer();
|
|
|
|
|
|
|
|
Type eventType = Type.PLAYER_ITEM;
|
|
|
|
Player who = (entityhuman == null) ? null : (Player) entityhuman.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);
|
2011-01-08 12:18:05 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
PlayerItemEvent event = new PlayerItemEvent(eventType, who, itemInHand, blockClicked, blockFace);
|
|
|
|
craftServer.getPluginManager().callEvent(event);
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (event.isCancelled()) {
|
|
|
|
return itemstack;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
world.a((Entity) (new EntityBoat(world, (double) ((float) i + 0.5F), (double) ((float) j + 1.5F), (double) ((float) k + 0.5F))));
|
2011-01-23 13:23:13 +01:00
|
|
|
}
|
2011-01-11 09:25:13 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
--itemstack.count;
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
return itemstack;
|
2011-01-08 12:18:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|