Search in sources :

Example 1 with SkinProperty

use of riskyken.armourersWorkshop.common.skin.data.SkinProperty 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)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)1 ISkinHolder (riskyken.armourersWorkshop.common.skin.ISkinHolder)1 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)1 SkinProperties (riskyken.armourersWorkshop.common.skin.data.SkinProperties)1 SkinProperty (riskyken.armourersWorkshop.common.skin.data.SkinProperty)1