Search in sources :

Example 1 with ModInventory

use of riskyken.armourersWorkshop.common.inventory.ModInventory in project Armourers-Workshop by RiskyKen.

the class TileEntitySkinnable method setSkinPointer.

public void setSkinPointer(Skin skin, SkinPointer skinPointer) {
    this.skinPointer = skinPointer;
    if (skin != null & isParent()) {
        SkinProperties skinProps = skin.getProperties();
        if (SkinProperties.PROP_BLOCK_INVENTORY.getValue(skin.getProperties())) {
            blockInventory = true;
            int size = SkinProperties.PROP_BLOCK_INVENTORY_WIDTH.getValue(skin.getProperties()) * SkinProperties.PROP_BLOCK_INVENTORY_HEIGHT.getValue(skin.getProperties());
            inventory = new ModInventory(LibBlockNames.SKINNABLE, size, this);
        }
    }
    markDirty();
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
Also used : ModInventory(riskyken.armourersWorkshop.common.inventory.ModInventory) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Example 2 with ModInventory

use of riskyken.armourersWorkshop.common.inventory.ModInventory 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)

Aggregations

ModInventory (riskyken.armourersWorkshop.common.inventory.ModInventory)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ISkinPointer (riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer)1 BlockLocation (riskyken.armourersWorkshop.common.blocks.BlockLocation)1 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)1 SkinProperties (riskyken.armourersWorkshop.common.skin.data.SkinProperties)1