use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class LibraryFile method readFromByteBuf.
public static LibraryFile readFromByteBuf(ByteBuf buf) {
String fileName = ByteBufUtils.readUTF8String(buf);
String filePath = ByteBufUtils.readUTF8String(buf);
boolean directory = buf.readBoolean();
ISkinType skinType = null;
if (buf.readBoolean()) {
String regName = ByteBufUtils.readUTF8String(buf);
skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(regName);
}
return new LibraryFile(fileName, filePath, skinType, directory);
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class SkinIOUtils method getSkinTypeNameFromFile.
public static ISkinType getSkinTypeNameFromFile(File file) {
DataInputStream stream = null;
ISkinType skinType = null;
try {
stream = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
skinType = SkinSerializer.readSkinTypeNameFromStream(stream);
} catch (FileNotFoundException e) {
e.printStackTrace();
ModLogger.log(Level.ERROR, "File name: " + file.getName());
} catch (IOException e) {
e.printStackTrace();
ModLogger.log(Level.ERROR, "File name: " + file.getName());
} catch (NewerFileVersionException e) {
e.printStackTrace();
ModLogger.log(Level.ERROR, "File name: " + file.getName());
} catch (Exception e) {
ModLogger.log(Level.ERROR, "Unable to load skin name. Unknown error.");
e.printStackTrace();
} finally {
IOUtils.closeQuietly(stream);
}
return skinType;
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class EquipmentWardrobeData method saveNBTData.
public void saveNBTData(NBTTagCompound compound) {
compound.setInteger(TAG_SKIN_COLOUR, this.skinColour);
compound.setInteger(TAG_HAIR_COLOUR, this.hairColour);
for (int i = 0; i < 4; i++) {
compound.setBoolean(TAG_ARMOUR_OVERRIDE + i, this.armourOverride.get(i));
}
compound.setBoolean(TAG_HEAD_OVERLAY, this.headOverlay);
compound.setBoolean(TAG_LIMIT_LIMBS, this.limitLimbs);
NBTTagList slotsList = new NBTTagList();
ISkinType[] validSkins = ExPropsPlayerSkinData.validSkins;
for (int i = 0; i < validSkins.length; i++) {
ISkinType skinType = validSkins[i];
NBTTagCompound slotCount = new NBTTagCompound();
slotCount.setString(TAG_SLOT_KEY, skinType.getRegistryName());
slotCount.setInteger(TAG_SLOT_VALUE, getUnlockedSlotsForSkinType(skinType));
slotsList.appendTag(slotCount);
}
compound.setTag(TAG_SLOTS_UNLOCKED, slotsList);
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class EquipmentWardrobeData method toBytes.
public void toBytes(ByteBuf buf) {
buf.writeInt(this.skinColour);
buf.writeInt(this.hairColour);
for (int i = 0; i < 4; i++) {
buf.writeBoolean(this.armourOverride.get(i));
}
buf.writeBoolean(this.headOverlay);
buf.writeBoolean(this.limitLimbs);
ISkinType[] validSkins = ExPropsPlayerSkinData.validSkins;
for (int i = 0; i < validSkins.length; i++) {
ISkinType skinType = validSkins[i];
ByteBufUtils.writeUTF8String(buf, skinType.getRegistryName());
buf.writeInt(getUnlockedSlotsForSkinType(skinType));
}
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType 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