Search in sources :

Example 36 with SkinPointer

use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.

the class SkinNBTHelper method addSkinDataToStack.

public static void addSkinDataToStack(ItemStack stack, SkinIdentifier identifier, boolean lockSkin, ISkinDye skinDye) {
    SkinPointer skinData;
    if (skinDye != null) {
        skinData = new SkinPointer(identifier, skinDye, lockSkin);
    } else {
        skinData = new SkinPointer(identifier, lockSkin);
    }
    addSkinDataToStack(stack, skinData);
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer)

Example 37 with SkinPointer

use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.

the class SkinNBTHelper method isSkinLockedOnStack.

public static boolean isSkinLockedOnStack(ItemStack stack) {
    if (!stackHasSkinData(stack)) {
        return false;
    }
    SkinPointer skinData = new SkinPointer();
    skinData.readFromCompound(stack.getTagCompound());
    return skinData.lockSkin;
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer)

Example 38 with SkinPointer

use of riskyken.armourersWorkshop.common.skin.data.SkinPointer 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 39 with SkinPointer

use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.

the class EntityEquipmentData method fromBytes.

private void fromBytes(ByteBuf buf) {
    int itemCount = buf.readByte();
    skinPointerMap.clear();
    for (int i = 0; i < itemCount; i++) {
        NBTTagCompound compound = ByteBufUtils.readTag(buf);
        String skinKey = ByteBufUtils.readUTF8String(buf);
        SkinPointer skinPointer = new SkinPointer();
        skinPointer.readFromCompound(compound);
        skinPointerMap.put(skinKey, skinPointer);
    }
}
Also used : ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 40 with SkinPointer

use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.

the class TileEntitySkinLibrary method saveArmour.

/**
 * Save armour data from an items NBT data into a file on the disk.
 * @param filePath
 * @param filename The name of the file to save to.
 * @param player The player that pressed the save button.
 * @param publicFiles If true save to the public file list or false for the players private files.
 */
public void saveArmour(String fileName, String filePath, EntityPlayerMP player, boolean publicFiles) {
    ItemStack stackInput = getStackInSlot(0);
    ItemStack stackOutput = getStackInSlot(1);
    if (stackInput == null) {
        return;
    }
    if (stackOutput != null) {
        return;
    }
    if (!(stackInput.getItem() instanceof ItemSkin)) {
        return;
    }
    if (!SkinNBTHelper.stackHasSkinData(stackInput)) {
        return;
    }
    SkinPointer skinPointer = SkinNBTHelper.getSkinPointerFromStack(stackInput);
    if (skinPointer == null) {
        return;
    }
    if (!publicFiles) {
    // filePath = "/private/" + player.getUniqueID().toString() + filePath;
    }
    ModLogger.log("save");
    Skin skin = CommonSkinCache.INSTANCE.getSkin(skinPointer);
    if (skin == null) {
        ModLogger.log("no input");
        return;
    }
    ModLogger.log("save");
    filePath = SkinIOUtils.makeFilePathValid(filePath);
    fileName = SkinIOUtils.makeFileNameValid(fileName);
    LibraryFile file = new LibraryFile(fileName, filePath, skin.getSkinType());
    // if the file was overwritten remove it's old id link
    CommonSkinCache.INSTANCE.clearFileNameIdLink(file);
    if (!SkinIOUtils.saveSkinFromFileName(filePath, fileName + SkinIOUtils.SKIN_FILE_EXTENSION, skin)) {
        return;
    }
    if (ArmourersWorkshop.isDedicated()) {
        if (publicFiles) {
            ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.SERVER_PUBLIC, player);
        } else {
            ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.SERVER_PRIVATE, player);
        }
    } else {
        ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.LOCAL, player);
    }
    this.decrStackSize(0, 1);
    this.setInventorySlotContents(1, stackInput);
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ItemSkin(riskyken.armourersWorkshop.common.items.ItemSkin) ItemSkin(riskyken.armourersWorkshop.common.items.ItemSkin) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) MessageServerLibrarySendSkin(riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)64 ItemStack (net.minecraft.item.ItemStack)28 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)19 ISkinPointer (riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer)15 Item (net.minecraft.item.Item)13 ISkinDye (riskyken.armourersWorkshop.api.common.skin.data.ISkinDye)8 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)7 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)7 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)6 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)4 Minecraft (net.minecraft.client.Minecraft)3 ScaledResolution (net.minecraft.client.gui.ScaledResolution)3 ItemBlock (net.minecraft.item.ItemBlock)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 AbstractModelSkin (riskyken.armourersWorkshop.client.model.skin.AbstractModelSkin)3 MessageServerLibrarySendSkin (riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin)3 SkinDye (riskyken.armourersWorkshop.common.skin.data.SkinDye)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2