Search in sources :

Example 11 with BlockLocation

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));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ModInventory(riskyken.armourersWorkshop.common.inventory.ModInventory) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation)

Example 12 with BlockLocation

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());
            }
        }
    }
}
Also used : BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation)

Example 13 with BlockLocation

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;
}
Also used : Rectangle3D(riskyken.armourersWorkshop.api.common.skin.Rectangle3D) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation)

Example 14 with BlockLocation

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockSkinnable(riskyken.armourersWorkshop.common.blocks.BlockSkinnable) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) Block(net.minecraft.block.Block) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) TileEntitySkinnable(riskyken.armourersWorkshop.common.tileentities.TileEntitySkinnable)

Example 15 with BlockLocation

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;
}
Also used : BlockSkinnable(riskyken.armourersWorkshop.common.blocks.BlockSkinnable) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation) TileEntitySkinnable(riskyken.armourersWorkshop.common.tileentities.TileEntitySkinnable)

Aggregations

BlockLocation (riskyken.armourersWorkshop.common.blocks.BlockLocation)21 Block (net.minecraft.block.Block)14 IPantableBlock (riskyken.armourersWorkshop.api.common.painting.IPantableBlock)10 TileEntity (net.minecraft.tileentity.TileEntity)8 TileEntityArmourer (riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer)7 MessageClientToolPaintBlock (riskyken.armourersWorkshop.common.network.messages.client.MessageClientToolPaintBlock)5 ArrayList (java.util.ArrayList)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IPantable (riskyken.armourersWorkshop.api.common.painting.IPantable)2 BlockColourable (riskyken.armourersWorkshop.common.blocks.BlockColourable)2 BlockSkinnable (riskyken.armourersWorkshop.common.blocks.BlockSkinnable)2 PaintType (riskyken.armourersWorkshop.common.painting.PaintType)2 TileEntitySkinnable (riskyken.armourersWorkshop.common.tileentities.TileEntitySkinnable)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 Color (java.awt.Color)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1