Search in sources :

Example 1 with ISkinPartTypeTextured

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);
}
Also used : IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISkinPartTypeTextured(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured) Point(java.awt.Point) Point(java.awt.Point)

Example 2 with ISkinPartTypeTextured

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();
}
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 3 with ISkinPartTypeTextured

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) PaintType(riskyken.armourersWorkshop.common.painting.PaintType) ISkinPartTypeTextured(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured) Point(java.awt.Point) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart) Point(java.awt.Point)

Example 4 with ISkinPartTypeTextured

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) TileEntityArmourer(riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer) TileEntityBoundingBox(riskyken.armourersWorkshop.common.tileentities.TileEntityBoundingBox) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISkinPartTypeTextured(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured) Point(java.awt.Point) Point(java.awt.Point)

Example 5 with ISkinPartTypeTextured

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityArmourer(riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer) PlayerTexture(riskyken.armourersWorkshop.client.texture.PlayerTexture) TileEntityBoundingBox(riskyken.armourersWorkshop.common.tileentities.TileEntityBoundingBox) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISkinPartTypeTextured(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ISkinPartTypeTextured (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured)10 Point (java.awt.Point)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 TileEntity (net.minecraft.tileentity.TileEntity)5 TileEntityArmourer (riskyken.armourersWorkshop.common.tileentities.TileEntityArmourer)5 TileEntityBoundingBox (riskyken.armourersWorkshop.common.tileentities.TileEntityBoundingBox)5 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)3 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)2 PaintType (riskyken.armourersWorkshop.common.painting.PaintType)2 SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)2 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)1 Rectangle3D (riskyken.armourersWorkshop.api.common.skin.Rectangle3D)1 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)1 PlayerTexture (riskyken.armourersWorkshop.client.texture.PlayerTexture)1 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)1