Search in sources :

Example 1 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart 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 SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class RenderSkinnedArrow method doRender.

@Override
public void doRender(EntityArrow entityArrow, double x, double y, double z, float yaw, float partialTickTime) {
    if (entityArrow.shootingEntity != null && entityArrow.shootingEntity instanceof EntityClientPlayerMP) {
        EntityClientPlayerMP player = (EntityClientPlayerMP) entityArrow.shootingEntity;
        IEntityEquipment entityEquipment = equipmentModelRenderer.getPlayerCustomEquipmentData(player);
        if (entityEquipment != null && entityEquipment.haveEquipment(SkinTypeRegistry.skinBow, 0)) {
            ISkinPointer skinPointer = entityEquipment.getSkinPointer(SkinTypeRegistry.skinBow, 0);
            if (ClientSkinCache.INSTANCE.isSkinInCache(skinPointer)) {
                Skin skin = ClientSkinCache.INSTANCE.getSkin(skinPointer);
                if (skin != null) {
                    SkinPart skinPart = skin.getPart("armourers:bow.arrow");
                    if (skinPart != null) {
                        ModRenderHelper.enableAlphaBlend();
                        renderArrowSkin(entityArrow, x, y, z, partialTickTime, skinPart, skinPointer.getSkinDye());
                        ModRenderHelper.disableAlphaBlend();
                        return;
                    }
                }
            } else {
                ClientSkinCache.INSTANCE.requestSkinFromServer(skinPointer);
            }
        }
    }
    super.doRender(entityArrow, x, y, z, yaw, partialTickTime);
}
Also used : EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) IEntityEquipment(riskyken.armourersWorkshop.api.common.skin.IEntityEquipment) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 3 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class RenderItemBowSkin method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
    if (canRenderModel(stack) & type != ItemRenderType.INVENTORY) {
        if (type != ItemRenderType.ENTITY) {
            GL11.glPopMatrix();
        // GL11.glPopMatrix();
        // GL11.glRotatef(-135, 0, 1, 0);
        // GL11.glRotatef(-10, 0, 0, 1);
        }
        GL11.glPushMatrix();
        AbstractClientPlayer player = null;
        int useCount = 0;
        boolean hasArrow = false;
        if (data.length >= 2) {
            if (data[1] instanceof AbstractClientPlayer & data[0] instanceof RenderBlocks) {
                RenderBlocks renderBlocks = (RenderBlocks) data[0];
                player = (AbstractClientPlayer) data[1];
                useCount = player.getItemInUseDuration();
                hasArrow = player.inventory.hasItem(Items.arrow);
                IEntityEquipment entityEquipment = SkinModelRenderer.INSTANCE.getPlayerCustomEquipmentData(player);
                if (!hasArrow) {
                    if (player.capabilities.isCreativeMode) {
                        hasArrow = true;
                    }
                }
            }
        }
        float scale = 0.0625F;
        float angle = (float) (((double) System.currentTimeMillis() / 5) % 360F);
        switch(type) {
            case EQUIPPED:
                GL11.glScalef(1F, -1F, 1F);
                GL11.glScalef(1.6F, 1.6F, 1.6F);
                GL11.glRotatef(-135, 0, 1, 0);
                GL11.glRotatef(10, 0, 0, 1);
                GL11.glRotatef(-20, 1, 0, 0);
                GL11.glRotatef(90, 0, 1, 0);
                GL11.glTranslatef(0F * scale, -6F * scale, 1F * scale);
                break;
            case ENTITY:
                GL11.glRotatef(180, 0, 0, 1);
                GL11.glTranslatef(0F, -10F * scale, 0F);
                break;
            case EQUIPPED_FIRST_PERSON:
                GL11.glScalef(1.6F, 1.6F, 1.6F);
                GL11.glRotatef(-135, 0, 1, 0);
                GL11.glRotatef(180, 0, 0, 1);
                GL11.glRotatef(-90, 0, 1, 0);
                // Back tilt
                GL11.glRotatef(-17, 1, 0, 0);
                GL11.glRotatef(2, 0, 0, 1);
                GL11.glTranslatef(0F * scale, -2F * scale, 1F * scale);
                if (useCount > 0) {
                    GL11.glTranslatef(-5 * scale, 3 * scale, 1 * scale);
                    GL11.glRotatef(-6, 1, 0, 0);
                    GL11.glRotatef(-16, 0, 1, 0);
                    GL11.glRotatef(2, 0, 0, 1);
                }
                break;
            default:
                break;
        }
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
        GL11.glEnable(GL11.GL_CULL_FACE);
        ModRenderHelper.enableAlphaBlend();
        ModelSkinBow model = SkinModelRenderer.INSTANCE.customBow;
        model.frame = getAnimationFrame(useCount);
        SkinPointer skinPointer = SkinNBTHelper.getSkinPointerFromStack(stack);
        Skin skin = ClientSkinCache.INSTANCE.getSkin(skinPointer);
        model.render(player, skin, false, skinPointer.getSkinDye(), null, false, 0, false);
        if (hasArrow & useCount > 0) {
            GL11.glTranslatef(1 * scale, 1 * scale, -12 * scale);
            int tarPart = getAnimationFrame(useCount);
            if (skin.getParts().get(tarPart).getMarkerBlocks().size() > 0) {
                CubeMarkerData cmd = skin.getParts().get(tarPart).getMarkerBlocks().get(0);
                ForgeDirection dir = ForgeDirection.getOrientation(cmd.meta - 1);
                GL11.glTranslatef((-dir.offsetX + cmd.x) * scale, (-dir.offsetY + cmd.y) * scale, (dir.offsetZ + cmd.z) * scale);
                // Shift the arrow a little to stop z fighting.
                GL11.glTranslatef(-0.01F * scale, 0.01F * scale, -0.01F * scale);
                SkinPart skinPartArrow = skin.getPart("armourers:bow.arrow");
                if (skinPartArrow != null) {
                    SkinPartRenderer.INSTANCE.renderPart(skinPartArrow, scale, skinPointer.getSkinDye(), null, false);
                } else {
                    ModelArrow.MODEL.render(scale, false);
                }
            }
        }
        GL11.glPopAttrib();
        GL11.glPopMatrix();
        if (type != ItemRenderType.ENTITY) {
            // GL11.glPushMatrix();
            GL11.glPushMatrix();
        }
    } else {
        if (itemRenderer != null) {
            itemRenderer.renderItem(type, stack, data);
        } else {
            renderNomalIcon(stack);
        }
    }
}
Also used : AbstractClientPlayer(net.minecraft.client.entity.AbstractClientPlayer) RenderBlocks(net.minecraft.client.renderer.RenderBlocks) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IEntityEquipment(riskyken.armourersWorkshop.api.common.skin.IEntityEquipment) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ModelSkinBow(riskyken.armourersWorkshop.client.model.skin.ModelSkinBow) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 4 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart in project Armourers-Workshop by RiskyKen.

