Search in sources :

Example 56 with SkinPointer

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

the class ContainerDyeTable method updateLockedSlots.

/**
 * Reads the input slot and locks dye slots that are in use.
 * @param stack
 */
private void updateLockedSlots(ItemStack stack) {
    SkinPointer skinPointer = SkinNBTHelper.getSkinPointerFromStack(stack);
    ISkinDye dye = skinPointer.getSkinDye();
    for (int i = 0; i < 8; i++) {
        if (dye.haveDyeInSlot(i)) {
            ((SlotDyeBottle) getSlot(37 + i)).setLocked(true);
        } else {
            ((SlotDyeBottle) getSlot(37 + i)).setLocked(false);
        }
    }
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ISkinDye(riskyken.armourersWorkshop.api.common.skin.data.ISkinDye) SlotDyeBottle(riskyken.armourersWorkshop.common.inventory.slot.SlotDyeBottle)

Example 57 with SkinPointer

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

the class CommandGiveSkin method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length < 3) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    String skinName = currentCommand[2];
    if (!skinName.substring(0, 1).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    int usedCommands = 2;
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        for (int i = 3; i < currentCommand.length; i++) {
            skinName += " " + currentCommand[i];
            if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
                usedCommands = i;
                break;
            }
        }
    }
    ModLogger.log("usedCommands used: " + usedCommands);
    ModLogger.log("total commands used: " + currentCommand.length);
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    skinName = skinName.replace("\"", "");
    SkinDye skinDye = new SkinDye();
    for (int i = usedCommands + 1; i < currentCommand.length; i++) {
        String dyeCommand = currentCommand[i];
        ModLogger.log("Command dye: " + dyeCommand);
        if (!dyeCommand.contains("-")) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        String[] commandSplit = dyeCommand.split("-");
        if (commandSplit.length != 2) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
        String dye = commandSplit[1];
        if (dye.startsWith("#") && dye.length() == 7) {
            // dye = dye.substring(2, 8);
            if (isValidHex(dye)) {
                Color dyeColour = Color.decode(dye);
                int r = dyeColour.getRed();
                int g = dyeColour.getGreen();
                int b = dyeColour.getBlue();
                skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
            } else {
                throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
            }
        } else if (dye.length() >= 5 & dye.contains(",")) {
            String[] dyeValues = dye.split(",");
            if (dyeValues.length != 3) {
                throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
            }
            int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
            int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
            int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
            skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
        } else {
            throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
        }
    }
    LibraryFile libraryFile = new LibraryFile(skinName);
    Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
    if (skin == null) {
        throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
    }
    try {
        skin.lightHash();
    } catch (Exception e) {
        ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
    EntityItem entityItem = player.dropPlayerItemWithRandomChoice(skinStack, false);
    entityItem.delayBeforeCanPickup = 0;
    entityItem.func_145797_a(player.getCommandSenderName());
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) SkinDye(riskyken.armourersWorkshop.common.skin.data.SkinDye) Color(java.awt.Color) WrongUsageException(net.minecraft.command.WrongUsageException) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 58 with SkinPointer

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

the class CommandSetSkin method processCommand.

