use of riskyken.armourersWorkshop.common.skin.data.SkinPart 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);
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.
the class RenderBlockSkinnable method renderSkin.
private void renderSkin(TileEntitySkinnable tileEntity, double x, double y, double z, Skin skin) {
int rotation = tileEntity.getBlockMetadata();
double distance = Minecraft.getMinecraft().thePlayer.getDistance(tileEntity.xCoord + 0.5F, tileEntity.yCoord + 0.5F, tileEntity.zCoord + 0.5F);
if (ConfigHandlerClient.showLodLevels) {
int colour = 0x00FF00;
int lod = MathHelper.floor_double(distance / ConfigHandlerClient.lodDistance);
lod = MathHelper.clamp_int(lod, 0, ConfigHandlerClient.maxLodLevels);
if (lod == 1) {
colour = 0xFFFF00;
} else if (lod == 2) {
colour = 0xFF0000;
} else if (lod == 3) {
colour = 0xFF00FF;
}
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glLineWidth(1.0F);
GL11.glDisable(GL11.GL_TEXTURE_2D);
RenderGlobal.drawOutlinedBoundingBox(aabb, colour);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glColor4f(1F, 1F, 1F, 1F);
}
GL11.glTranslated(x + 0.5F, y + 0.5F, z + 0.5F);
GL11.glScalef(-1, -1, 1);
if (rotation != 0) {
GL11.glRotatef((90F * rotation), 0, 1, 0);
}
for (int i = 0; i < skin.getParts().size(); i++) {
SkinPart skinPart = skin.getParts().get(i);
SkinPartRenderer.INSTANCE.renderPart(skinPart, 0.0625F, tileEntity.getSkinPointer().getSkinDye(), null, distance, true);
}
if (rotation != 0) {
GL11.glRotatef((90F * -rotation), 0, 1, 0);
}
GL11.glScalef(-1, -1, 1);
GL11.glTranslated(-x - 0.5F, -y - 0.5F, -z - 0.5F);
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.
the class SkinItemRenderHelper method renderSkinWithoutHelper.
public static void renderSkinWithoutHelper(ISkinPointer skinPointer, boolean doLodLoading) {
Skin skin = ClientSkinCache.INSTANCE.getSkin(skinPointer);
if (skin == null) {
return;
}
float scale = 1F / 16F;
for (int i = 0; i < skin.getParts().size(); i++) {
GL11.glPushMatrix();
SkinPart skinPart = skin.getParts().get(i);
IPoint3D offset = skinPart.getPartType().getOffset();
GL11.glTranslated(offset.getX() * scale, (offset.getY() + 1) * scale, offset.getZ() * scale);
SkinPartRenderer.INSTANCE.renderPart(skinPart, 0.0625F, skinPointer.getSkinDye(), null, doLodLoading);
GL11.glPopMatrix();
}
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.
the class ModelSkinSword method render.
@Override
public void render(Entity entity, Skin armourData, boolean showSkinPaint, ISkinDye skinDye, byte[] extraColour, boolean itemRender, double distance, boolean doLodLoading) {
if (armourData == null) {
return;
}
ArrayList<SkinPart> parts = armourData.getParts();
if (entity != null && entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
this.isSneak = player.isSneaking();
this.isRiding = player.isRiding();
this.heldItemRight = 0;
if (player.getHeldItem() != null) {
this.heldItemRight = 1;
}
}
if (ClientProxy.isJrbaClientLoaded()) {
this.isChild = false;
}
ApiRegistrar.INSTANCE.onRenderEquipment(entity, SkinTypeRegistry.skinSword);
for (int i = 0; i < parts.size(); i++) {
SkinPart part = parts.get(i);
GL11.glPushMatrix();
if (isChild) {
float f6 = 2.0F;
GL11.glScalef(1.0F / f6, 1.0F / f6, 1.0F / f6);
GL11.glTranslatef(0.0F, 24.0F * SCALE, 0.0F);
}
ApiRegistrar.INSTANCE.onRenderEquipmentPart(entity, part.getPartType());
if (part.getPartType().getPartName().equals("base")) {
renderRightArm(part, SCALE, skinDye, extraColour, distance, doLodLoading);
}
GL11.glPopMatrix();
}
GL11.glColor3f(1F, 1F, 1F);
}
use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.
the class ModelSkinWings method render.
@Override
public void render(Entity entity, Skin skin, boolean showSkinPaint, ISkinDye skinDye, byte[] extraColour, boolean itemRender, double distance, boolean doLodLoading) {
if (skin == null) {
return;
}
ArrayList<SkinPart> parts = skin.getParts();
if (entity != null && entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
this.isSneak = player.isSneaking();
this.isRiding = player.isRiding();
this.heldItemRight = 0;
if (player.getHeldItem() != null) {
this.heldItemRight = 1;
}
}
if (ClientProxy.isJrbaClientLoaded()) {
this.isChild = false;
}
ApiRegistrar.INSTANCE.onRenderEquipment(entity, SkinTypeRegistry.skinSword);
for (int i = 0; i < parts.size(); i++) {
SkinPart part = parts.get(i);
GL11.glPushMatrix();
GL11.glTranslated(0, 0, SCALE * 2);
if (isChild) {
float f6 = 2.0F;
GL11.glScalef(1.0F / f6, 1.0F / f6, 1.0F / f6);
GL11.glTranslatef(0.0F, 24.0F * SCALE, 0.0F);
}
ApiRegistrar.INSTANCE.onRenderEquipmentPart(entity, part.getPartType());
double angle = 45D;
MovementType movmentType = MovementType.valueOf(SkinProperties.PROP_WINGS_MOVMENT_TYPE.getValue(skin.getProperties()));
angle = SkinUtils.getFlapAngleForWings(entity, skin);
if (isSneak) {
GL11.glRotated(28F, 1F, 0, 0);
}
if (part.getPartType().getPartName().equals("leftWing")) {
renderLeftWing(part, SCALE, skinDye, extraColour, distance, angle, doLodLoading, movmentType);
}
if (part.getPartType().getPartName().equals("rightWing")) {
renderRightWing(part, SCALE, skinDye, extraColour, distance, -angle, doLodLoading, movmentType);
}
GL11.glPopMatrix();
}
GL11.glColor3f(1F, 1F, 1F);
}
Aggregations