the class ModelSkinSkirt method render.

@Override
public void render(Entity entity, Skin armourData, boolean showSkinPaint, ISkinDye skinDye, byte[] extraColour, boolean itemRender, double distance, boolean doLodLoading) {
    if (armourData == null) {
        return;
    }
    ArrayList<SkinPart> parts = armourData.getParts();
    if (entity != null && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        this.isSneak = player.isSneaking();
        this.isRiding = player.isRiding();
        this.heldItemRight = 0;
        if (player.getHeldItem() != null) {
            this.heldItemRight = 1;
        }
    }
    if (ClientProxy.isJrbaClientLoaded()) {
        this.isChild = false;
    }
    ApiRegistrar.INSTANCE.onRenderEquipment(entity, SkinTypeRegistry.skinSkirt);
    for (int i = 0; i < parts.size(); i++) {
        SkinPart part = parts.get(i);
        GL11.glPushMatrix();
        if (isChild) {
            float f6 = 2.0F;
            GL11.glScalef(1.0F / f6, 1.0F / f6, 1.0F / f6);
            GL11.glTranslatef(0.0F, 24.0F * SCALE, 0.0F);
        }
        ApiRegistrar.INSTANCE.onRenderEquipmentPart(entity, part.getPartType());
        if (part.getPartType().getPartName().equals("base")) {
            renderSkirt(part, SCALE, skinDye, extraColour, distance, doLodLoading);
        }
        GL11.glPopMatrix();
    }
    GL11.glColor3f(1F, 1F, 1F);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 5 with SkinPart

use of riskyken.armourersWorkshop.common.skin.data.SkinPart 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)

Aggregations

SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)26 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 ArrayList (java.util.ArrayList)5 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)3 SkinModelTexture (riskyken.armourersWorkshop.client.skin.SkinModelTexture)3 CubeMarkerData (riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData)3 Color (java.awt.Color)2 IOException (java.io.IOException)2 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)2 IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)2 IEntityEquipment (riskyken.armourersWorkshop.api.common.skin.IEntityEquipment)2 Rectangle3D (riskyken.armourersWorkshop.api.common.skin.Rectangle3D)2 ISkinPartTypeTextured (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartTypeTextured)2 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)2 SkinCubeData (riskyken.armourersWorkshop.common.skin.data.SkinCubeData)2 SkinBlock (riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)2 MovementType (riskyken.armourersWorkshop.common.skin.type.wings.SkinWings.MovementType)2