Search in sources :

Example 1 with IESmartObjModel

use of blusunrize.immersiveengineering.client.models.IESmartObjModel in project ImmersiveEngineering by BluSunrize.

the class TileRenderBucketWheel method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
    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);
        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.length; i++) if (tile.digStacks[i] != null) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
                IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.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 * f : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer 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.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    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 2 with IESmartObjModel

use of blusunrize.immersiveengineering.client.models.IESmartObjModel 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 3 with IESmartObjModel

use of blusunrize.immersiveengineering.client.models.IESmartObjModel 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)

Aggregations

IESmartObjModel (blusunrize.immersiveengineering.client.models.IESmartObjModel)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 EnumFacing (net.minecraft.util.EnumFacing)2 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)2 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)2 CapabilityShader (blusunrize.immersiveengineering.api.shader.CapabilityShader)1 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)1 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)1 IOBJModelCallback (blusunrize.immersiveengineering.client.models.IOBJModelCallback)1 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 ItemCameraTransforms (net.minecraft.client.renderer.block.model.ItemCameraTransforms)1 ItemStack (net.minecraft.item.ItemStack)1 World (net.minecraft.world.World)1 OBJModel (net.minecraftforge.client.model.obj.OBJModel)1 Pair (org.apache.commons.lang3.tuple.Pair)1