Search in sources :

Example 1 with ItemSkin

use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.

the class TileEntitySkinLibrary method sendArmourToClient.

public void sendArmourToClient(String filename, String filePath, EntityPlayerMP player) {
    if (!ConfigHandler.allowClientsToDownloadSkins) {
        return;
    }
    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);
    Skin skin = CommonSkinCache.INSTANCE.getSkin(skinPointer);
    if (skin == null) {
        return;
    }
    LibraryFile file = new LibraryFile(filename, filePath, skin.getSkinType());
    // if the file was overwritten remove it's old id link
    CommonSkinCache.INSTANCE.clearFileNameIdLink(file);
    // ModLogger.log(file.getFullName());
    MessageServerLibrarySendSkin message = new MessageServerLibrarySendSkin(filename, filePath, skin, SendType.LIBRARY_SAVE);
    PacketHandler.networkWrapper.sendTo(message, 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) MessageServerLibrarySendSkin(riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemSkin

use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.

the class ContainerEntityEquipment method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotId) {
    Slot slot = getSlot(slotId);
    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        ItemStack result = stack.copy();
        if (slotId < skinSlots) {
            // Moving item to main inv
            if (!this.mergeItemStack(stack, skinSlots + 9, skinSlots + 36, false)) {
                // Moving item to hotbar
                if (!this.mergeItemStack(stack, skinSlots, skinSlots + 9, false)) {
                    return null;
                }
            }
        } else {
            if (stack.getItem() instanceof ItemSkin & SkinNBTHelper.stackHasSkinData(stack)) {
                boolean slotted = false;
                for (int i = 0; i < skinSlots; i++) {
                    Slot targetSlot = getSlot(i);
                    if (targetSlot.isItemValid(stack)) {
                        if (this.mergeItemStack(stack, i, i + 1, false)) {
                            slotted = true;
                            break;
                        }
                    }
                }
                if (!slotted) {
                    return null;
                }
            } else {
                return null;
            }
        }
        if (stack.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
        slot.onPickupFromSlot(entityPlayer, stack);
        return result;
    }
    return null;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemSkin(riskyken.armourersWorkshop.common.items.ItemSkin) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemSkin

use of riskyken.armourersWorkshop.common.items.ItemSkin 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)

Example 4 with ItemSkin

use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.

the class TileEntityArmourer method loadArmourItem.

/**
 * Reads the NBT data from an item and places blocks in the world.
 * @param player The player that pressed the load button.
 */
public void loadArmourItem(EntityPlayerMP player) {
    if (getWorldObj().isRemote) {
        return;
    }
    ItemStack stackInput = this.getStackInSlot(0);
    ItemStack stackOuput = this.getStackInSlot(1);
    if (stackInput == null) {
        return;
    }
    if (stackOuput != null) {
        return;
    }
    if (!(stackInput.getItem() instanceof ItemSkin)) {
        return;
    }
    SkinPointer skinPointerInput = SkinNBTHelper.getSkinPointerFromStack(stackInput);
    if (skinPointerInput == null) {
        return;
    }
    if (skinType == null) {
        return;
    }
    if (skinType != skinPointerInput.getIdentifier().getSkinType()) {
        if (!(skinType == SkinTypeRegistry.skinLegs && skinPointerInput.getIdentifier().getSkinType() == SkinTypeRegistry.skinSkirt)) {
            return;
        }
    }
    Skin skin = CommonSkinCache.INSTANCE.getSkin(skinPointerInput);
    if (skin == null) {
        return;
    }
    setSkinProps(new SkinProperties(skin.getProperties()));
    ArmourerWorldHelper.loadSkinIntoWorld(worldObj, xCoord, yCoord + HEIGHT_OFFSET, zCoord, skin, direction);
    if (skin.hasPaintData()) {
        this.paintData = skin.getPaintData().clone();
    } else {
        clearPaintData(true);
    }
    dirtySync();
    this.setInventorySlotContents(0, null);
    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) ItemStack(net.minecraft.item.ItemStack) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Example 5 with ItemSkin

use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.

the class ContainerArmourLibrary method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
    Slot slot = getSlot(slotID);
    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        ItemStack result = stack.copy();
        if (slotID < 36) {
            if ((stack.getItem() instanceof ItemSkinTemplate & stack.getItemDamage() == 0) | stack.getItem() instanceof ItemSkin) {
                if (!this.mergeItemStack(stack, 36, 37, false)) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            if (!this.mergeItemStack(stack, 9, 36, false)) {
                if (!this.mergeItemStack(stack, 0, 9, false)) {
                    return null;
                }
            }
        }
        if (stack.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
        slot.onPickupFromSlot(player, stack);
        return result;
    }
    return null;
}
Also used : ItemSkinTemplate(riskyken.armourersWorkshop.common.items.ItemSkinTemplate) Slot(net.minecraft.inventory.Slot) ItemSkin(riskyken.armourersWorkshop.common.items.ItemSkin) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)7 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)7 Slot (net.minecraft.inventory.Slot)4 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)3 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)3 ItemSkinTemplate (riskyken.armourersWorkshop.common.items.ItemSkinTemplate)2 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)2 MessageServerLibrarySendSkin (riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin)2 ItemArmourContainerItem (riskyken.armourersWorkshop.common.items.ItemArmourContainerItem)1 SkinProperties (riskyken.armourersWorkshop.common.skin.data.SkinProperties)1