use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class GuiSkinLibrary method actionPerformed.
@Override
protected void actionPerformed(GuiButton button) {
String filename = filenameTextbox.getText().trim();
if (button == fileSwitchlocal | button == fileSwitchRemotePublic | button == fileSwitchRemotePrivate) {
if (button == fileSwitchlocal) {
setFileSwitchType(LibraryFileType.LOCAL);
}
if (button == fileSwitchRemotePublic) {
setFileSwitchType(LibraryFileType.SERVER_PUBLIC);
}
if (button == fileSwitchRemotePrivate) {
setFileSwitchType(LibraryFileType.SERVER_PRIVATE);
}
}
if (button == reloadButton) {
if (fileSwitchType == LibraryFileType.LOCAL) {
ILibraryManager libraryManager = ArmourersWorkshop.proxy.libraryManager;
libraryManager.reloadLibrary();
} else {
// TODO reload server library
}
}
if (button == openFolderButton) {
openEquipmentFolder();
}
if (button == deleteButton) {
if (fileList.getSelectedListEntry() != null) {
GuiFileListItem item = (GuiFileListItem) fileList.getSelectedListEntry();
openDialog(new GuiDialogDelete(this, armourLibrary.getInventoryName() + ".dialog.delete", this, 190, 100, item.getFile().isDirectory(), item.getDisplayName()));
}
}
if (button == newFolderButton) {
openDialog(new GuiDialogNewFolder(this, armourLibrary.getInventoryName() + ".dialog.newFolder", this, 190, 120));
}
if (button == checkBoxTrack) {
trackFile = checkBoxTrack.isChecked();
}
GuiFileListItem fileItem = (GuiFileListItem) fileList.getSelectedListEntry();
boolean clientLoad = false;
boolean publicList = true;
MessageClientGuiLoadSaveArmour message;
if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
// Is playing on a server.
clientLoad = true;
}
if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
publicList = false;
}
if (button == loadSaveButton) {
if (fileItem != null && !fileItem.getFile().isDirectory()) {
LibraryFile file = fileItem.getFile();
if (isLoading()) {
if (clientLoad) {
Skin itemData = SkinIOUtils.loadSkinFromFileName(file.filePath + filename + SkinIOUtils.SKIN_FILE_EXTENSION);
if (itemData != null) {
SkinUploadHelper.uploadSkinToServer(itemData);
}
} else {
message = new MessageClientGuiLoadSaveArmour(file.fileName, file.filePath, LibraryPacketType.SERVER_LOAD, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
filenameTextbox.setText("");
}
}
if (!filename.isEmpty()) {
if (!isLoading()) {
if (fileExists(currentFolder, filename)) {
openDialog(new GuiDialogOverwrite(this, armourLibrary.getInventoryName() + ".dialog.overwrite", this, 190, 100, filename));
return;
}
if (clientLoad) {
message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
} else {
message = new MessageClientGuiLoadSaveArmour(filename, currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
// filenameTextbox.setText("");
}
}
}
setupLibraryEditButtons();
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class GuiFileListItem method drawListItem.
@Override
public void drawListItem(FontRenderer fontRenderer, int x, int y, int mouseX, int mouseY, boolean selected, int width) {
int iconOffset = 0;
if (GuiSkinLibrary.showModelPreviews() | file.isDirectory()) {
iconOffset = 10;
}
int fontColour = UtilColour.getMinecraftColor(8, ColourFamily.MINECRAFT);
if (isHovering(fontRenderer, x, y, mouseX, mouseY, width)) {
Gui.drawRect(x, y, x + width - 3, y + 12, 0xFFCCCCCC);
fontColour = UtilColour.getMinecraftColor(15, ColourFamily.MINECRAFT);
}
if (selected) {
Gui.drawRect(x, y, x + width - 3, y + 12, 0xFFFFFF88);
fontColour = UtilColour.getMinecraftColor(15, ColourFamily.MINECRAFT);
}
if (!file.isDirectory()) {
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, fontColour);
if (GuiSkinLibrary.showModelPreviews() | file.isDirectory()) {
IGuiListItem item = this;
if (item != null) {
SkinIdentifier identifier = new SkinIdentifier(0, new LibraryFile(file.getFullName()), 0, null);
Skin skin = ClientSkinCache.INSTANCE.getSkin(identifier, true);
if (skin != null) {
SkinPointer skinPointer = new SkinPointer(identifier);
float scale = 10F;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glTranslatef((float) x + 5, (float) y + 6, 50.0F);
GL11.glScalef((float) (-scale), (float) scale, (float) scale);
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
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.glEnable(GL11.GL_NORMALIZE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
ModRenderHelper.enableAlphaBlend();
// ItemStackRenderHelper.renderItemModelFromSkinPointer(skinPointer, true, false);
SkinItemRenderHelper.renderSkinAsItem(skin, skinPointer, true, false, 16, 16);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
} else {
GL11.glColor4f(1, 1, 1, 1);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
if (file.fileName.equals("private")) {
drawTexturedModalRect(x, y, 32, 0, 12, 12);
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, 0xFF8888FF);
} else {
drawTexturedModalRect(x, y, 16, 0, 10, 10);
fontRenderer.drawString(file.fileName, x + 2 + iconOffset, y + 2, 0xFF88FF88);
}
GL11.glColor4f(1, 1, 1, 1);
}
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method setBoundsOnBlock.
public void setBoundsOnBlock(Block block, int xOffset, int yOffset, int zOffset) {
if (haveBlockBounds) {
// TODO change before release!!!
// block.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
// return;
}
if (block != null && !(block instanceof BlockSkinnable)) {
ModLogger.log(Level.ERROR, String.format("Tile entity at X:%d Y:%d Z:%d has an invalid block.", xOffset, yOffset, zOffset));
if (worldObj != null) {
worldObj.removeTileEntity(xOffset, yOffset, zOffset);
}
return;
}
if (hasSkin()) {
BlockSkinnable blockSkinnable = (BlockSkinnable) block;
Skin skin = null;
skin = getSkin(skinPointer);
if (skin != null) {
ForgeDirection dir = blockSkinnable.getFacingDirection(getBlockMetadata());
float[] bounds = getBlockBounds(skin, xOffset, yOffset, zOffset, dir);
if (bounds != null) {
minX = bounds[0];
minY = bounds[1];
minZ = bounds[2];
maxX = bounds[3];
maxY = bounds[4];
maxZ = bounds[5];
haveBlockBounds = true;
block.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
}
return;
}
}
if (haveBlockBounds) {
block.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
} else {
block.setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);
}
}
use of riskyken.armourersWorkshop.common.skin.data.Skin 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.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class SkinSerializer method readSkinFromStream.
public static Skin readSkinFromStream(DataInputStream stream) throws IOException, NewerFileVersionException, InvalidCubeTypeException {
int fileVersion = stream.readInt();
if (fileVersion > Skin.FILE_VERSION) {
throw new NewerFileVersionException();
}
if (fileVersion > 12) {
String header = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!header.equals(TAG_SKIN_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin header.");
}
String propsHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!propsHeader.equals(TAG_SKIN_PROPS_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin props header.");
}
}
SkinProperties properties = new SkinProperties();
boolean loadedProps = true;
IOException e = null;
if (fileVersion < 12) {
String authorName = stream.readUTF();
String customName = stream.readUTF();
String tags = "";
if (!(fileVersion < 4)) {
tags = stream.readUTF();
} else {
tags = "";
}
properties.setProperty(Skin.KEY_AUTHOR_NAME, authorName);
properties.setProperty(Skin.KEY_CUSTOM_NAME, customName);
if (tags != null && !tags.equalsIgnoreCase("")) {
properties.setProperty(KEY_TAGS, tags);
}
} else {
try {
properties.readFromStream(stream, fileVersion);
} catch (IOException propE) {
ModLogger.log(Level.ERROR, "prop load failed");
e = propE;
loadedProps = false;
}
}
if (fileVersion > 12) {
String propsFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!propsFooter.equals(TAG_SKIN_PROPS_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin props footer.");
}
String typeHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeHeader.equals(TAG_SKIN_TYPE_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin type header.");
}
}
ISkinType equipmentSkinType = null;
if (fileVersion < 5) {
if (loadedProps) {
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromLegacyId(stream.readByte() - 1);
} else {
throw e;
}
} else {
if (loadedProps) {
String regName = stream.readUTF();
if (regName.equals(SkinTypeRegistry.skinSkirt.getRegistryName())) {
regName = SkinTypeRegistry.skinLegs.getRegistryName();
}
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(regName);
} else {
StringBuilder sb = new StringBuilder();
while (true) {
sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
if (sb.toString().endsWith("armourers:")) {
break;
}
}
ModLogger.log("Got armourers");
sb = new StringBuilder();
sb.append("armourers:");
while (SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString()) == null) {
sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
}
ModLogger.log(sb.toString());
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString());
ModLogger.log("got failed type " + equipmentSkinType);
}
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_TYPE_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin type footer.");
}
}
if (equipmentSkinType == null) {
throw new InvalidCubeTypeException();
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_PAINT_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin paint header.");
}
}
int[] paintData = null;
if (fileVersion > 7) {
boolean hasPaintData = stream.readBoolean();
if (hasPaintData) {
paintData = new int[SkinTexture.TEXTURE_SIZE];
for (int i = 0; i < SkinTexture.TEXTURE_SIZE; i++) {
paintData[i] = stream.readInt();
}
}
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_PAINT_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin paint footer.");
}
}
int size = stream.readByte();
ArrayList<SkinPart> parts = new ArrayList<SkinPart>();
for (int i = 0; i < size; i++) {
if (fileVersion > 12) {
String partHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!partHeader.equals(TAG_SKIN_PART_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin part header.");
}
}
SkinPart part = SkinPartSerializer.loadSkinPart(stream, fileVersion);
if (fileVersion > 12) {
String partFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!partFooter.equals(TAG_SKIN_PART_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin part footer.");
}
}
parts.add(part);
}
if (fileVersion > 12) {
String footer = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!footer.equals(TAG_SKIN_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin footer.");
}
}
return new Skin(properties, equipmentSkinType, paintData, parts);
}
Aggregations