Search in sources :

Example 1 with ISkinHolder

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

the class TileEntitySkinLibrary method loadArmour.

/**
 * Loads an armour file from the disk and adds it to an items NBT data.
 * @param filePath
 * @param filename The name of the file to load.
 * @param player The player that pressed the load button.
 */
public void loadArmour(String fileName, String filePath, EntityPlayerMP player, boolean trackFile) {
    ItemStack stackInput = getStackInSlot(0);
    ItemStack stackOutput = getStackInSlot(1);
    if (!isCreativeLibrary()) {
        if (stackInput == null) {
            return;
        }
    }
    if (stackOutput != null) {
        return;
    }
    if (!isCreativeLibrary()) {
        if (!(stackInput.getItem() instanceof ISkinHolder)) {
            return;
        }
    }
    Skin skin = null;
    String fullFileName = fileName;
    skin = SkinIOUtils.loadSkinFromFileName(filePath + fileName + SkinIOUtils.SKIN_FILE_EXTENSION);
    if (skin == null) {
        return;
    }
    LibraryFile libraryFile = new LibraryFile(fileName, filePath, skin.getSkinType());
    SkinIdentifier identifier = null;
    if (trackFile) {
        identifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    } else {
        identifier = new SkinIdentifier(skin.lightHash(), null, 0, skin.getSkinType());
    }
    // TODO Set master using trackFile
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    ModLogger.log("Loaded file form lib: " + libraryFile.toString());
    ItemStack stackArmour = SkinNBTHelper.makeEquipmentSkinStack(skin, identifier);
    if (stackArmour == null) {
        return;
    }
    if (!isCreativeLibrary()) {
        this.decrStackSize(0, 1);
    }
    this.setInventorySlotContents(1, stackArmour);
}
Also used : ISkinHolder(riskyken.armourersWorkshop.common.skin.ISkinHolder) 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) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 2 with ISkinHolder

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

the class TileEntitySkinLibrary method loadArmour.

public void loadArmour(Skin skin, EntityPlayerMP player) {
    ItemStack stackInput = getStackInSlot(0);
    ItemStack stackOutput = getStackInSlot(1);
    if (!isCreativeLibrary()) {
        if (stackInput == null) {
            return;
        }
    }
    if (stackOutput != null) {
        return;
    }
    if (!isCreativeLibrary()) {
        if (!(stackInput.getItem() instanceof ISkinHolder)) {
            return;
        }
    }
    ItemStack inputItem = SkinNBTHelper.makeEquipmentSkinStack(skin);
    if (inputItem == null) {
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, (LibraryFile) null);
    this.decrStackSize(0, 1);
    this.setInventorySlotContents(1, inputItem);
}
Also used : ISkinHolder(riskyken.armourersWorkshop.common.skin.ISkinHolder) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISkinHolder

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

the class TileEntityArmourer method saveArmourItem.

/**
 * Get blocks in the world and saved them onto an items NBT data.
 * @param player The player that pressed the save button.
 * @param name Custom name for the item.
 */
public void saveArmourItem(EntityPlayerMP player, String customName, String tags) {
    if (getWorldObj().isRemote) {
        return;
    }
    ItemStack stackInput = getStackInSlot(0);
    ItemStack stackOutput = getStackInSlot(1);
    if (stackInput == null) {
        return;
    }
    if (stackOutput != null) {
        return;
    }
    if (!(stackInput.getItem() instanceof ISkinHolder)) {
        return;
    }
    ISkinHolder inputItem = (ISkinHolder) stackInput.getItem();
    Skin armourItemData = null;
    SkinProperties skinProps = new SkinProperties();
    skinProps.setProperty(Skin.KEY_AUTHOR_NAME, player.getCommandSenderName());
    if (player.getGameProfile() != null && player.getGameProfile().getId() != null) {
        skinProps.setProperty(Skin.KEY_AUTHOR_UUID, player.getGameProfile().getId().toString());
    }
    skinProps.setProperty(Skin.KEY_CUSTOM_NAME, customName);
    for (int i = 0; i < skinType.getProperties().size(); i++) {
        SkinProperty skinProp = (SkinProperty) skinType.getProperties().get(i);
        skinProp.setValue(skinProps, skinProp.getValue(this.skinProps));
    }
    try {
        armourItemData = ArmourerWorldHelper.saveSkinFromWorld(worldObj, skinProps, skinType, paintData, xCoord, yCoord + HEIGHT_OFFSET, zCoord, direction);
    } catch (SkinSaveException e) {
        switch(e.getType()) {
            case NO_DATA:
                player.addChatMessage(new ChatComponentText(e.getMessage()));
                break;
            case MARKER_ERROR:
                player.addChatMessage(new ChatComponentText(e.getMessage()));
                break;
            case MISSING_PARTS:
                player.addChatMessage(new ChatComponentText(e.getMessage()));
                break;
            case BED_AND_SEAT:
                player.addChatMessage(new ChatComponentText(e.getMessage()));
                break;
            case INVALID_MULTIBLOCK:
                player.addChatMessage(new ChatComponentText(e.getMessage()));
                break;
        }
    }
    if (armourItemData == null) {
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(armourItemData, (LibraryFile) null);
    stackOutput = inputItem.makeStackForEquipment(armourItemData);
    if (stackOutput == null) {
        return;
    }
    this.decrStackSize(0, 1);
    setInventorySlotContents(1, stackOutput);
}
Also used : SkinSaveException(riskyken.armourersWorkshop.common.exception.SkinSaveException) ISkinHolder(riskyken.armourersWorkshop.common.skin.ISkinHolder) ItemSkin(riskyken.armourersWorkshop.common.items.ItemSkin) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) ItemStack(net.minecraft.item.ItemStack) SkinProperty(riskyken.armourersWorkshop.common.skin.data.SkinProperty) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ItemStack (net.minecraft.item.ItemStack)3 ISkinHolder (riskyken.armourersWorkshop.common.skin.ISkinHolder)3 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)2 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)2 ChatComponentText (net.minecraft.util.ChatComponentText)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)1 MessageServerLibrarySendSkin (riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin)1 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)1 SkinProperties (riskyken.armourersWorkshop.common.skin.data.SkinProperties)1 SkinProperty (riskyken.armourersWorkshop.common.skin.data.SkinProperty)1