Search in sources :

Example 81 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderBelljar method render.

@Override
public void render(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = tile.getPos();
    if (!quads.containsKey(tile.getFacing())) {
        IBlockState state = getWorld().getBlockState(blockPos);
        if (state.getBlock() != IEContent.blockMetalDevice1)
            return;
        state = state.getActualState(getWorld(), blockPos);
        IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
        if (state instanceof IExtendedBlockState)
            state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
        quads.put(tile.getFacing(), model.getQuads(state, null, 0));
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BufferBuilder worldRenderer = Tessellator.getInstance().getBuffer();
    GlStateManager.enableCull();
    IPlantHandler plantHandler = tile.getCurrentPlantHandler();
    if (plantHandler != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 1.0625, 0);
        GlStateManager.color(1, 1, 1, 1);
        NonNullList<ItemStack> inventory = tile.getInventory();
        float scale = plantHandler.getRenderSize(inventory.get(1), inventory.get(0), tile.renderGrowth, tile);
        GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
        GlStateManager.scale(scale, scale, scale);
        if (!plantHandler.overrideRender(inventory.get(1), inventory.get(0), tile.renderGrowth, tile, blockRenderer)) {
            IBlockState[] states = plantHandler.getRenderedPlant(inventory.get(1), inventory.get(0), tile.renderGrowth, tile);
            if (states == null || states.length < 1)
                return;
            for (IBlockState s : states) {
                List<BakedQuad> plantQuadList = plantQuads.get(s);
                if (plantQuadList == null) {
                    IBakedModel plantModel = blockRenderer.getModelForState(s);
                    plantQuadList = new ArrayList<BakedQuad>(plantModel.getQuads(s, null, 0));
                    for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
                    plantQuads.put(s, plantQuadList);
                }
                if (plantQuadList != null) {
                    GlStateManager.pushMatrix();
                    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                    ClientUtils.renderModelTESRFancy(plantQuadList, worldRenderer, tile.getWorld(), blockPos, false);
                    Tessellator.getInstance().draw();
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0, 1, 0);
                }
            }
        }
        GlStateManager.popMatrix();
    }
    GlStateManager.depthMask(false);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    ClientUtils.renderModelTESRFast(quads.get(tile.getFacing()), worldRenderer, tile.getWorld(), blockPos);
    Tessellator.getInstance().draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState) ItemStack(net.minecraft.item.ItemStack)

Example 82 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderBucketWheel method render.

