Search in sources :

Example 1 with SkinIdentifier

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

the class GuiGlobalLibraryPanelSkinInfo method draw.

@Override
public void draw(int mouseX, int mouseY, float partialTickTime) {
    if (!visible) {
        return;
    }
    PlushieUser user = null;
    if (skinJson != null && skinJson.has("user_id")) {
        int userId = skinJson.get("user_id").getAsInt();
        user = GlobalSkinLibraryUtils.getUserInfo(userId);
    }
    drawGradientRect(this.x, this.y, this.x + this.width, this.y + height, 0xC0101010, 0xD0101010);
    Skin skin = null;
    if (skinJson != null && skinJson.has("id")) {
        SkinIdentifier identifier = new SkinIdentifier(0, null, skinJson.get("id").getAsInt(), null);
        skin = ClientSkinCache.INSTANCE.getSkin(identifier);
    }
    super.draw(mouseX, mouseY, partialTickTime);
    drawUserbox(x + 5, y + 5, 185, 30, mouseX, mouseY, partialTickTime);
    drawSkinInfo(skin, x + 5, y + 20 + 20, 185, height - 70, mouseX, mouseY, partialTickTime);
    drawPreviewBox(skin, x + 195, y + 5, width - 200, height - 35, mouseX, mouseY, partialTickTime);
}
Also used : Skin(riskyken.armourersWorkshop.common.skin.data.Skin) PlushieUser(riskyken.armourersWorkshop.common.library.global.PlushieUser) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 2 with SkinIdentifier

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

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

Example 4 with SkinIdentifier

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

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

the class ClientSkinCache method receivedModelFromBakery.

public void receivedModelFromBakery(BakedSkin bakedSkin) {
    SkinIdentifier identifierRequested = bakedSkin.getSkinIdentifierRequested();
    synchronized (requestedSkinIDs) {
        synchronized (skinIDMap) {
            if (skinIDMap.containsKey(identifierRequested)) {
                // We already have this skin, remove the old one before adding the new one.
                Skin oldSkin = skinIDMap.get(identifierRequested);
                skinIDMap.remove(identifierRequested);
                oldSkin.cleanUpDisplayLists();
                ModLogger.log("removing skin");
            }
            if (requestedSkinIDs.contains(identifierRequested)) {
                skinIDMap.put(identifierRequested, bakedSkin.getSkin());
                requestedSkinIDs.remove(identifierRequested);
            } else {
                // We did not request this skin.
                skinIDMap.put(bakedSkin.getSkinIdentifierUpdated(), bakedSkin.getSkin());
                ModLogger.log(Level.WARN, "Got an unknown skin - Identifier: " + bakedSkin.getSkinIdentifierUpdated().toString());
            }
        }
    }
}
Also used : Skin(riskyken.armourersWorkshop.common.skin.data.Skin) BakedSkin(riskyken.armourersWorkshop.client.model.bake.ModelBakery.BakedSkin) ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Aggregations

SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)21 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)10 ItemStack (net.minecraft.item.ItemStack)8 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)8 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)7 ISkinIdentifier (riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier)6 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ILibraryFile (riskyken.armourersWorkshop.api.common.library.ILibraryFile)3 Color (java.awt.Color)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 SkinDye (riskyken.armourersWorkshop.common.skin.data.SkinDye)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GuiButton (net.minecraft.client.gui.GuiButton)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Slot (net.minecraft.inventory.Slot)1