use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class TileEntitySkinnable method getRenderBoundingBox.
@SideOnly(Side.CLIENT)
@Override
public AxisAlignedBB getRenderBoundingBox() {
if (renderBounds == null) {
if (hasSkin()) {
Skin skin = getSkin(getSkinPointer());
if (skin != null) {
if (SkinProperties.PROP_BLOCK_MULTIBLOCK.getValue(skin.getProperties())) {
renderBounds = AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2);
ForgeDirection dir = getRotation().getOpposite();
renderBounds.offset(dir.offsetX, 0, dir.offsetZ);
} else {
renderBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
}
} else {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
}
} else {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
}
}
return renderBounds;
}
use of riskyken.armourersWorkshop.common.skin.data.Skin 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.skin.data.Skin 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.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class SkinIOUtils method updateSkins.
public static void updateSkins(EntityPlayer player) {
File updateDir = new File(System.getProperty("user.dir"), "skin-update");
if (!updateDir.exists() & updateDir.isDirectory()) {
player.addChatComponentMessage(new ChatComponentText("Directory skin-update not found."));
return;
}
File outputDir = new File(updateDir, "updated");
if (!outputDir.exists()) {
outputDir.mkdir();
}
File[] skinFiles = updateDir.listFiles();
player.addChatComponentMessage(new ChatComponentText(String.format("Found %d skins to be updated.", skinFiles.length)));
player.addChatComponentMessage(new ChatComponentText("Working..."));
int successCount = 0;
int failCount = 0;
for (int i = 0; i < skinFiles.length; i++) {
File skinFile = skinFiles[i];
if (skinFile.isFile()) {
Skin skin = loadSkinFromFile(skinFile);
if (skin != null) {
if (saveSkinToFile(new File(outputDir, skinFile.getName()), skin)) {
successCount++;
} else {
ModLogger.log(Level.ERROR, "Failed to update skin " + skinFile.getName());
failCount++;
}
} else {
ModLogger.log(Level.ERROR, "Failed to update skin " + skinFile.getName());
failCount++;
}
}
}
player.addChatComponentMessage(new ChatComponentText("Finished skin update."));
player.addChatComponentMessage(new ChatComponentText(String.format("%d skins were updated and %d failed.", successCount, failCount)));
}
use of riskyken.armourersWorkshop.common.skin.data.Skin in project Armourers-Workshop by RiskyKen.
the class SkinIOUtils method loadSkinFromStream.
public static Skin loadSkinFromStream(InputStream inputStream) {
DataInputStream stream = null;
Skin skin = null;
try {
stream = new DataInputStream(new BufferedInputStream(inputStream));
skin = SkinSerializer.readSkinFromStream(stream);
} catch (FileNotFoundException e) {
ModLogger.log(Level.WARN, "Skin file not found.");
e.printStackTrace();
} catch (IOException e) {
ModLogger.log(Level.ERROR, "Skin file load failed.");
e.printStackTrace();
} catch (NewerFileVersionException e) {
ModLogger.log(Level.ERROR, "Can not load skin file it was saved in newer version.");
e.printStackTrace();
} catch (InvalidCubeTypeException e) {
ModLogger.log(Level.ERROR, "Unable to load skin. Unknown cube types found.");
e.printStackTrace();
} finally {
IOUtils.closeQuietly(stream);
IOUtils.closeQuietly(inputStream);
}
return skin;
}
Aggregations