use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
boolean hasSkin = compound.getBoolean(TAG_HAS_SKIN);
nbtVersion = 0;
if (compound.hasKey(ModConstants.Tags.TAG_NBT_VERSION, Constants.NBT.TAG_INT)) {
nbtVersion = compound.getInteger(ModConstants.Tags.TAG_NBT_VERSION);
}
if (compound.hasKey(TAG_LINKED_BLOCK, Constants.NBT.TAG_INT_ARRAY)) {
int[] loc = compound.getIntArray(TAG_LINKED_BLOCK);
linkedBlock = new BlockLocation(loc[0], loc[1], loc[2]);
} else {
linkedBlock = null;
}
if (hasSkin) {
skinPointer = new SkinPointer();
skinPointer.readFromCompound(compound);
if (compound.hasKey(TAG_RELATED_BLOCKS, Constants.NBT.TAG_LIST)) {
NBTTagList list = compound.getTagList(TAG_RELATED_BLOCKS, Constants.NBT.TAG_COMPOUND);
relatedBlocks = new ArrayList<BlockLocation>();
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound blockCompound = (NBTTagCompound) list.getCompoundTagAt(i);
int x = blockCompound.getInteger(TAG_X);
int y = blockCompound.getInteger(TAG_Y);
int z = blockCompound.getInteger(TAG_Z);
BlockLocation blockLoc = new BlockLocation(x, y, z);
relatedBlocks.add(blockLoc);
}
} else {
relatedBlocks = null;
}
blockInventory = false;
inventory = null;
if (isParent()) {
if (compound.hasKey(TAG_BLOCK_INVENTORY, Constants.NBT.TAG_BYTE) && compound.getBoolean(TAG_BLOCK_INVENTORY)) {
int size = 36;
if (compound.hasKey(TAG_BLOCK_INVENTORY_SIZE, NBT.TAG_INT)) {
size = compound.getInteger(TAG_BLOCK_INVENTORY_SIZE);
}
blockInventory = true;
inventory = new ModInventory(LibBlockNames.SKINNABLE, size, this);
inventory.loadItemsFromNBT(compound);
}
}
} else {
skinPointer = null;
relatedBlocks = null;
ModLogger.log(Level.WARN, String.format("Skinnable tile at X:%d Y:%d Z:%d has no skin data.", xCoord, yCoord, zCoord));
}
}
use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method killChildren.
public void killChildren(World world) {
if (relatedBlocks != null) {
for (int i = 0; i < relatedBlocks.size(); i++) {
BlockLocation loc = relatedBlocks.get(i);
if (!(xCoord == loc.x & yCoord == loc.y & zCoord == loc.z)) {
ModLogger.log("Removing child: " + loc.toString());
world.setBlockToAir(loc.x, loc.y, loc.z);
world.removeTileEntity(loc.x, loc.y, loc.z);
} else {
ModLogger.log("Skipping child: " + loc.toString());
}
}
}
}
use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.
the class SkinPart method setupBlockBounds.
private void setupBlockBounds(int blockX, int blockY, int blockZ, int x, int y, int z) {
BlockLocation loc = new BlockLocation(blockX + 1, -blockY, blockZ);
if (blockGrid[loc.x][loc.y][loc.z] == null) {
blockGrid[loc.x][loc.y][loc.z] = new Rectangle3D(127, 127, 127, -127, -127, -127);
}
Rectangle3D rec = blockGrid[loc.x][loc.y][loc.z];
rec.setX(Math.min(rec.getX(), x));
rec.setY(Math.min(rec.getY(), y));
rec.setZ(Math.min(rec.getZ(), z));
rec.setWidth(Math.max(rec.getWidth(), x));
rec.setHeight(Math.max(rec.getHeight(), y));
rec.setDepth(Math.max(rec.getDepth(), z));
// blockGrid[loc.x][loc.y][loc.z] = rec;
}
use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.
the class ItemLinkingTool method onItemUseFirst.
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return false;
}
if (!world.isRemote) {
if (!hasLinkLocation(stack)) {
Block block = world.getBlock(x, y, z);
if (!(block instanceof BlockSkinnable)) {
setLinkLocation(stack, new BlockLocation(x, y, z));
player.addChatMessage(new ChatComponentTranslation("chat.armourersworkshop:linkingTool.start", (Object) null));
return true;
} else {
player.addChatMessage(new ChatComponentTranslation("chat.armourersworkshop:linkingTool.linkedToSkinnable", (Object) null));
return true;
}
} else {
BlockLocation loc = getLinkLocation(stack);
Block block = world.getBlock(x, y, z);
if (block instanceof BlockSkinnable) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntitySkinnable) {
((TileEntitySkinnable) te).getParent().setLinkedBlock(loc);
player.addChatMessage(new ChatComponentTranslation("chat.armourersworkshop:linkingTool.finish", (Object) null));
removeLinkLocation(stack);
return true;
}
}
}
removeLinkLocation(stack);
player.addChatMessage(new ChatComponentTranslation("chat.armourersworkshop:linkingTool.fail", (Object) null));
}
return true;
}
use of riskyken.armourersWorkshop.common.blocks.BlockLocation in project Armourers-Workshop by RiskyKen.
the class ItemSkin method placeSkinAtLocation.
private boolean placeSkinAtLocation(World world, EntityPlayer player, int side, ItemStack stack, int x, int y, int z, SkinPointer skinPointer) {
if (!canPlaceSkinAtLocation(world, player, side, stack, x, y, z, skinPointer)) {
return false;
}
ForgeDirection dir = UtilPlayer.getDirectionSide(player).getOpposite();
Skin skin = SkinUtils.getSkinDetectSide(stack, false, true);
if (skin == null) {
return false;
}
BlockSkinnable targetBlock = (BlockSkinnable) ModBlocks.skinnable;
if (SkinProperties.PROP_BLOCK_GLOWING.getValue(skin.getProperties())) {
targetBlock = (BlockSkinnable) ModBlocks.skinnableGlowing;
}
int meta = targetBlock.convertDirectionToMetadata(dir);
boolean multiblock = SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skin.getProperties());
ArrayList<BlockLocation> relatedBlocks = new ArrayList<BlockLocation>();
if (multiblock) {
if (!canPlaceChildren(world, player, side, stack, x, y, z, skin, skinPointer, relatedBlocks)) {
return false;
}
placeChildren(world, player, side, x, y, z, skin, skinPointer, relatedBlocks);
}
world.setBlock(x, y, z, targetBlock, meta, 2);
world.setTileEntity(x, y, z, ((ITileEntityProvider) targetBlock).createNewTileEntity(world, 0));
TileEntitySkinnable te = (TileEntitySkinnable) world.getTileEntity(x, y, z);
te.setSkinPointer(skin, skinPointer);
targetBlock.onBlockPlacedBy(world, x, y, z, player, stack);
targetBlock.onPostBlockPlaced(world, x, y, z, meta);
te.setRelatedBlocks(relatedBlocks);
// targetBlock.setFacingDirection(world, x, y, z, dir);
stack.stackSize--;
world.playSoundEffect((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F, "dig.stone", 1, 1);
return true;
}
Aggregations