Search in sources :

Example 1 with ItemPowerpack

use of blusunrize.immersiveengineering.common.items.ItemPowerpack in project ImmersiveEngineering by BluSunrize.

the class ModelPowerpack method render.

@Override
public void render(Entity entity, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float scale) {
    if (entity instanceof EntityLivingBase) {
        ItemStack chest = ((EntityLivingBase) entity).getItemStackFromSlot(EntityEquipmentSlot.CHEST);
        ItemStack powerpack = null;
        float storage = 0;
        if (!chest.isEmpty() && chest.getItem() instanceof ItemPowerpack)
            powerpack = chest;
        else if (!chest.isEmpty() && chest.getItem() instanceof ItemArmor && ItemNBTHelper.hasKey(chest, "IE:Powerpack"))
            powerpack = ItemNBTHelper.getItemStack(chest, "IE:Powerpack");
        else if (IEBipedLayerRenderer.POWERPACK_PLAYERS.containsKey(entity.getUniqueID()))
            powerpack = IEBipedLayerRenderer.POWERPACK_PLAYERS.get(entity.getUniqueID()).getLeft();
        if (powerpack != null) {
            float max = EnergyHelper.getMaxEnergyStored(powerpack);
            storage = max <= 0 ? 0 : EnergyHelper.getEnergyStored(powerpack) / max;
            this.modelParts[7].rotateAngleZ = 0.5235987f - (1.047197f * storage);
        }
    }
    GlStateManager.enableBlend();
    super.render(entity, p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, scale);
    GlStateManager.disableBlend();
    ClientUtils.bindTexture("immersiveengineering:textures/blocks/wire.png");
    GlStateManager.pushMatrix();
    if (entity instanceof EntityLivingBase)
        for (EnumHand hand : EnumHand.values()) {
            ItemStack stack = ((EntityLivingBase) entity).getHeldItem(hand);
            if (!stack.isEmpty() && EnergyHelper.isFluxItem(stack)) {
                boolean right = (hand == EnumHand.MAIN_HAND) == (((EntityLivingBase) entity).getPrimaryHand() == EnumHandSide.RIGHT);
                float angleX = (right ? bipedRightArm : bipedLeftArm).rotateAngleX;
                float angleZ = (right ? bipedRightArm : bipedLeftArm).rotateAngleZ;
                String cacheKey = keyFormat.format(angleX) + "_" + keyFormat.format(angleZ);
                Vec3d[] vex = new Vec3d[0];
                try {
                    vex = (right ? catenaryCacheRight : catenaryCacheLeft).get(cacheKey, () -> {
                        double armLength = .75f;
                        double x = .3125 + (right ? 1 : -1) * armLength * Math.sin(angleZ);
                        double y = armLength * Math.cos(angleX);
                        double z = armLength * Math.sin(angleX);
                        return ApiUtils.getConnectionCatenary(new Vec3d(.484375, -.75, .25), new Vec3d(x, -y, z), 1.5);
                    });
                } catch (Exception e) {
                }
                float vStep = 1f / vex.length;
                int i = 0;
                Tessellator tes = ClientUtils.tes();
                BufferBuilder worldrenderer = tes.getBuffer();
                // float[] colour = {.7f,.42f,.25f,1};
                float[] colour = { .93f, .63f, .27f, 1 };
                worldrenderer.begin(GL11.GL_QUAD_STRIP, DefaultVertexFormats.POSITION_TEX_COLOR);
                for (Vec3d v : vex) {
                    worldrenderer.pos((right ? -v.x : v.x) - .015625, -v.y, v.z).tex(vStep * i, 0).color(colour[0], colour[1], colour[2], colour[3]).endVertex();
                    worldrenderer.pos((right ? -v.x : v.x) + .015625, -v.y, v.z).tex(vStep * i++, 1).color(colour[0], colour[1], colour[2], colour[3]).endVertex();
                }
                tes.draw();
                worldrenderer.begin(GL11.GL_QUAD_STRIP, DefaultVertexFormats.POSITION_TEX_COLOR);
                i = 0;
                for (Vec3d v : vex) {
                    worldrenderer.pos((right ? -v.x : v.x), -v.y - .015625, v.z).tex(vStep * i, 0).color(colour[0], colour[1], colour[2], colour[3]).endVertex();
                    worldrenderer.pos((right ? -v.x : v.x), -v.y + .015625, v.z).tex(vStep * i++, 1).color(colour[0], colour[1], colour[2], colour[3]).endVertex();
                }
                tes.draw();
            }
        }
    GlStateManager.popMatrix();
}
Also used : ItemPowerpack(blusunrize.immersiveengineering.common.items.ItemPowerpack) Tessellator(net.minecraft.client.renderer.Tessellator) ItemArmor(net.minecraft.item.ItemArmor) EnumHand(net.minecraft.util.EnumHand) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

ItemPowerpack (blusunrize.immersiveengineering.common.items.ItemPowerpack)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemArmor (net.minecraft.item.ItemArmor)1 ItemStack (net.minecraft.item.ItemStack)1 EnumHand (net.minecraft.util.EnumHand)1 Vec3d (net.minecraft.util.math.Vec3d)1