use of riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured in project Armourers-Workshop by RiskyKen.
the class SkinTextureHelper method getTextureLocationFromWorldBlock.
public static Point getTextureLocationFromWorldBlock(TileEntityBoundingBox te, int side) {
ISkinPartTypeTextured skinPart = (ISkinPartTypeTextured) te.getSkinPart();
Point textureLocation = skinPart.getTextureLocation();
IPoint3D textureModelSize = skinPart.getTextureModelSize();
ForgeDirection blockFace = ForgeDirection.getOrientation(side);
byte blockX = te.getGuideX();
byte blockY = te.getGuideY();
byte blockZ = te.getGuideZ();
int textureX = textureLocation.x;
int textureY = textureLocation.y;
int shiftX = 0;
int shiftY = 0;
if (skinPart.isTextureMirrored()) {
if (blockFace == ForgeDirection.EAST | blockFace == ForgeDirection.WEST) {
blockFace = blockFace.getOpposite();
}
}
switch(blockFace) {
case EAST:
textureY += textureModelSize.getZ();
shiftX = (byte) (-blockZ + textureModelSize.getZ() - 1);
shiftY = (byte) (-blockY + textureModelSize.getY() - 1);
break;
case NORTH:
textureX += textureModelSize.getZ();
textureY += textureModelSize.getZ();
shiftX = (byte) (-blockX + textureModelSize.getX() - 1);
if (skinPart.isTextureMirrored()) {
shiftX = (byte) (blockX);
}
shiftY = (byte) (-blockY + textureModelSize.getY() - 1);
break;
case WEST:
textureX += textureModelSize.getZ() + textureModelSize.getX();
textureY += textureModelSize.getZ();
shiftX = blockZ;
shiftY = (byte) (-blockY + textureModelSize.getY() - 1);
break;
case SOUTH:
textureX += textureModelSize.getZ() + textureModelSize.getX() + textureModelSize.getZ();
textureY += textureModelSize.getZ();
shiftX = blockX;
if (skinPart.isTextureMirrored()) {
shiftX = (byte) (-blockX + textureModelSize.getX() - 1);
}
shiftY = (byte) (-blockY + textureModelSize.getY() - 1);
break;
case DOWN:
textureX += textureModelSize.getZ() + textureModelSize.getX();
shiftX = (byte) (-blockX + textureModelSize.getX() - 1);
if (skinPart.isTextureMirrored()) {
shiftX = blockX;
}
shiftY = (byte) (-blockZ + textureModelSize.getZ() - 1);
break;
case UP:
textureX += textureModelSize.getZ();
shiftX = (byte) (-blockX + textureModelSize.getX() - 1);
if (skinPart.isTextureMirrored()) {
shiftX = blockX;
}
shiftY = (byte) (-blockZ + textureModelSize.getZ() - 1);
break;
default:
break;
}
textureX += shiftX;
textureY += shiftY;
return new Point(textureX, textureY);
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured in project Armourers-Workshop by RiskyKen.
the class SkinItemRenderHelper method renderSkinAsItem.
public static void renderSkinAsItem(Skin skin, ISkinPointer skinPointer, boolean showSkinPaint, boolean doLodLoading, int targetWidth, int targetHeight) {
if (skin == null) {
return;
}
float blockScale = 16F;
float mcScale = 1F / blockScale;
ArrayList<IRectangle3D> boundsParts = new ArrayList<IRectangle3D>();
ArrayList<IRectangle3D> boundsTextures = new ArrayList<IRectangle3D>();
IRectangle3D boundsTexture = null;
for (int i = 0; i < skin.getPartCount(); i++) {
SkinPart skinPart = skin.getParts().get(i);
if (!(skin.getSkinType() == SkinTypeRegistry.skinBow && i > 0)) {
Rectangle3D bounds = skinPart.getPartBounds();
IPoint3D offset = skinPart.getPartType().getItemRenderOffset();
Rectangle3D rec = new Rectangle3D(bounds.getX() + offset.getX(), bounds.getY() + offset.getY(), bounds.getZ() + offset.getZ(), bounds.getWidth(), bounds.getHeight(), bounds.getDepth());
boundsParts.add(rec);
}
}
if (skin.hasPaintData()) {
ArrayList<ISkinPartType> parts = skin.getSkinType().getSkinParts();
for (int i = 0; i < parts.size(); i++) {
ISkinPartType part = parts.get(i);
if (part instanceof ISkinPartTypeTextured) {
if (part.getItemRenderTextureBounds() != null) {
boundsTextures.add(part.getItemRenderTextureBounds());
}
}
}
}
int minX = 256;
int minY = 256;
int minZ = 256;
int maxX = -256;
int maxY = -256;
int maxZ = -256;
for (int i = 0; i < boundsParts.size(); i++) {
IRectangle3D rec = boundsParts.get(i);
minX = Math.min(minX, rec.getX());
minY = Math.min(minY, rec.getY());
minZ = Math.min(minZ, rec.getZ());
maxX = Math.max(maxX, rec.getWidth() + rec.getX());
maxY = Math.max(maxY, rec.getHeight() + rec.getY());
maxZ = Math.max(maxZ, rec.getDepth() + rec.getZ());
}
for (int i = 0; i < boundsTextures.size(); i++) {
IRectangle3D rec = boundsTextures.get(i);
minX = Math.min(minX, rec.getX());
minY = Math.min(minY, rec.getY());
minZ = Math.min(minZ, rec.getZ());
maxX = Math.max(maxX, rec.getWidth() + rec.getX());
maxY = Math.max(maxY, rec.getHeight() + rec.getY());
maxZ = Math.max(maxZ, rec.getDepth() + rec.getZ());
}
Rectangle3D maxBounds = new Rectangle3D(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ);
GL11.glPushMatrix();
if (debugSpin) {
float angle = (((System.currentTimeMillis() / 10) % 360));
GL11.glRotatef(angle, 0, 1, 0);
}
// Target bounds
if (debugShowTargetBounds) {
drawBounds(new Rectangle3D(-targetWidth / 2, -targetHeight / 2, -targetWidth / 2, targetWidth, targetHeight, targetWidth), 0, 0, 255);
}
int biggerSize = Math.max(maxBounds.getWidth(), maxBounds.getHeight());
biggerSize = Math.max(biggerSize, maxBounds.getDepth());
float newScaleW = (float) targetWidth / Math.max(maxBounds.getWidth(), maxBounds.getDepth());
float newScaleH = (float) targetHeight / maxBounds.getHeight();
float newScale = Math.min(newScaleW, newScaleH);
GL11.glScalef(newScale, newScale, newScale);
// Center the skin
GL11.glTranslated(-(maxBounds.getWidth() / 2F + maxBounds.getX()) * mcScale, 0, 0);
GL11.glTranslated(0, -(maxBounds.getHeight() / 2F + maxBounds.getY()) * mcScale, 0);
GL11.glTranslated(0, 0, -(maxBounds.getDepth() / 2F + maxBounds.getZ()) * mcScale);
renderSkinWithHelper(skin, skinPointer, showSkinPaint, doLodLoading);
if (debugShowFullBounds) {
drawBounds(maxBounds, 255, 255, 0);
}
if (debugShowPartBounds) {
for (int i = 0; i < boundsParts.size(); i++) {
drawBounds(boundsParts.get(i), 255, 0, 0);
}
}
if (debugShowTextureBounds) {
for (int i = 0; i < boundsTextures.size(); i++) {
drawBounds(boundsTextures.get(i), 0, 255, 0);
}
}
GL11.glPopMatrix();
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured in project Armourers-Workshop by RiskyKen.
the class EntityTextureInfo method applySkinsToTexture.
private void applySkinsToTexture() {
for (int i = 0; i < skins.length; i++) {
Skin skin = skins[i];
if (skin != null && skin.hasPaintData()) {
for (int ix = 0; ix < textureWidth; ix++) {
for (int iy = 0; iy < textureHeight; iy++) {
int paintColour = skin.getPaintData()[ix + (iy * textureWidth)];
PaintType paintType = PaintType.getPaintTypeFromColour(paintColour);
if (paintType == PaintType.NORMAL) {
bufferedEntitySkinnedImage.setRGB(ix, iy, BitwiseUtils.setUByteToInt(paintColour, 0, 255));
}
if (paintType == PaintType.HAIR) {
int colour = dyeColour(lastEntityHairColour, paintColour, 9, skin);
bufferedEntitySkinnedImage.setRGB(ix, iy, colour);
}
if (paintType == PaintType.SKIN) {
int colour = dyeColour(lastEntitySkinColour, paintColour, 8, skin);
bufferedEntitySkinnedImage.setRGB(ix, iy, colour);
}
if (paintType.getKey() >= 1 && paintType.getKey() <= 8) {
int dyeNumber = paintType.getKey() - 1;
if (dyes != null && dyes[i] != null && dyes[i].haveDyeInSlot(dyeNumber)) {
byte[] dye = dyes[i].getDyeColour(dyeNumber);
int colour = dyeColour(dye, paintColour, dyeNumber, skin);
bufferedEntitySkinnedImage.setRGB(ix, iy, colour);
} else {
bufferedEntitySkinnedImage.setRGB(ix, iy, BitwiseUtils.setUByteToInt(paintColour, 0, 255));
}
}
}
}
}
}
for (int i = 0; i < skins.length; i++) {
Skin skin = skins[i];
if (skin != null && SkinProperties.PROP_ARMOUR_OVERRIDE.getValue(skin.getProperties())) {
for (int j = 0; j < skin.getPartCount(); j++) {
SkinPart skinPart = skin.getParts().get(j);
if (skinPart.getPartType() instanceof ISkinPartTypeTextured) {
ISkinPartTypeTextured typeTextured = (ISkinPartTypeTextured) skinPart.getPartType();
Point texLoc = typeTextured.getTextureLocation();
IPoint3D texSize = typeTextured.getTextureModelSize();
for (int ix = 0; ix < texSize.getZ() * 2 + texSize.getX() * 2; ix++) {
for (int iy = 0; iy < texSize.getZ() + texSize.getY(); iy++) {
if (skin.getSkinType() == SkinTypeRegistry.skinLegs) {
if (iy >= 12) {
continue;
}
if (iy < 4 & ix > 7 & ix < 12) {
continue;
}
}
if (skin.getSkinType() == SkinTypeRegistry.skinFeet) {
if (iy < 12) {
if (!(iy < 4 & ix > 7 & ix < 12)) {
continue;
}
}
}
bufferedEntitySkinnedImage.setRGB((int) texLoc.getX() + ix, (int) texLoc.getY() + iy, 0x00FFFFFF);
}
}
}
}
}
}
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured in project Armourers-Workshop by RiskyKen.
the class BlockBoundingBox method setColour.
@Override
public boolean setColour(IBlockAccess world, int x, int y, int z, int colour, int side) {
ForgeDirection sideBlock = ForgeDirection.getOrientation(side);
if (world.getBlock(x + sideBlock.offsetX, y + sideBlock.offsetY, z + sideBlock.offsetZ) == this) {
return false;
}
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityBoundingBox) {
TileEntityArmourer parent = ((TileEntityBoundingBox) te).getParent();
if (((TileEntityBoundingBox) te).getSkinPart() instanceof ISkinPartTypeTextured) {
if (parent != null) {
ISkinType skinType = parent.getSkinType();
Point texturePoint = SkinTextureHelper.getTextureLocationFromWorldBlock((TileEntityBoundingBox) te, side);
int oldColour = parent.getPaintData(texturePoint.x, texturePoint.y);
int paintType = BitwiseUtils.getUByteFromInt(oldColour, 0);
int newColour = BitwiseUtils.setUByteToInt(colour, 0, paintType);
parent.updatePaintData(texturePoint.x, texturePoint.y, newColour);
return true;
}
}
}
return false;
}
use of riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured in project Armourers-Workshop by RiskyKen.
the class BlockBoundingBox method getColour.
@Override
public int getColour(IBlockAccess world, int x, int y, int z, int side) {
ForgeDirection sideBlock = ForgeDirection.getOrientation(side);
if (world.getBlock(x + sideBlock.offsetX, y + sideBlock.offsetY, z + sideBlock.offsetZ) == this) {
return 0x00FFFFFF;
}
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityBoundingBox) {
TileEntityArmourer parent = ((TileEntityBoundingBox) te).getParent();
if (parent != null) {
if (((TileEntityBoundingBox) te).getSkinPart() instanceof ISkinPartTypeTextured) {
Point texturePoint = SkinTextureHelper.getTextureLocationFromWorldBlock((TileEntityBoundingBox) te, side);
int colour = parent.getPaintData(texturePoint.x, texturePoint.y);
int paintType = BitwiseUtils.getUByteFromInt(colour, 0);
if (paintType != 0) {
return colour;
} else {
if (te.getWorldObj().isRemote) {
PlayerTexture playerTexture = ClientProxy.playerTextureDownloader.getPlayerTexture(parent.getTexture());
BufferedImage playerSkin = SkinHelper.getBufferedImageSkin(playerTexture.getResourceLocation());
if (playerSkin != null) {
colour = playerSkin.getRGB(texturePoint.x, texturePoint.y);
return colour;
}
}
}
}
}
}
return 0x00FFFFFF;
}
Aggregations