Search in sources :

Example 11 with SkinProperties

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

the class TileEntityArmourer method clearArmourCubes.

public void clearArmourCubes(ISkinPartType partType) {
    if (skinType != null) {
        ArmourerWorldHelper.clearEquipmentCubes(worldObj, xCoord, yCoord + getHeightOffset(), zCoord, skinType, skinProps, partType);
        SkinProperties newSkinProps = new SkinProperties();
        SkinProperties.PROP_BLOCK_MULTIBLOCK.setValue(newSkinProps, SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skinProps));
        setSkinProps(newSkinProps);
        dirtySync();
    }
}
Also used : SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Example 12 with SkinProperties

use of riskyken.armourersWorkshop.common.skin.data.SkinProperties 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)

Example 13 with SkinProperties

use of riskyken.armourersWorkshop.common.skin.data.SkinProperties 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 14 with SkinProperties

use of riskyken.armourersWorkshop.common.skin.data.SkinProperties 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)

Example 15 with SkinProperties

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

the class MessageClientGuiSetArmourerSkinProps method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    NBTTagCompound compound = ByteBufUtils.readTag(buf);
    skinProps = new SkinProperties();
    skinProps.readFromNBT(compound);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SkinProperties(riskyken.armourersWorkshop.common.skin.data.SkinProperties)

Aggregations

SkinProperties (riskyken.armourersWorkshop.common.skin.data.SkinProperties)16 MessageClientGuiSetArmourerSkinProps (riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiSetArmourerSkinProps)4 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)3 IOException (java.io.IOException)2 ItemStack (net.minecraft.item.ItemStack)2 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)2 NewerFileVersionException (riskyken.armourersWorkshop.common.exception.NewerFileVersionException)2 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)2 GameProfile (com.mojang.authlib.GameProfile)1 ArrayList (java.util.ArrayList)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 GuiCheckBox (riskyken.armourersWorkshop.client.gui.controls.GuiCheckBox)1 GuiCustomSlider (riskyken.armourersWorkshop.client.gui.controls.GuiCustomSlider)1 GuiDropDownList (riskyken.armourersWorkshop.client.gui.controls.GuiDropDownList)1 GuiInventorySize (riskyken.armourersWorkshop.client.gui.controls.GuiInventorySize)1 PlayerTexture (riskyken.armourersWorkshop.client.texture.PlayerTexture)1 InvalidCubeTypeException (riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 ModInventory (riskyken.armourersWorkshop.common.inventory.ModInventory)1