use of riskyken.armourersWorkshop.common.items.ItemSkin 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);
}
use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.
the class ContainerEntityEquipment method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotId) {
Slot slot = getSlot(slotId);
if (slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
ItemStack result = stack.copy();
if (slotId < skinSlots) {
// Moving item to main inv
if (!this.mergeItemStack(stack, skinSlots + 9, skinSlots + 36, false)) {
// Moving item to hotbar
if (!this.mergeItemStack(stack, skinSlots, skinSlots + 9, false)) {
return null;
}
}
} else {
if (stack.getItem() instanceof ItemSkin & SkinNBTHelper.stackHasSkinData(stack)) {
boolean slotted = false;
for (int i = 0; i < skinSlots; i++) {
Slot targetSlot = getSlot(i);
if (targetSlot.isItemValid(stack)) {
if (this.mergeItemStack(stack, i, i + 1, false)) {
slotted = true;
break;
}
}
}
if (!slotted) {
return null;
}
} else {
return null;
}
}
if (stack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
slot.onPickupFromSlot(entityPlayer, stack);
return result;
}
return null;
}
use of riskyken.armourersWorkshop.common.items.ItemSkin 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);
}
use of riskyken.armourersWorkshop.common.items.ItemSkin 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);
}
use of riskyken.armourersWorkshop.common.items.ItemSkin in project Armourers-Workshop by RiskyKen.
the class ContainerArmourLibrary method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
Slot slot = getSlot(slotID);
if (slot != null && slot.getHasStack()) {
ItemStack stack = slot.getStack();
ItemStack result = stack.copy();
if (slotID < 36) {
if ((stack.getItem() instanceof ItemSkinTemplate & stack.getItemDamage() == 0) | stack.getItem() instanceof ItemSkin) {
if (!this.mergeItemStack(stack, 36, 37, false)) {
return null;
}
} else {
return null;
}
} else {
if (!this.mergeItemStack(stack, 9, 36, false)) {
if (!this.mergeItemStack(stack, 0, 9, false)) {
return null;
}
}
}
if (stack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
slot.onPickupFromSlot(player, stack);
return result;
}
return null;
}
Aggregations