use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.
the class SkinNBTHelper method addSkinDataToStack.
public static void addSkinDataToStack(ItemStack stack, SkinIdentifier identifier, boolean lockSkin, ISkinDye skinDye) {
SkinPointer skinData;
if (skinDye != null) {
skinData = new SkinPointer(identifier, skinDye, lockSkin);
} else {
skinData = new SkinPointer(identifier, lockSkin);
}
addSkinDataToStack(stack, skinData);
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.
the class SkinNBTHelper method isSkinLockedOnStack.
public static boolean isSkinLockedOnStack(ItemStack stack) {
if (!stackHasSkinData(stack)) {
return false;
}
SkinPointer skinData = new SkinPointer();
skinData.readFromCompound(stack.getTagCompound());
return skinData.lockSkin;
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
boolean hasSkin = compound.getBoolean(TAG_HAS_SKIN);
nbtVersion = 0;
if (compound.hasKey(ModConstants.Tags.TAG_NBT_VERSION, Constants.NBT.TAG_INT)) {
nbtVersion = compound.getInteger(ModConstants.Tags.TAG_NBT_VERSION);
}
if (compound.hasKey(TAG_LINKED_BLOCK, Constants.NBT.TAG_INT_ARRAY)) {
int[] loc = compound.getIntArray(TAG_LINKED_BLOCK);
linkedBlock = new BlockLocation(loc[0], loc[1], loc[2]);
} else {
linkedBlock = null;
}
if (hasSkin) {
skinPointer = new SkinPointer();
skinPointer.readFromCompound(compound);
if (compound.hasKey(TAG_RELATED_BLOCKS, Constants.NBT.TAG_LIST)) {
NBTTagList list = compound.getTagList(TAG_RELATED_BLOCKS, Constants.NBT.TAG_COMPOUND);
relatedBlocks = new ArrayList<BlockLocation>();
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound blockCompound = (NBTTagCompound) list.getCompoundTagAt(i);
int x = blockCompound.getInteger(TAG_X);
int y = blockCompound.getInteger(TAG_Y);
int z = blockCompound.getInteger(TAG_Z);
BlockLocation blockLoc = new BlockLocation(x, y, z);
relatedBlocks.add(blockLoc);
}
} else {
relatedBlocks = null;
}
blockInventory = false;
inventory = null;
if (isParent()) {
if (compound.hasKey(TAG_BLOCK_INVENTORY, Constants.NBT.TAG_BYTE) && compound.getBoolean(TAG_BLOCK_INVENTORY)) {
int size = 36;
if (compound.hasKey(TAG_BLOCK_INVENTORY_SIZE, NBT.TAG_INT)) {
size = compound.getInteger(TAG_BLOCK_INVENTORY_SIZE);
}
blockInventory = true;
inventory = new ModInventory(LibBlockNames.SKINNABLE, size, this);
inventory.loadItemsFromNBT(compound);
}
}
} else {
skinPointer = null;
relatedBlocks = null;
ModLogger.log(Level.WARN, String.format("Skinnable tile at X:%d Y:%d Z:%d has no skin data.", xCoord, yCoord, zCoord));
}
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.
the class EntityEquipmentData method fromBytes.
private void fromBytes(ByteBuf buf) {
int itemCount = buf.readByte();
skinPointerMap.clear();
for (int i = 0; i < itemCount; i++) {
NBTTagCompound compound = ByteBufUtils.readTag(buf);
String skinKey = ByteBufUtils.readUTF8String(buf);
SkinPointer skinPointer = new SkinPointer();
skinPointer.readFromCompound(compound);
skinPointerMap.put(skinKey, skinPointer);
}
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPointer in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinLibrary method saveArmour.
/**
* Save armour data from an items NBT data into a file on the disk.
* @param filePath
* @param filename The name of the file to save to.
* @param player The player that pressed the save button.
* @param publicFiles If true save to the public file list or false for the players private files.
*/
public void saveArmour(String fileName, String filePath, EntityPlayerMP player, boolean publicFiles) {
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);
if (skinPointer == null) {
return;
}
if (!publicFiles) {
// filePath = "/private/" + player.getUniqueID().toString() + filePath;
}
ModLogger.log("save");
Skin skin = CommonSkinCache.INSTANCE.getSkin(skinPointer);
if (skin == null) {
ModLogger.log("no input");
return;
}
ModLogger.log("save");
filePath = SkinIOUtils.makeFilePathValid(filePath);
fileName = SkinIOUtils.makeFileNameValid(fileName);
LibraryFile file = new LibraryFile(fileName, filePath, skin.getSkinType());
// if the file was overwritten remove it's old id link
CommonSkinCache.INSTANCE.clearFileNameIdLink(file);
if (!SkinIOUtils.saveSkinFromFileName(filePath, fileName + SkinIOUtils.SKIN_FILE_EXTENSION, skin)) {
return;
}
if (ArmourersWorkshop.isDedicated()) {
if (publicFiles) {
ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.SERVER_PUBLIC, player);
} else {
ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.SERVER_PRIVATE, player);
}
} else {
ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.LOCAL, player);
}
this.decrStackSize(0, 1);
this.setInventorySlotContents(1, stackInput);
}
Aggregations