Search in sources :

Example 6 with ISkinType

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

the class EquipmentRenderHandler method renderSkin.

@Override
public boolean renderSkin(ISkinPointer skinPointer) {
    ISkinType skinType = skinPointer.getIdentifier().getSkinType();
    for (int i = 0; i < skinType.getSkinParts().size(); i++) {
        // TODO Offset each part when rendering.
        ISkinPartType skinPartType = skinType.getSkinParts().get(i);
        renderSkinPart(skinPointer, skinPartType);
    }
    return false;
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)

Example 7 with ISkinType

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

the class SkinIdentifierSerializer method readFromCompound.

public static SkinIdentifier readFromCompound(NBTTagCompound compound) {
    int localId = 0;
    ILibraryFile libraryFile = null;
    int globalId = 0;
    ISkinType skinType = null;
    NBTTagCompound idDataCompound = compound.getCompoundTag(TAG_SKIN_ID_DATA);
    localId = idDataCompound.getInteger(TAG_SKIN_LOCAL_ID);
    if (idDataCompound.hasKey(TAG_SKIN_LIBRARY_FILE, NBT.TAG_STRING)) {
        libraryFile = new LibraryFile(idDataCompound.getString(TAG_SKIN_LIBRARY_FILE));
    }
    globalId = idDataCompound.getInteger(TAG_SKIN_GLOBAL_ID);
    skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(idDataCompound.getString(TAG_SKIN_TYPE));
    if (compound.hasKey(TAG_SKIN_OLD_ID, NBT.TAG_INT)) {
        localId = compound.getInteger(TAG_SKIN_OLD_ID);
    }
    if (compound.hasKey(TAG_SKIN_TYPE, NBT.TAG_STRING)) {
        skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(compound.getString(TAG_SKIN_TYPE));
    }
    return new SkinIdentifier(localId, libraryFile, globalId, skinType);
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 8 with ISkinType

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

the class SkinSerializer method readSkinTypeNameFromStream.

public static ISkinType readSkinTypeNameFromStream(DataInputStream stream) throws IOException, NewerFileVersionException {
    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);
        }
    }
    return equipmentSkinType;
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) IOException(java.io.IOException) NewerFileVersionException(riskyken.armourersWorkshop.common.exception.NewerFileVersionException) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Example 9 with ISkinType

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

the class EntitySkinHandler method dropEntitySkins.

private void dropEntitySkins(Entity entity) {
    if (ConfigHandler.entityDropSkinChance <= 0) {
        return;
    }
    int rnd = entity.worldObj.rand.nextInt(99) + 1;
    if (rnd <= ConfigHandler.entityDropSkinChance) {
        ExPropsEntityEquipmentData entityEquipmentData = ExPropsEntityEquipmentData.getExtendedPropsForEntity(entity);
        if (entityEquipmentData != null) {
            ArrayList<ISkinType> skinTypes = entityEquipmentData.getSkinInventory().getSkinTypes();
            for (int i = 0; i < skinTypes.size(); i++) {
                ISkinPointer skinPointer = entityEquipmentData.getEquipmentData().getSkinPointer(skinTypes.get(i), 0);
                if (skinPointer != null) {
                    ItemStack stack = SkinNBTHelper.makeEquipmentSkinStack((SkinPointer) skinPointer);
                    UtilItems.spawnItemAtEntity(entity, stack);
                }
            }
        }
    }
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) ItemStack(net.minecraft.item.ItemStack)

Example 10 with ISkinType

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

the class EntitySkinHandler method giveRandomSkin.

public void giveRandomSkin(ExPropsEntityEquipmentData entityEquipmentData) {
    if (entityEquipmentData == null) {
        return;
    }
    if (ConfigHandler.enitiySpawnWithSkinsChance <= 0) {
        return;
    }
    ArrayList<ISkinType> skinTypes = entityEquipmentData.getSkinInventory().getSkinTypes();
    for (int i = 0; i < skinTypes.size(); i++) {
        int rnd = entityEquipmentData.getEntity().worldObj.rand.nextInt(99) + 1;
        if (rnd >= ConfigHandler.enitiySpawnWithSkinsChance) {
            continue;
        }
        ISkinType skinType = skinTypes.get(i);
        LibraryFile libraryFile = getRandomSkinOfType(skinType);
        if (libraryFile == null) {
            continue;
        }
        SkinIdentifier identifier = new SkinIdentifier(0, libraryFile, 0, skinType);
        ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(identifier));
        if (skinStack == null) {
            continue;
        }
        entityEquipmentData.getSkinInventory().setInventorySlotContents(i, skinStack);
    }
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

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