use of riskyken.armourersWorkshop.api.common.IPoint3D 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.IPoint3D 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.IPoint3D in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method saveArmourPart.
private static SkinPart saveArmourPart(World world, ISkinPartType skinPart, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean markerCheck) throws SkinSaveException {
int cubeCount = getNumberOfCubesInPart(world, xCoord, yCoord, zCoord, skinPart);
if (cubeCount < 1) {
return null;
}
SkinCubeData cubeData = new SkinCubeData();
cubeData.setCubeCount(cubeCount);
ArrayList<CubeMarkerData> markerBlocks = new ArrayList<CubeMarkerData>();
IRectangle3D buildSpace = skinPart.getBuildingSpace();
IPoint3D offset = skinPart.getOffset();
int i = 0;
for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
int x = xCoord + ix + -offset.getX() + buildSpace.getX();
int y = yCoord + iy + -offset.getY();
int z = zCoord + iz + offset.getZ() + buildSpace.getZ();
int xOrigin = -ix + -buildSpace.getX();
int yOrigin = -iy + -buildSpace.getY();
int zOrigin = -iz + -buildSpace.getZ();
if (!world.isAirBlock(x, y, z)) {
Block block = world.getBlock(x, y, z);
if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
saveArmourBlockToList(world, x, y, z, xOrigin - 1, yOrigin - 1, -zOrigin, cubeData, i, markerBlocks, direction);
i++;
}
}
}
}
}
if (markerCheck) {
if (skinPart.getMinimumMarkersNeeded() > markerBlocks.size()) {
throw new SkinSaveException("Missing marker for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
}
if (markerBlocks.size() > skinPart.getMaximumMarkersNeeded()) {
throw new SkinSaveException("Too many markers for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
}
}
return new SkinPart(cubeData, skinPart, markerBlocks);
}
use of riskyken.armourersWorkshop.api.common.IPoint3D in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method getBuildingCubesForPart.
private static void getBuildingCubesForPart(World world, int x, int y, int z, ISkinPartType skinPart, ArrayList<BlockLocation> blList) {
IRectangle3D buildSpace = skinPart.getBuildingSpace();
IPoint3D offset = skinPart.getOffset();
for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
int xTar = x + ix + -offset.getX() + buildSpace.getX();
int yTar = y + iy + -offset.getY();
int zTar = z + iz + offset.getZ() + buildSpace.getZ();
if (world.blockExists(xTar, yTar, zTar)) {
Block block = world.getBlock(xTar, yTar, zTar);
if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
blList.add(new BlockLocation(xTar, yTar, zTar));
}
}
}
}
}
}
use of riskyken.armourersWorkshop.api.common.IPoint3D in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method clearEquipmentCubesForSkinPart.
private static int clearEquipmentCubesForSkinPart(World world, int x, int y, int z, ISkinPartType skinPart) {
IRectangle3D buildSpace = skinPart.getBuildingSpace();
IPoint3D offset = skinPart.getOffset();
int blockCount = 0;
for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
int xTar = x + ix + -offset.getX() + buildSpace.getX();
int yTar = y + iy + -offset.getY();
int zTar = z + iz + offset.getZ() + buildSpace.getZ();
if (world.blockExists(xTar, yTar, zTar)) {
Block block = world.getBlock(xTar, yTar, zTar);
if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
world.setBlockToAir(xTar, yTar, zTar);
world.removeTileEntity(xTar, yTar, zTar);
blockCount++;
}
}
}
}
}
return blockCount;
}
Aggregations