Search in sources :

Example 1 with IOBJModelCallback

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

use of blusunrize.immersiveengineering.client.models.IOBJModelCallback in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    state = super.getExtendedState(state, world, pos);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extended = (IExtendedBlockState) state;
        TileEntity te = world.getTileEntity(pos);
        if (te != null) {
            if (te instanceof IConfigurableSides)
                for (int i = 0; i < 6; i++) if (extended.getUnlistedNames().contains(IEProperties.SIDECONFIG[i]))
                    extended = extended.withProperty(IEProperties.SIDECONFIG[i], ((IConfigurableSides) te).getSideConfig(i));
            if (te instanceof IAdvancedHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, ((IAdvancedHasObjProperty) te).getOBJState());
            else if (te instanceof IHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, new OBJState(((IHasObjProperty) te).compileDisplayList(), true));
            if (te instanceof IDynamicTexture)
                extended = extended.withProperty(IEProperties.OBJ_TEXTURE_REMAP, ((IDynamicTexture) te).getTextureReplacements());
            if (te instanceof IOBJModelCallback)
                extended = extended.withProperty(IOBJModelCallback.PROPERTY, (IOBJModelCallback) te);
            if (te.hasCapability(CapabilityShader.SHADER_CAPABILITY, null))
                extended = extended.withProperty(CapabilityShader.BLOCKSTATE_PROPERTY, te.getCapability(CapabilityShader.SHADER_CAPABILITY, null));
            if (te instanceof IPropertyPassthrough && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                extended = extended.withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te);
            if (te instanceof TileEntityImmersiveConnectable && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.CONNECTIONS))
                extended = extended.withProperty(IEProperties.CONNECTIONS, ((TileEntityImmersiveConnectable) te).genConnBlockstate());
        }
        state = extended;
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable) IDynamicTexture(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDynamicTexture) IPropertyPassthrough(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPropertyPassthrough) IOBJModelCallback(blusunrize.immersiveengineering.client.models.IOBJModelCallback) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IAdvancedHasObjProperty(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedHasObjProperty) IHasObjProperty(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasObjProperty) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 3 with IOBJModelCallback

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

the class BlockIETileProvider method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    state = super.getExtendedState(state, world, pos);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extended = (IExtendedBlockState) state;
        TileEntity te = world.getTileEntity(pos);
        if (te != null) {
            if (te instanceof IConfigurableSides)
                for (int i = 0; i < 6; i++) if (extended.getUnlistedNames().contains(IEProperties.SIDECONFIG[i]))
                    extended = extended.withProperty(IEProperties.SIDECONFIG[i], ((IConfigurableSides) te).getSideConfig(i));
            if (te instanceof IAdvancedHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, ((IAdvancedHasObjProperty) te).getOBJState());
            else if (te instanceof IHasObjProperty)
                extended = extended.withProperty(Properties.AnimationProperty, new OBJState(((IHasObjProperty) te).compileDisplayList(), true));
            if (te instanceof IDynamicTexture)
                extended = extended.withProperty(IEProperties.OBJ_TEXTURE_REMAP, ((IDynamicTexture) te).getTextureReplacements());
            if (te instanceof IOBJModelCallback)
                extended = extended.withProperty(IOBJModelCallback.PROPERTY, (IOBJModelCallback) te);
            if (te.hasCapability(CapabilityShader.SHADER_CAPABILITY, null))
                extended = extended.withProperty(CapabilityShader.BLOCKSTATE_PROPERTY, te.getCapability(CapabilityShader.SHADER_CAPABILITY, null));
            if (te instanceof IPropertyPassthrough && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                extended = extended.withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te);
            if (te instanceof TileEntityImmersiveConnectable && ((IExtendedBlockState) state).getUnlistedNames().contains(IEProperties.CONNECTIONS))
                extended = extended.withProperty(IEProperties.CONNECTIONS, ((TileEntityImmersiveConnectable) te).genConnBlockstate());
        }
        state = extended;
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable) IOBJModelCallback(blusunrize.immersiveengineering.client.models.IOBJModelCallback) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Aggregations

IOBJModelCallback (blusunrize.immersiveengineering.client.models.IOBJModelCallback)3 TileEntityImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable)2 TileEntity (net.minecraft.tileentity.TileEntity)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 IESmartObjModel (blusunrize.immersiveengineering.client.models.IESmartObjModel)1 IAdvancedHasObjProperty (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedHasObjProperty)1 IConfigurableSides (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides)1 IDynamicTexture (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDynamicTexture)1 IHasObjProperty (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasObjProperty)1 IPropertyPassthrough (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPropertyPassthrough)1 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)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