@Override
public void render(TileEntityBucketWheel tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    if (model == null) {
        state = state.withProperty(IEProperties.DYNAMICRENDER, true);
        state = state.withProperty(IEProperties.FACING_HORIZONTAL, EnumFacing.NORTH);
        model = blockRenderer.getModelForState(state);
    }
    OBJState objState = null;
    HashMap<String, String> texMap = new HashMap<>();
    if (state instanceof IExtendedBlockState) {
        ArrayList<String> list = Lists.newArrayList("bucketWheel");
        synchronized (tile.digStacks) {
            for (int i = 0; i < tile.digStacks.size(); i++) if (!tile.digStacks.get(i).isEmpty()) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks.get(i).getItem());
                IBlockState digState = b != Blocks.AIR ? b.getStateFromMeta(tile.digStacks.get(i).getMetadata()) : Blocks.COBBLESTONE.getDefaultState();
                IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
                if (digModel != null && digModel.getParticleTexture() != null)
                    texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
            }
        }
        objState = new OBJState(list, true);
    }
    Tessellator tessellator = Tessellator.getInstance();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    EnumFacing facing = tile.facing;
    if (tile.mirrored) {
        GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
        GlStateManager.disableCull();
    }
    float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
    GlStateManager.rotate(dir, 0, 1, 0);
    float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * partialTicks : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BufferBuilder worldRenderer = tessellator.getBuffer();
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5, -.5, -.5);
    List<BakedQuad> quads;
    if (model instanceof IESmartObjModel)
        quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
    else
        quads = model.getQuads(state, null, 0);
    ClientUtils.renderModelTESRFast(quads, worldRenderer, tile.getWorld(), tile.getPos());
    worldRenderer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    if (tile.mirrored) {
        GlStateManager.enableCull();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 83 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class ItemRendererIEOBJ method renderByItem.

@Override
public void renderByItem(ItemStack stack, float partialTicks) {
    GlStateManager.enableCull();
    partialTicks = mc().getRenderPartialTicks();
    if (stack.getItem() instanceof IOBJModelCallback) {
        IOBJModelCallback<ItemStack> callback = (IOBJModelCallback<ItemStack>) stack.getItem();
        World w = IESmartObjModel.tempEntityStatic != null ? IESmartObjModel.tempEntityStatic.world : null;
        IBakedModel model = mc().getRenderItem().getItemModelWithOverrides(stack, w, IESmartObjModel.tempEntityStatic);
        if (model instanceof IESmartObjModel) {
            GlStateManager.disableCull();
            ItemStack shader = ItemStack.EMPTY;
            ShaderCase sCase = null;
            if (!stack.isEmpty() && stack.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
                CapabilityShader.ShaderWrapper wrapper = stack.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
                if (wrapper != null) {
                    shader = wrapper.getShaderItem();
                    if (!shader.isEmpty() && shader.getItem() instanceof IShaderItem)
                        sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, stack, wrapper.getShaderType());
                }
            }
            IESmartObjModel obj = (IESmartObjModel) model;
            Map<String, Boolean> visible = new HashMap<>(((OBJModel.OBJState) obj.getState()).getVisibilityMap());
            Tessellator tes = Tessellator.getInstance();
            BufferBuilder bb = tes.getBuffer();
            ItemCameraTransforms.TransformType transformType = obj.lastCameraTransform;
            List<Pair<BakedQuad, ShaderLayer>> quads = new ArrayList<>();
            for (String[] groups : callback.getSpecialGroups(stack, transformType, IESmartObjModel.tempEntityStatic)) {
                GlStateManager.pushMatrix();
                Matrix4 mat = callback.getTransformForGroups(stack, groups, transformType, mc().player, ItemRendererIEOBJ.mat, partialTicks);
                GlStateManager.multMatrix(mat.toFloatBuffer(transform));
                boolean wasLightmapEnabled, wasLightingEnabled;
                {
                    GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
                    wasLightmapEnabled = GL11.glIsEnabled(GL11.GL_TEXTURE_2D);
                    GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
                    wasLightingEnabled = GL11.glIsEnabled(GL11.GL_LIGHTING);
                }
                boolean bright = callback.areGroupsFullbright(stack, groups);
                if (bright) {
                    GlStateManager.disableLighting();
                    ClientUtils.setLightmapDisabled(true);
                }
                renderQuadsForGroups(groups, callback, obj, quads, stack, sCase, shader, bb, tes, visible, partialTicks);
                if (bright) {
                    if (wasLightingEnabled)
                        GlStateManager.enableLighting();
                    if (wasLightmapEnabled)
                        ClientUtils.setLightmapDisabled(false);
                }
                GlStateManager.popMatrix();
            }
            renderQuadsForGroups(visible.keySet().toArray(new String[0]), callback, obj, quads, stack, sCase, shader, bb, tes, visible, partialTicks);
            GlStateManager.enableCull();
        }
    }
}
Also used : CapabilityShader(blusunrize.immersiveengineering.api.shader.CapabilityShader) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) World(net.minecraft.world.World) ItemCameraTransforms(net.minecraft.client.renderer.block.model.ItemCameraTransforms) IOBJModelCallback(blusunrize.immersiveengineering.client.models.IOBJModelCallback) IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) OBJModel(net.minecraftforge.client.model.obj.OBJModel) Pair(org.apache.commons.lang3.tuple.Pair) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Example 84 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderAutoWorkbench method render.

