use of mcjty.rftools.blocks.spaceprojector.BuilderTileEntity in project RFTools by McJty.
the class ShapeCardItem method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float sx, float sy, float sz) {
if (!world.isRemote) {
int mode = getMode(stack);
if (mode == MODE_NONE) {
if (player.isSneaking()) {
if (world.getTileEntity(x, y, z) instanceof BuilderTileEntity) {
setCurrentBlock(stack, new GlobalCoordinate(new Coordinate(x, y, z), world.provider.dimensionId));
Logging.message(player, EnumChatFormatting.GREEN + "Now select the first corner");
setMode(stack, MODE_CORNER1);
setCorner1(stack, null);
} else {
Logging.message(player, EnumChatFormatting.RED + "You can only do this on a builder!");
}
} else {
return false;
}
} else if (mode == MODE_CORNER1) {
GlobalCoordinate currentBlock = getCurrentBlock(stack);
if (currentBlock.getDimension() != world.provider.dimensionId) {
Logging.message(player, EnumChatFormatting.RED + "The Builder is in another dimension!");
} else if (currentBlock.getCoordinate().equals(new Coordinate(x, y, z))) {
Logging.message(player, EnumChatFormatting.RED + "Cleared area selection mode!");
setMode(stack, MODE_NONE);
} else {
Logging.message(player, EnumChatFormatting.GREEN + "Now select the second corner");
setMode(stack, MODE_CORNER2);
setCorner1(stack, new Coordinate(x, y, z));
}
} else {
GlobalCoordinate currentBlock = getCurrentBlock(stack);
if (currentBlock.getDimension() != world.provider.dimensionId) {
Logging.message(player, EnumChatFormatting.RED + "The Builder is in another dimension!");
} else if (currentBlock.getCoordinate().equals(new Coordinate(x, y, z))) {
Logging.message(player, EnumChatFormatting.RED + "Cleared area selection mode!");
setMode(stack, MODE_NONE);
} else {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
stack.setTagCompound(tag);
}
Coordinate c1 = getCorner1(stack);
if (c1 == null) {
Logging.message(player, EnumChatFormatting.RED + "Cleared area selection mode!");
setMode(stack, MODE_NONE);
} else {
Logging.message(player, EnumChatFormatting.GREEN + "New settings copied to the shape card!");
System.out.println("currentBlock = " + currentBlock.getCoordinate());
System.out.println("corner1 = " + c1);
System.out.println("corner2 = " + x + ", " + y + ", " + z);
// Coordinate center = new Coordinate((int) ((c1.getX() + x) / 2.0f + .55f), (int) ((c1.getY() + y) / 2.0f + .55f), (int) ((c1.getZ() + z) / 2.0f + .55f));
Coordinate center = new Coordinate((int) Math.ceil((c1.getX() + x) / 2.0f), (int) Math.ceil((c1.getY() + y) / 2.0f), (int) Math.ceil((c1.getZ() + z) / 2.0f));
System.out.println("center = " + center);
tag.setInteger("dimX", Math.abs(c1.getX() - x) + 1);
tag.setInteger("dimY", Math.abs(c1.getY() - y) + 1);
tag.setInteger("dimZ", Math.abs(c1.getZ() - z) + 1);
tag.setInteger("offsetX", center.getX() - currentBlock.getCoordinate().getX());
tag.setInteger("offsetY", center.getY() - currentBlock.getCoordinate().getY());
tag.setInteger("offsetZ", center.getZ() - currentBlock.getCoordinate().getZ());
setMode(stack, MODE_NONE);
setCorner1(stack, null);
}
}
}
}
return true;
}
Aggregations