use of riskyken.armourersWorkshop.common.library.LibraryFile 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);
}
use of riskyken.armourersWorkshop.common.library.LibraryFile 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.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class ClientProxy method receivedSkinFromLibrary.
@Override
public void receivedSkinFromLibrary(String fileName, String filePath, Skin skin, SendType sendType) {
switch(sendType) {
case LIBRARY_SAVE:
SkinIOUtils.saveSkinFromFileName(filePath, fileName + SkinIOUtils.SKIN_FILE_EXTENSION, skin);
ArmourersWorkshop.proxy.libraryManager.addFileToListType(new LibraryFile(fileName, filePath, skin.getSkinType()), LibraryFileType.LOCAL, null);
break;
case GLOBAL_UPLOAD:
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if (screen instanceof GuiGlobalLibrary) {
((GuiGlobalLibrary) screen).gotSkinFromServer(skin);
}
break;
}
}
use of riskyken.armourersWorkshop.common.library.LibraryFile 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.library.LibraryFile in project Armourers-Workshop by RiskyKen.
the class GuiSkinLibrary method drawScreen.
@Override
public void drawScreen(int mouseX, int mouseY, float partialTickTime) {
int oldMouseX = mouseX;
int oldMouseY = mouseY;
if (isDialogOpen()) {
mouseX = mouseY = 0;
}
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
super.drawScreen(mouseX, mouseY, partialTickTime);
GL11.glPopAttrib();
ILibraryManager libraryManager = ArmourersWorkshop.proxy.libraryManager;
ArrayList<LibraryFile> files = libraryManager.getServerPublicFileList().getFileList();
loadSaveButton.enabled = true;
if (isLoading()) {
loadSaveButton.displayString = GuiHelper.getLocalizedControlName(armourLibrary.getInventoryName(), "load");
if (fileList.getSelectedListEntry() == null || ((GuiFileListItem) fileList.getSelectedListEntry()).getFile().directory) {
loadSaveButton.displayString = "";
loadSaveButton.enabled = false;
}
} else {
loadSaveButton.displayString = GuiHelper.getLocalizedControlName(armourLibrary.getInventoryName(), "save");
}
if (!((Slot) inventorySlots.inventorySlots.get(36)).getHasStack() & !armourLibrary.isCreativeLibrary()) {
loadSaveButton.displayString = "";
loadSaveButton.enabled = false;
}
if (fileSwitchType == LibraryFileType.LOCAL) {
files = libraryManager.getClientPublicFileList().getFileList();
if (!mc.isIntegratedServerRunning()) {
loadSaveButton.enabled = false;
if (isLoading()) {
loadSaveButton.enabled = ConfigHandler.allowClientsToUploadSkins;
} else {
loadSaveButton.enabled = ConfigHandler.allowClientsToDownloadSkins;
}
}
} else {
loadSaveButton.enabled = true;
}
if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
files = libraryManager.getServerPrivateFileList(mc.thePlayer).getFileList();
}
String typeFilter = dropDownList.getListSelectedItem().tag;
ISkinType skinTypeFilter = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(typeFilter);
lastSkinType = skinTypeFilter;
lastSearchText = searchTextbox.getText();
IGuiListItem selectedItem = fileList.getSelectedListEntry();
if (selectedItem != null) {
// deleteButton.enabled = !((GuiFileListItem)selectedItem).getFile().readOnly;
} else {
// deleteButton.enabled = false;
}
fileList.setSelectedIndex(-1);
fileList.clearList();
if (!(currentFolder.equals("/") | currentFolder.equals(getPrivateRoot(player)))) {
fileList.addListItem(new GuiFileListItem(new LibraryFile("../", "", null, true)));
if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile().fileName.equals("../")) {
fileList.setSelectedIndex(0);
}
}
if (files != null) {
for (int i = 0; i < files.size(); i++) {
LibraryFile file = files.get(i);
if (skinTypeFilter == null | skinTypeFilter == file.skinType) {
if (file.filePath.equals(currentFolder)) {
if (!searchTextbox.getText().equals("")) {
if (file.fileName.toLowerCase().contains(searchTextbox.getText().toLowerCase())) {
fileList.addListItem(new GuiFileListItem(file));
if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile() == file) {
fileList.setSelectedIndex(fileList.getSize() - 1);
}
}
} else {
fileList.addListItem(new GuiFileListItem(file));
if (selectedItem != null && ((GuiFileListItem) selectedItem).getFile() == file) {
fileList.setSelectedIndex(fileList.getSize() - 1);
}
}
}
}
}
}
scrollAmount = scrollbar.getValue();
fileList.setScrollPercentage(scrollbar.getPercentageValue());
for (int i = 0; i < buttonList.size(); i++) {
GuiButton button = (GuiButton) buttonList.get(i);
if (button instanceof GuiIconButton) {
((GuiIconButton) button).drawRollover(mc, mouseX, mouseY);
}
}
if (showModelPreviews()) {
GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
if (item != null && !item.getFile().isDirectory()) {
SkinIdentifier identifier = new SkinIdentifier(0, new LibraryFile(item.getFile().getFullName()), 0, null);
Skin skin = ClientSkinCache.INSTANCE.getSkin(identifier, true);
if (skin != null) {
SkinPointer skinPointer = new SkinPointer(identifier);
int listRight = this.width - INVENTORY_WIDTH - PADDING * 5;
listRight = MathHelper.clamp_int(listRight, 0, 200);
listRight += INVENTORY_WIDTH + PADDING * 2 + 10;
int listTop = TITLE_HEIGHT + 14 + PADDING * 2;
int xSize = (this.width - listRight - PADDING) / 2;
int ySize = (this.height - listTop - PADDING) / 2;
float x = listRight + xSize;
float y = listTop + ySize;
float scale = 1F;
scale = 1 * Math.min(xSize, ySize);
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int startX = listRight + PADDING;
int startY = listTop + PADDING;
int tarW = (int) (x + xSize);
int tarH = (int) (y + ySize);
drawRect(startX, startY, tarW, tarH, 0x77777777);
if (scale > 8) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, 500.0F);
GL11.glScalef(10, 10, -10);
GL11.glRotatef(30, 1, 0, 0);
GL11.glRotatef(45, 0, 1, 0);
float rotation = (float) ((double) System.currentTimeMillis() / 10 % 360);
GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_NORMALIZE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
ModRenderHelper.enableAlphaBlend();
SkinItemRenderHelper.renderSkinAsItem(skin, skinPointer, true, false, tarW - startX, tarH - startY);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
}
GL11.glColor4f(1, 1, 1, 1);
if (isDialogOpen()) {
this.dialog.draw(oldMouseX, oldMouseY, partialTickTime);
}
}
Aggregations