@Override
public void render(TileEntityAutoWorkbench te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
        return;
    // Grab model + correct eextended state
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    // Initialize Tesselator and BufferBuilder
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldRenderer = tessellator.getBuffer();
    // Outer GL Wrapping, initial translation
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    if (te.mirrored)
        GlStateManager.scale(te.facing.getXOffset() == 0 ? -1 : 1, 1, te.facing.getZOffset() == 0 ? -1 : 1);
    // Item Displacement
    float[][] itemDisplays = new float[te.processQueue.size()][];
    // Animations
    float drill = 0;
    float lift = 0;
    float press = 0;
    float liftPress = 0;
    for (int i = 0; i < itemDisplays.length; i++) {
        MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
        if (process == null || process.processTick <= 0 || process.processTick == process.maxTicks)
            continue;
        // +partialTicks
        float processTimer = ((float) process.processTick) / process.maxTicks * 180;
        if (processTimer <= 9)
            continue;
        float itemX = -1;
        float itemY = -.34375f;
        float itemZ = -.9375f;
        float itemAngle = 90f;
        if (// slide
        processTimer <= 24) {
            itemAngle = 67.5f;
            if (processTimer <= 19) {
                itemZ += .25 + (19 - processTimer) / 10f * .5f;
                itemY += .25 + (19 - processTimer) / 10f * .21875f;
            } else {
                itemZ += (24 - processTimer) / 5f * .25f;
                itemY += (24 - processTimer) / 5f * .25f;
            }
        } else if (processTimer <= 40) {
            itemX += (processTimer - 24) / 16f;
        } else if (processTimer <= 100) {
            itemX += 1;
            float drillStep = 0;
            if (processTimer <= 60) {
                lift = (processTimer - 40) / 20f * .3125f;
                drillStep = 4 + (60 - processTimer) * 4;
            } else if (processTimer <= 80) {
                lift = .3125f;
                drillStep = 4;
            } else {
                lift = (100 - processTimer) / 20f * .3125f;
                drillStep = 4 + (processTimer - 80) * 4;
            }
            if (drillStep > 0)
                drill = processTimer % drillStep / drillStep * 360;
            itemY += Math.max(0, lift - .0625);
        } else if (processTimer <= 116) {
            itemX += 1;
            itemZ += (processTimer - 100) / 16f;
        } else if (processTimer <= 132) {
            itemX += 1 + (processTimer - 116) / 16f;
            itemZ += 1;
        } else if (processTimer <= 172) {
            itemX += 2;
            itemZ += 1;
            if (processTimer <= 142)
                press = (processTimer - 132) / 10f;
            else if (processTimer <= 162)
                press = 1;
            else
                press = (172 - processTimer) / 10f;
            liftPress = press * .0625f;
            itemY += liftPress;
        } else if (processTimer <= 180) {
            itemX += 2 + (processTimer - 172) / 16f;
            itemZ += 1;
        }
        itemDisplays[i] = new float[] { processTimer, itemX, itemY, itemZ, itemAngle };
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    ItemStack blueprintStack = te.inventory.get(0);
    if (!blueprintStack.isEmpty())
        renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "blueprint");
    GlStateManager.translate(0, lift, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "lift");
    GlStateManager.translate(0, -lift, 0);
    EnumFacing f = te.getFacing();
    float tx = f == EnumFacing.WEST ? -.9375f : f == EnumFacing.EAST ? .9375f : 0;
    float tz = f == EnumFacing.NORTH ? -.9375f : f == EnumFacing.SOUTH ? .9375f : 0;
    GlStateManager.translate(tx, 0, tz);
    GlStateManager.rotate(drill, 0, 1, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "drill");
    GlStateManager.rotate(-drill, 0, 1, 0);
    GlStateManager.translate(-tx, 0, -tz);
    tx = f == EnumFacing.WEST ? -.59375f : f == EnumFacing.EAST ? .59375f : 0;
    tz = f == EnumFacing.NORTH ? -.59375f : f == EnumFacing.SOUTH ? .59375f : 0;
    GlStateManager.translate(tx, -.21875, tz);
    GlStateManager.rotate(press * 90, -f.getZOffset(), 0, f.getXOffset());
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "press");
    GlStateManager.rotate(-press * 90, -f.getZOffset(), 0, f.getXOffset());
    GlStateManager.translate(-tx, .21875, -tz);
    GlStateManager.translate(0, liftPress, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "pressLift");
    GlStateManager.translate(0, -liftPress, 0);
    RenderHelper.enableStandardItemLighting();
    GlStateManager.popMatrix();
    switch(f) {
        case NORTH:
            break;
        case SOUTH:
            GlStateManager.rotate(180, 0, 1, 0);
            break;
        case WEST:
            GlStateManager.rotate(90, 0, 1, 0);
            break;
        case EAST:
            GlStateManager.rotate(-90, 0, 1, 0);
            break;
    }
    // DRAW ITEMS HERE
    for (int i = 0; i < itemDisplays.length; i++) if (itemDisplays[i] != null) {
        MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
        if (process == null || !(process instanceof MultiblockProcessInWorld))
            continue;
        float scale = .3125f;
        List<ItemStack> dList = ((MultiblockProcessInWorld) process).getDisplayItem();
        if (!dList.isEmpty())
            if (dList.size() < 2) {
                GlStateManager.translate(itemDisplays[i][1], itemDisplays[i][2], itemDisplays[i][3]);
                GlStateManager.rotate(itemDisplays[i][4], 1, 0, 0);
                GlStateManager.scale(scale, scale, .5f);
                ClientUtils.mc().getRenderItem().renderItem(dList.get(0), ItemCameraTransforms.TransformType.FIXED);
                GlStateManager.scale(1 / scale, 1 / scale, 2);
                GlStateManager.rotate(-itemDisplays[i][4], 1, 0, 0);
                GlStateManager.translate(-itemDisplays[i][1], -itemDisplays[i][2], -itemDisplays[i][3]);
            } else {
                int size = dList.size();
                int lines = (int) Math.ceil(size / 2f);
                float spacer = (lines - 1) * .234375f;
                for (int d = 0; d < size; d++) {
                    float oX = (size > 2 ? -.3125f : 0) + (lines - d / 2) * .0625f + d % 2 * .3125f;
                    float oZ = -spacer / 2f + d / 2 * .234375f;
                    float oY = 0;
                    float localItemX = itemDisplays[i][1] + oX;
                    float localItemY = itemDisplays[i][2] + oY;
                    float localItemZ = itemDisplays[i][3] + oZ;
                    float subProcess = itemDisplays[i][0] - d / 2 * 4;
                    float localAngle = itemDisplays[i][4];
                    if (// slide
                    subProcess <= 24) {
                        localAngle = 67.5f;
                        if (subProcess <= 19) {
                            localItemZ = -1 + .25f + (19 - subProcess) / 10f * .5f;
                            localItemY = -.34375f + .25f + (19 - subProcess) / 10f * .21875f;
                        } else {
                            localItemZ = -1 + (oZ - (24 - subProcess) / 5f * oZ);
                            localItemY = -.34375f + (24 - subProcess) / 5f * .25f;
                        }
                    }
                    GlStateManager.translate(localItemX, localItemY, localItemZ);
                    GlStateManager.rotate(localAngle, 1, 0, 0);
                    GlStateManager.scale(scale, scale, .5f);
                    ClientUtils.mc().getRenderItem().renderItem(dList.get(d), ItemCameraTransforms.TransformType.FIXED);
                    GlStateManager.scale(1 / scale, 1 / scale, 2);
                    GlStateManager.rotate(-localAngle, 1, 0, 0);
                    GlStateManager.translate(-localItemX, -localItemY, -localItemZ);
                }
            }
    }
    // Blueprint
    double playerDistanceSq = ClientUtils.mc().player.getDistanceSq(blockPos);
    if (!Config.IEConfig.disableFancyBlueprints && !blueprintStack.isEmpty() && playerDistanceSq < 1000) {
        BlueprintCraftingRecipe[] recipes = BlueprintCraftingRecipe.findRecipes(ItemNBTHelper.getString(blueprintStack, "blueprint"));
        BlueprintCraftingRecipe recipe = (te.selectedRecipe < 0 || te.selectedRecipe >= recipes.length) ? null : recipes[te.selectedRecipe];
        BlueprintLines blueprint = recipe == null ? null : getBlueprintDrawable(recipe, te.getWorld());
        if (blueprint != null) {
            // Width depends on distance
            float lineWidth = playerDistanceSq < 6 ? 3 : playerDistanceSq < 25 ? 2 : playerDistanceSq < 40 ? 1 : .5f;
            GlStateManager.translate(-.195, .125, .97);
            GlStateManager.rotate(-45, 1, 0, 0);
            GlStateManager.disableCull();
            GlStateManager.disableTexture2D();
            GlStateManager.enableBlend();
            float scale = .0375f / (blueprint.textureScale / 16f);
            GlStateManager.scale(scale, -scale, scale);
            GlStateManager.color(1, 1, 1, 1);
            blueprint.draw(lineWidth);
            GlStateManager.scale(1 / scale, -1 / scale, 1 / scale);
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableCull();
        }
    }
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MultiblockProcess(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcess) EnumFacing(net.minecraft.util.EnumFacing) MultiblockProcessInWorld(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcessInWorld) BlueprintCraftingRecipe(blusunrize.immersiveengineering.api.crafting.BlueprintCraftingRecipe) IMultiblockRecipe(blusunrize.immersiveengineering.api.crafting.IMultiblockRecipe) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Example 85 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderMetalPress method render.

