use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class EquipmentRenderHandler method renderSkin.
@Override
public boolean renderSkin(ISkinPointer skinPointer) {
ISkinType skinType = skinPointer.getIdentifier().getSkinType();
for (int i = 0; i < skinType.getSkinParts().size(); i++) {
// TODO Offset each part when rendering.
ISkinPartType skinPartType = skinType.getSkinParts().get(i);
renderSkinPart(skinPointer, skinPartType);
}
return false;
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class SkinIdentifierSerializer method readFromCompound.
public static SkinIdentifier readFromCompound(NBTTagCompound compound) {
int localId = 0;
ILibraryFile libraryFile = null;
int globalId = 0;
ISkinType skinType = null;
NBTTagCompound idDataCompound = compound.getCompoundTag(TAG_SKIN_ID_DATA);
localId = idDataCompound.getInteger(TAG_SKIN_LOCAL_ID);
if (idDataCompound.hasKey(TAG_SKIN_LIBRARY_FILE, NBT.TAG_STRING)) {
libraryFile = new LibraryFile(idDataCompound.getString(TAG_SKIN_LIBRARY_FILE));
}
globalId = idDataCompound.getInteger(TAG_SKIN_GLOBAL_ID);
skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(idDataCompound.getString(TAG_SKIN_TYPE));
if (compound.hasKey(TAG_SKIN_OLD_ID, NBT.TAG_INT)) {
localId = compound.getInteger(TAG_SKIN_OLD_ID);
}
if (compound.hasKey(TAG_SKIN_TYPE, NBT.TAG_STRING)) {
skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(compound.getString(TAG_SKIN_TYPE));
}
return new SkinIdentifier(localId, libraryFile, globalId, skinType);
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class SkinSerializer method readSkinTypeNameFromStream.
public static ISkinType readSkinTypeNameFromStream(DataInputStream stream) throws IOException, NewerFileVersionException {
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);
}
}
return equipmentSkinType;
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class EntitySkinHandler method dropEntitySkins.
private void dropEntitySkins(Entity entity) {
if (ConfigHandler.entityDropSkinChance <= 0) {
return;
}
int rnd = entity.worldObj.rand.nextInt(99) + 1;
if (rnd <= ConfigHandler.entityDropSkinChance) {
ExPropsEntityEquipmentData entityEquipmentData = ExPropsEntityEquipmentData.getExtendedPropsForEntity(entity);
if (entityEquipmentData != null) {
ArrayList<ISkinType> skinTypes = entityEquipmentData.getSkinInventory().getSkinTypes();
for (int i = 0; i < skinTypes.size(); i++) {
ISkinPointer skinPointer = entityEquipmentData.getEquipmentData().getSkinPointer(skinTypes.get(i), 0);
if (skinPointer != null) {
ItemStack stack = SkinNBTHelper.makeEquipmentSkinStack((SkinPointer) skinPointer);
UtilItems.spawnItemAtEntity(entity, stack);
}
}
}
}
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinType in project Armourers-Workshop by RiskyKen.
the class EntitySkinHandler method giveRandomSkin.
public void giveRandomSkin(ExPropsEntityEquipmentData entityEquipmentData) {
if (entityEquipmentData == null) {
return;
}
if (ConfigHandler.enitiySpawnWithSkinsChance <= 0) {
return;
}
ArrayList<ISkinType> skinTypes = entityEquipmentData.getSkinInventory().getSkinTypes();
for (int i = 0; i < skinTypes.size(); i++) {
int rnd = entityEquipmentData.getEntity().worldObj.rand.nextInt(99) + 1;
if (rnd >= ConfigHandler.enitiySpawnWithSkinsChance) {
continue;
}
ISkinType skinType = skinTypes.get(i);
LibraryFile libraryFile = getRandomSkinOfType(skinType);
if (libraryFile == null) {
continue;
}
SkinIdentifier identifier = new SkinIdentifier(0, libraryFile, 0, skinType);
ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(identifier));
if (skinStack == null) {
continue;
}
entityEquipmentData.getSkinInventory().setInventorySlotContents(i, skinStack);
}
}
Aggregations