Search in sources :

Example 21 with Skin

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

the class TileEntitySkinnable method getRenderBoundingBox.

@SideOnly(Side.CLIENT)
@Override
public AxisAlignedBB getRenderBoundingBox() {
    if (renderBounds == null) {
        if (hasSkin()) {
            Skin skin = getSkin(getSkinPointer());
            if (skin != null) {
                if (SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skin.getProperties())) {
                    renderBounds = AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2);
                    ForgeDirection dir = getRotation().getOpposite();
                    renderBounds.offset(dir.offsetX, 0, dir.offsetZ);
                } else {
                    renderBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
                }
            } else {
                return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
            }
        } else {
            return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
        }
    }
    return renderBounds;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 22 with Skin

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

the class TileEntitySkinLibrary method loadArmour.

/**
 * Loads an armour file from the disk and adds it to an items NBT data.
 * @param filePath
 * @param filename The name of the file to load.
 * @param player The player that pressed the load button.
 */
public void loadArmour(String fileName, String filePath, EntityPlayerMP player, boolean trackFile) {
    ItemStack stackInput = getStackInSlot(0);
    ItemStack stackOutput = getStackInSlot(1);
    if (!isCreativeLibrary()) {
        if (stackInput == null) {
            return;
        }
    }
    if (stackOutput != null) {
        return;
    }
    if (!isCreativeLibrary()) {
        if (!(stackInput.getItem() instanceof ISkinHolder)) {
            return;
        }
    }
    Skin skin = null;
    String fullFileName = fileName;
    skin = SkinIOUtils.loadSkinFromFileName(filePath + fileName + SkinIOUtils.SKIN_FILE_EXTENSION);
    if (skin == null) {
        return;
    }
    LibraryFile libraryFile = new LibraryFile(fileName, filePath, skin.getSkinType());
    SkinIdentifier identifier = null;
    if (trackFile) {
        identifier = new SkinIdentifier(0, libraryFile, 0, skin.getSkinType());
    } else {
        identifier = new SkinIdentifier(skin.lightHash(), null, 0, skin.getSkinType());
    }
    // TODO Set master using trackFile
    CommonSkinCache.INSTANCE.addEquipmentDataToCache(skin, libraryFile);
    ModLogger.log("Loaded file form lib: " + libraryFile.toString());
    ItemStack stackArmour = SkinNBTHelper.makeEquipmentSkinStack(skin, identifier);
    if (stackArmour == null) {
        return;
    }
    if (!isCreativeLibrary()) {
        this.decrStackSize(0, 1);
    }
    this.setInventorySlotContents(1, stackArmour);
}
Also used : ISkinHolder(riskyken.armourersWorkshop.common.skin.ISkinHolder) 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) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 23 with Skin

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

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

the class SkinIOUtils method updateSkins.

public static void updateSkins(EntityPlayer player) {
    File updateDir = new File(System.getProperty("user.dir"), "skin-update");
    if (!updateDir.exists() & updateDir.isDirectory()) {
        player.addChatComponentMessage(new ChatComponentText("Directory skin-update not found."));
        return;
    }
    File outputDir = new File(updateDir, "updated");
    if (!outputDir.exists()) {
        outputDir.mkdir();
    }
    File[] skinFiles = updateDir.listFiles();
    player.addChatComponentMessage(new ChatComponentText(String.format("Found %d skins to be updated.", skinFiles.length)));
    player.addChatComponentMessage(new ChatComponentText("Working..."));
    int successCount = 0;
    int failCount = 0;
    for (int i = 0; i < skinFiles.length; i++) {
        File skinFile = skinFiles[i];
        if (skinFile.isFile()) {
            Skin skin = loadSkinFromFile(skinFile);
            if (skin != null) {
                if (saveSkinToFile(new File(outputDir, skinFile.getName()), skin)) {
                    successCount++;
                } else {
                    ModLogger.log(Level.ERROR, "Failed to update skin " + skinFile.getName());
                    failCount++;
                }
            } else {
                ModLogger.log(Level.ERROR, "Failed to update skin " + skinFile.getName());
                failCount++;
            }
        }
    }
    player.addChatComponentMessage(new ChatComponentText("Finished skin update."));
    player.addChatComponentMessage(new ChatComponentText(String.format("%d skins were updated and %d failed.", successCount, failCount)));
}
Also used : Skin(riskyken.armourersWorkshop.common.skin.data.Skin) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) File(java.io.File) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 25 with Skin

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

the class SkinIOUtils method loadSkinFromStream.

public static Skin loadSkinFromStream(InputStream inputStream) {
    DataInputStream stream = null;
    Skin skin = null;
    try {
        stream = new DataInputStream(new BufferedInputStream(inputStream));
        skin = SkinSerializer.readSkinFromStream(stream);
    } catch (FileNotFoundException e) {
        ModLogger.log(Level.WARN, "Skin file not found.");
        e.printStackTrace();
    } catch (IOException e) {
        ModLogger.log(Level.ERROR, "Skin file load failed.");
        e.printStackTrace();
    } catch (NewerFileVersionException e) {
        ModLogger.log(Level.ERROR, "Can not load skin file it was saved in newer version.");
        e.printStackTrace();
    } catch (InvalidCubeTypeException e) {
        ModLogger.log(Level.ERROR, "Unable to load skin. Unknown cube types found.");
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(stream);
        IOUtils.closeQuietly(inputStream);
    }
    return skin;
}
Also used : InvalidCubeTypeException(riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) NewerFileVersionException(riskyken.armourersWorkshop.common.exception.NewerFileVersionException)

Aggregations

Skin (riskyken.armourersWorkshop.common.skin.data.Skin)69 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)19 ItemStack (net.minecraft.item.ItemStack)11 ISkinPointer (riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer)11 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)10 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)10 SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)10 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)9 IOException (java.io.IOException)6 ISkinIdentifier (riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier)6 AbstractModelSkin (riskyken.armourersWorkshop.client.model.skin.AbstractModelSkin)6 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)6 Color (java.awt.Color)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)4 BakedSkin (riskyken.armourersWorkshop.client.model.bake.ModelBakery.BakedSkin)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)3 BufferedInputStream (java.io.BufferedInputStream)3 ArrayList (java.util.ArrayList)3