use of riskyken.armourersWorkshop.api.common.IRectangle3D 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.IRectangle3D 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.IRectangle3D 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.IRectangle3D 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;
}
use of riskyken.armourersWorkshop.api.common.IRectangle3D in project Armourers-Workshop by RiskyKen.
the class ArmourerWorldHelper method removeBoundingBoxesForSkinPart.
private static void removeBoundingBoxesForSkinPart(World world, int x, int y, int z, ISkinPartType skinPart) {
IRectangle3D buildSpace = skinPart.getBuildingSpace();
IRectangle3D guideSpace = skinPart.getGuideSpace();
IPoint3D offset = skinPart.getOffset();
if (guideSpace == null) {
return;
}
for (int ix = 0; ix < guideSpace.getWidth(); ix++) {
for (int iy = 0; iy < guideSpace.getHeight(); iy++) {
for (int iz = 0; iz < guideSpace.getDepth(); iz++) {
int xTar = x + ix + -offset.getX() + guideSpace.getX();
int yTar = y + iy + -offset.getY() + guideSpace.getY() - buildSpace.getY();
int zTar = z + iz + offset.getZ() + guideSpace.getZ();
if (world.blockExists(xTar, yTar, zTar)) {
if (world.getBlock(xTar, yTar, zTar) == ModBlocks.boundingBox) {
world.setBlockToAir(xTar, yTar, zTar);
}
}
}
}
}
}
Aggregations