@Override
public void processCommand(ICommandSender commandSender, String[] currentCommand) {
    if (currentCommand.length < 3) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) currentCommand);
    }
    String playerName = currentCommand[1];
    EntityPlayerMP player = getPlayer(commandSender, playerName);
    if (player == null) {
        return;
    }
    int slotNum = 0;
    slotNum = parseIntBounded(commandSender, currentCommand[2], 1, 8);
    String skinName = currentCommand[3];
    if (!skinName.substring(0, 1).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    int usedCommands = 3;
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        for (int i = 3; i < currentCommand.length; i++) {
            skinName += " " + currentCommand[i];
            if (skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
                usedCommands = i;
                break;
            }
        }
    }
    ModLogger.log("usedCommands used: " + usedCommands);
    ModLogger.log("total commands used: " + currentCommand.length);
    if (!skinName.substring(skinName.length() - 1, skinName.length()).equals("\"")) {
        throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
    }
    skinName = skinName.replace("\"", "");
    SkinDye skinDye = new SkinDye();
    for (int i = usedCommands + 1; i < currentCommand.length; i++) {
        String dyeCommand = currentCommand[i];
        ModLogger.log("Command dye: " + dyeCommand);
        if (!dyeCommand.contains("-")) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        String[] commandSplit = dyeCommand.split("-");
        if (commandSplit.length != 2) {
            throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
        }
        int dyeIndex = parseIntBounded(commandSender, commandSplit[0], 1, 8) - 1;
        String dye = commandSplit[1];
        if (dye.startsWith("#") && dye.length() == 7) {
            // dye = dye.substring(2, 8);
            if (isValidHex(dye)) {
                Color dyeColour = Color.decode(dye);
                int r = dyeColour.getRed();
                int g = dyeColour.getGreen();
                int b = dyeColour.getBlue();
                skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
            } else {
                throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
            }
        } else if (dye.length() >= 5 & dye.contains(",")) {
            String[] dyeValues = dye.split(",");
            if (dyeValues.length != 3) {
                throw new WrongUsageException(getCommandUsage(commandSender), (Object) skinName);
            }
            int r = parseIntBounded(commandSender, dyeValues[0], 0, 255);
            int g = parseIntBounded(commandSender, dyeValues[1], 0, 255);
            int b = parseIntBounded(commandSender, dyeValues[2], 0, 255);
            skinDye.addDye(dyeIndex, new byte[] { (byte) r, (byte) g, (byte) b, (byte) 255 });
        } else {
            throw new WrongUsageException("commands.armourers.invalidDyeFormat", (Object) dye);
        }
    }
    LibraryFile libraryFile = new LibraryFile(skinName);
    Skin skin = SkinIOUtils.loadSkinFromLibraryFile(libraryFile);
    if (skin == null) {
        throw new WrongUsageException("commands.armourers.fileNotFound", (Object) skinName);
    }
    try {
        skin.lightHash();
    } catch (Exception e) {
        ModLogger.log(Level.ERROR, String.format("Unable to create ID for file %s.", libraryFile.toString()));
        return;
    }
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    SkinIdentifier skinIdentifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(skinIdentifier, skinDye));
    ExPropsPlayerSkinData.get(player).setEquipmentStack(skinStack, slotNum - 1);
}
Also used : SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) SkinDye(riskyken.armourersWorkshop.common.skin.data.SkinDye) Color(java.awt.Color) WrongUsageException(net.minecraft.command.WrongUsageException) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack)

Example 59 with SkinPointer

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

the class RecipeSkinArmourContainer method getCraftingResult.

@Override
public ItemStack getCraftingResult(IInventory inventory) {
    ItemStack skinStack = null;
    ItemStack armourStack = null;
    for (int slotId = 0; slotId < inventory.getSizeInventory(); slotId++) {
        ItemStack stack = inventory.getStackInSlot(slotId);
        if (stack != null) {
            Item item = stack.getItem();
            if (isValidSkinForType(stack)) {
                if (skinStack != null) {
                    return null;
                }
                skinStack = stack;
            } else if (stack.getItem() == ModItems.armourContainerItem) {
                if (armourStack != null) {
                    return null;
                }
                armourStack = stack;
            } else {
                return null;
            }
        }
    }
    if (skinStack != null && armourStack != null) {
        SkinPointer skinPointer = SkinNBTHelper.getSkinPointerFromStack(skinStack);
        ItemStack returnStack = SkinNBTHelper.makeArmouerContainerStack(skinPointer);
        return returnStack;
    } else {
        return null;
    }
}
Also used : Item(net.minecraft.item.Item) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ItemStack(net.minecraft.item.ItemStack)

Example 60 with SkinPointer

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

the class RecipeSkinArmourContainer method isValidArmourForSkin.

private boolean isValidArmourForSkin(ItemStack armourStack, ItemStack skinStack) {
    SkinPointer sp = SkinNBTHelper.getSkinPointerFromStack(skinStack);
    ISkinType skinType = sp.getIdentifier().getSkinType();
    Item armourItem = armourStack.getItem();
    if (armourItem.isValidArmor(armourStack, skinType.getVanillaArmourSlotId(), null)) {
        return true;
    }
    return false;
}
Also used : Item(net.minecraft.item.Item) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType)

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