@Override
public void render(TileEntityMetalPress te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldRenderer = tessellator.getBuffer();
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    float piston = 0;
    float[] shift = new float[te.processQueue.size()];
    for (int i = 0; i < shift.length; i++) {
        MultiblockProcess process = te.processQueue.get(i);
        if (process == null)
            continue;
        float transportTime = 52.5f / 120f;
        float pressTime = 3.75f / 120f;
        float fProcess = (process.processTick + (te.shouldRenderAsActive() ? partialTicks : 0)) / (float) process.maxTicks;
        if (fProcess < transportTime)
            shift[i] = fProcess / transportTime * .5f;
        else if (fProcess < (1 - transportTime))
            shift[i] = .5f;
        else
            shift[i] = .5f + (fProcess - (1 - transportTime)) / transportTime * .5f;
        if (!te.mold.isEmpty())
            if (fProcess >= transportTime && fProcess < (1 - transportTime)) {
                if (fProcess < (transportTime + pressTime))
                    piston = (fProcess - transportTime) / pressTime;
                else if (fProcess < (1 - transportTime - pressTime))
                    piston = 1;
                else
                    piston = 1 - (fProcess - (1 - transportTime - pressTime)) / pressTime;
            }
    }
    GlStateManager.translate(0, -piston * .6875f, 0);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
    worldRenderer.color(255, 255, 255, 255);
    blockRenderer.getBlockModelRenderer().renderModel(te.getWorld(), model, state, blockPos, worldRenderer, true);
    worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
    tessellator.draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.rotate(te.facing == EnumFacing.SOUTH ? 180 : te.facing == EnumFacing.WEST ? 90 : te.facing == EnumFacing.EAST ? -90 : 0, 0, 1, 0);
    if (!te.mold.isEmpty()) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, .34, 0);
        GlStateManager.rotate(-90, 1, 0, 0);
        float scale = .75f;
        GlStateManager.scale(scale, scale, 1);
        ClientUtils.mc().getRenderItem().renderItem(te.mold, ItemCameraTransforms.TransformType.FIXED);
        GlStateManager.scale(1 / scale, 1 / scale, 1);
        GlStateManager.popMatrix();
    }
    GlStateManager.translate(0, piston * .6875f, 0);
    GlStateManager.translate(0, -.35, 1.25);
    for (int i = 0; i < shift.length; i++) {
        MultiblockProcess process = te.processQueue.get(i);
        if (process == null || !(process instanceof MultiblockProcessInWorld))
            continue;
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 0, -2.5 * shift[i]);
        if (piston > .92)
            GlStateManager.translate(0, .92 - piston, 0);
        List<ItemStack> displays = ((MultiblockProcessInWorld) process).getDisplayItem();
        if (!displays.isEmpty()) {
            GlStateManager.rotate(-90, 1, 0, 0);
            float scale = .625f;
            GlStateManager.scale(scale, scale, 1);
            ClientUtils.mc().getRenderItem().renderItem(displays.get(0), ItemCameraTransforms.TransformType.FIXED);
            GlStateManager.popMatrix();
        }
    }
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MultiblockProcess(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcess) MultiblockProcessInWorld(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcessInWorld) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)197 IBlockState (net.minecraft.block.state.IBlockState)94 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)42 BlockPos (net.minecraft.util.math.BlockPos)40 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)38 EnumFacing (net.minecraft.util.EnumFacing)38 ResourceLocation (net.minecraft.util.ResourceLocation)36 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 ItemStack (net.minecraft.item.ItemStack)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)24 Block (net.minecraft.block.Block)23 IModel (net.minecraftforge.client.model.IModel)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)22 ArrayList (java.util.ArrayList)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 Minecraft (net.minecraft.client.Minecraft)15 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)15 List (java.util.List)14 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)14 ImmutableList (com.google.common.collect.ImmutableList)13