Search in sources :

Example 16 with ISkinType

use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.

the class LibraryFile method readFromByteBuf.

public static LibraryFile readFromByteBuf(ByteBuf buf) {
    String fileName = ByteBufUtils.readUTF8String(buf);
    String filePath = ByteBufUtils.readUTF8String(buf);
    boolean directory = buf.readBoolean();
    ISkinType skinType = null;
    if (buf.readBoolean()) {
        String regName = ByteBufUtils.readUTF8String(buf);
        skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(regName);
    }
    return new LibraryFile(fileName, filePath, skinType, directory);
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile)

Example 17 with ISkinType

use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.

the class SkinIOUtils method getSkinTypeNameFromFile.

public static ISkinType getSkinTypeNameFromFile(File file) {
    DataInputStream stream = null;
    ISkinType skinType = null;
    try {
        stream = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
        skinType = SkinSerializer.readSkinTypeNameFromStream(stream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        ModLogger.log(Level.ERROR, "File name: " + file.getName());
    } catch (IOException e) {
        e.printStackTrace();
        ModLogger.log(Level.ERROR, "File name: " + file.getName());
    } catch (NewerFileVersionException e) {
        e.printStackTrace();
        ModLogger.log(Level.ERROR, "File name: " + file.getName());
    } catch (Exception e) {
        ModLogger.log(Level.ERROR, "Unable to load skin name. Unknown error.");
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return skinType;
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) NewerFileVersionException(riskyken.armourersWorkshop.common.exception.NewerFileVersionException) FileInputStream(java.io.FileInputStream) NewerFileVersionException(riskyken.armourersWorkshop.common.exception.NewerFileVersionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvalidCubeTypeException(riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException)

Example 18 with ISkinType

use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.

the class EquipmentWardrobeData method saveNBTData.

public void saveNBTData(NBTTagCompound compound) {
    compound.setInteger(TAG_SKIN_COLOUR, this.skinColour);
    compound.setInteger(TAG_HAIR_COLOUR, this.hairColour);
    for (int i = 0; i < 4; i++) {
        compound.setBoolean(TAG_ARMOUR_OVERRIDE + i, this.armourOverride.get(i));
    }
    compound.setBoolean(TAG_HEAD_OVERLAY, this.headOverlay);
    compound.setBoolean(TAG_LIMIT_LIMBS, this.limitLimbs);
    NBTTagList slotsList = new NBTTagList();
    ISkinType[] validSkins = ExPropsPlayerSkinData.validSkins;
    for (int i = 0; i < validSkins.length; i++) {
        ISkinType skinType = validSkins[i];
        NBTTagCompound slotCount = new NBTTagCompound();
        slotCount.setString(TAG_SLOT_KEY, skinType.getRegistryName());
        slotCount.setInteger(TAG_SLOT_VALUE, getUnlockedSlotsForSkinType(skinType));
        slotsList.appendTag(slotCount);
    }
    compound.setTag(TAG_SLOTS_UNLOCKED, slotsList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 19 with ISkinType

use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.

the class EquipmentWardrobeData method toBytes.

public void toBytes(ByteBuf buf) {
    buf.writeInt(this.skinColour);
    buf.writeInt(this.hairColour);
    for (int i = 0; i < 4; i++) {
        buf.writeBoolean(this.armourOverride.get(i));
    }
    buf.writeBoolean(this.headOverlay);
    buf.writeBoolean(this.limitLimbs);
    ISkinType[] validSkins = ExPropsPlayerSkinData.validSkins;
    for (int i = 0; i < validSkins.length; i++) {
        ISkinType skinType = validSkins[i];
        ByteBufUtils.writeUTF8String(buf, skinType.getRegistryName());
        buf.writeInt(getUnlockedSlotsForSkinType(skinType));
    }
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType)

Example 20 with ISkinType

use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.

the class SkinSerializer method readSkinFromStream.

public static Skin readSkinFromStream(DataInputStream stream) throws IOException, NewerFileVersionException, InvalidCubeTypeException {
    int fileVersion = stream.readInt();
    if (fileVersion > Skin.FILE_VERSION) {
        throw new NewerFileVersionException();
    }
    if (fileVersion > 12) {
        String header = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!header.equals(TAG_SKIN_HEADER)) {
            ModLogger.log(Level.ERROR, "Error loading skin header.");
        }
        String propsHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!propsHeader.equals(TAG_SKIN_PROPS_HEADER)) {
            ModLogger.log(Level.ERROR, "Error loading skin props header.");
        }
    }
    SkinProperties properties = new SkinProperties();
    boolean loadedProps = true;
    IOException e = null;
    if (fileVersion < 12) {
        String authorName = stream.readUTF();
        String customName = stream.readUTF();
        String tags = "";
        if (!(fileVersion < 4)) {
            tags = stream.readUTF();
        } else {
            tags = "";
        }
        properties.setProperty(Skin.KEY_AUTHOR_NAME, authorName);
        properties.setProperty(Skin.KEY_CUSTOM_NAME, customName);
        if (tags != null && !tags.equalsIgnoreCase("")) {
            properties.setProperty(KEY_TAGS, tags);
        }
    } else {
        try {
            properties.readFromStream(stream, fileVersion);
        } catch (IOException propE) {
            ModLogger.log(Level.ERROR, "prop load failed");
            e = propE;
            loadedProps = false;
        }
    }
    if (fileVersion > 12) {
        String propsFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!propsFooter.equals(TAG_SKIN_PROPS_FOOTER)) {
            ModLogger.log(Level.ERROR, "Error loading skin props footer.");
        }
        String typeHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!typeHeader.equals(TAG_SKIN_TYPE_HEADER)) {
            ModLogger.log(Level.ERROR, "Error loading skin type header.");
        }
    }
    ISkinType equipmentSkinType = null;
    if (fileVersion < 5) {
        if (loadedProps) {
            equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromLegacyId(stream.readByte() - 1);
        } else {
            throw e;
        }
    } else {
        if (loadedProps) {
            String regName = stream.readUTF();
            if (regName.equals(SkinTypeRegistry.skinSkirt.getRegistryName())) {
                regName = SkinTypeRegistry.skinLegs.getRegistryName();
            }
            equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(regName);
        } else {
            StringBuilder sb = new StringBuilder();
            while (true) {
                sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
                if (sb.toString().endsWith("armourers:")) {
                    break;
                }
            }
            ModLogger.log("Got armourers");
            sb = new StringBuilder();
            sb.append("armourers:");
            while (SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString()) == null) {
                sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
            }
            ModLogger.log(sb.toString());
            equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString());
            ModLogger.log("got failed type " + equipmentSkinType);
        }
    }
    if (fileVersion > 12) {
        String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!typeFooter.equals(TAG_SKIN_TYPE_FOOTER)) {
            ModLogger.log(Level.ERROR, "Error loading skin type footer.");
        }
    }
    if (equipmentSkinType == null) {
        throw new InvalidCubeTypeException();
    }
    if (fileVersion > 12) {
        String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!typeFooter.equals(TAG_SKIN_PAINT_HEADER)) {
            ModLogger.log(Level.ERROR, "Error loading skin paint header.");
        }
    }
    int[] paintData = null;
    if (fileVersion > 7) {
        boolean hasPaintData = stream.readBoolean();
        if (hasPaintData) {
            paintData = new int[SkinTexture.TEXTURE_SIZE];
            for (int i = 0; i < SkinTexture.TEXTURE_SIZE; i++) {
                paintData[i] = stream.readInt();
            }
        }
    }
    if (fileVersion > 12) {
        String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!typeFooter.equals(TAG_SKIN_PAINT_FOOTER)) {
            ModLogger.log(Level.ERROR, "Error loading skin paint footer.");
        }
    }
    int size = stream.readByte();
    ArrayList<SkinPart> parts = new ArrayList<SkinPart>();
    for (int i = 0; i < size; i++) {
        if (fileVersion > 12) {
            String partHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
            if (!partHeader.equals(TAG_SKIN_PART_HEADER)) {
                ModLogger.log(Level.ERROR, "Error loading skin part header.");
            }
        }
        SkinPart part = SkinPartSerializer.loadSkinPart(stream, fileVersion);
        if (fileVersion > 12) {
            String partFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
            if (!partFooter.equals(TAG_SKIN_PART_FOOTER)) {
                ModLogger.log(Level.ERROR, "Error loading skin part footer.");
            }
        }
        parts.add(part);
    }
    if (fileVersion > 12) {
        String footer = StreamUtils.readString(stream, Charsets.US_ASCII);
        if (!footer.equals(TAG_SKIN_FOOTER)) {
            ModLogger.log(Level.ERROR, "Error loading skin footer.");
        }
    }
    return new Skin(properties, equipmentSkinType, paintData, parts);
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart) InvalidCubeTypeException(riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) NewerFileVersionException(riskyken.armourersWorkshop.common.exception.NewerFileVersionException) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Aggregations

ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)38 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)6 ItemStack (net.minecraft.item.ItemStack)5 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 GuiButtonExt (cpw.mods.fml.client.config.GuiButtonExt)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Slot (net.minecraft.inventory.Slot)3 Item (net.minecraft.item.Item)3 ILibraryFile (riskyken.armourersWorkshop.api.common.library.ILibraryFile)3 GuiDropDownList (riskyken.armourersWorkshop.client.gui.controls.GuiDropDownList)3 NewerFileVersionException (riskyken.armourersWorkshop.common.exception.NewerFileVersionException)3 Point (java.awt.Point)2 Minecraft (net.minecraft.client.Minecraft)2 ScaledResolution (net.minecraft.client.gui.ScaledResolution)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 ISkinIdentifier (riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier)2