Search in sources :

Example 1 with IRectangle3D

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();
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) ArrayList(java.util.ArrayList) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) Rectangle3D(riskyken.armourersWorkshop.api.common.skin.Rectangle3D) ISkinPartTypeTextured(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 2 with IRectangle3D

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);
}
Also used : SkinSaveException(riskyken.armourersWorkshop.common.exception.SkinSaveException) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 3 with IRectangle3D

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));
                    }
                }
            }
        }
    }
}
Also used : IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock) BlockLocation(riskyken.armourersWorkshop.common.blocks.BlockLocation)

Example 4 with IRectangle3D

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;
}
Also used : IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)

Example 5 with IRectangle3D

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);
                    }
                }
            }
        }
    }
}
Also used : IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D)

Aggregations

IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)12 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)9 Block (net.minecraft.block.Block)5 SkinBlock (riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)5 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)4 ArrayList (java.util.ArrayList)2 Rectangle3D (riskyken.armourersWorkshop.api.common.skin.Rectangle3D)2 CubeMarkerData (riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData)2 SkinCubeData (riskyken.armourersWorkshop.common.skin.data.SkinCubeData)2 SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ICubeColour (riskyken.armourersWorkshop.api.common.skin.cubes.ICubeColour)1 ISkinPart (riskyken.armourersWorkshop.api.common.skin.data.ISkinPart)1 ISkinPartTypeTextured (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured)1 IRenderBuffer (riskyken.armourersWorkshop.client.render.IRenderBuffer)1 BlockLocation (riskyken.armourersWorkshop.common.blocks.BlockLocation)1 MiniCube (riskyken.armourersWorkshop.common.data.MiniCube)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 CubeColour (riskyken.armourersWorkshop.common.skin.cubes.CubeColour)1