Search in sources :

Example 1 with IShaderItem

use of blusunrize.immersiveengineering.api.shader.IShaderItem 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 IShaderItem

use of blusunrize.immersiveengineering.api.shader.IShaderItem in project ImmersiveEngineering by BluSunrize.

the class ModelShaderMinecart method render.

@Override
public void render(Entity entity, float f0, float f1, float f2, float f3, float f4, float f5) {
    ShaderCase sCase = null;
    ItemStack shader = ItemStack.EMPTY;
    if (shadedCarts.containsKey(entity.getEntityId())) {
        shader = shadedCarts.get(entity.getEntityId());
        if (shader != null && !shader.isEmpty() && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, "immersiveengineering:minecart");
    }
    if (sCase != null) {
        GlStateManager.enableBlend();
        OpenGlHelper.glBlendFunc(770, 771, 0, 1);
        sideModels[5].rotationPointY = 4.0F - f2;
        sideModelsMirrored[5].rotationPointY = 4.0F - f2;
        for (int part = 0; part < sideModels.length - 1; part++) if (sideModels[part] != null) {
            float scale = 1;
            ShaderLayer[] layers = sCase.getLayers();
            for (int pass = 0; pass < layers.length; pass++) if (sCase.renderModelPartForPass(shader, null, "" + part, pass)) {
                int col = sCase.getARGBColourModifier(shader, null, "" + part, pass);
                boolean upScale = pass != layers.length - 2;
                GlStateManager.scale(scale, scale, scale);
                GlStateManager.color((col >> 16 & 255) / 255f, (col >> 8 & 255) / 255f, (col & 255) / 255f, (col >> 24 & 255) / 255f);
                // if(pass==maxPasses-1)
                // ClientUtils.bindTexture("immersiveengineering:textures/models/shaders/minecart_uncoloured.png");
                // else if(pass==maxPasses-2 && ((ShaderCaseMinecart)sCase).additionalTexture!=null)
                // ClientUtils.bindTexture(sCase.getBaseTexturePath()+((ShaderCaseMinecart)sCase).additionalTexture+".png");
                // else if(pass==0)
                // ClientUtils.bindTexture("immersiveengineering:textures/models/shaders/minecart_0.png");
                // else
                // {
                // ClientUtils.bindTexture(sCase.getBaseTexturePath()+"1_"+sCase.getOverlayType()+".png");
                // upScale = false;
                // }
                ClientUtils.mc().getTextureManager().bindTexture(sCase.getReplacementSprite(shader, null, "" + part, pass));
                if (layers[pass].isDynamicLayer())
                    layers[pass].modifyRender(true, part);
                if (((ShaderCaseMinecart) sCase).mirrorSideForPass[pass])
                    sideModelsMirrored[part].render(f5);
                else
                    sideModels[part].render(f5);
                if (layers[pass].isDynamicLayer())
                    layers[pass].modifyRender(false, part);
                GlStateManager.color(1, 1, 1, 1);
                GlStateManager.scale(1 / scale, 1 / scale, 1 / scale);
            // if(upScale)
            // scale += .001f;
            }
        }
        GlStateManager.disableBlend();
    } else
        super.render(entity, f0, f1, f2, f3, f4, f5);
}
Also used : IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IShaderItem

use of blusunrize.immersiveengineering.api.shader.IShaderItem in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method buildQuads.

private ImmutableList<BakedQuad> buildQuads() {
    List<BakedQuad> quads = Lists.newArrayList();
    ItemStack shader = ItemStack.EMPTY;
    ShaderCase sCase = null;
    IOBJModelCallback callback = null;
    Object callbackObject = null;
    if (!this.tempStack.isEmpty() && tempStack.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
        ShaderWrapper wrapper = tempStack.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
        if (wrapper != null) {
            shader = wrapper.getShaderItem();
            if (!shader.isEmpty() && shader.getItem() instanceof IShaderItem)
                sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, tempStack, wrapper.getShaderType());
        }
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(CapabilityShader.BLOCKSTATE_PROPERTY)) {
        ShaderWrapper wrapper = ((IExtendedBlockState) this.tempState).getValue(CapabilityShader.BLOCKSTATE_PROPERTY);
        if (wrapper != null) {
            shader = wrapper.getShaderItem();
            if (!shader.isEmpty() && shader.getItem() instanceof IShaderItem)
                sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, wrapper.getShaderType());
        }
    }
    if (!this.tempStack.isEmpty() && tempStack.getItem() instanceof IOBJModelCallback) {
        callback = (IOBJModelCallback) tempStack.getItem();
        callbackObject = this.tempStack;
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(IOBJModelCallback.PROPERTY)) {
        callback = ((IExtendedBlockState) this.tempState).getValue(IOBJModelCallback.PROPERTY);
        callbackObject = this.tempState;
    }
    for (String groupName : getModel().getMatLib().getGroups().keySet()) {
        List<Pair<BakedQuad, ShaderLayer>> temp = addQuadsForGroup(callback, callbackObject, groupName, sCase, shader);
        quads.addAll(temp.stream().filter(Objects::nonNull).map(Pair::getKey).collect(Collectors.toList()));
    }
    if (callback != null)
        quads = callback.modifyQuads(callbackObject, quads);
    return ImmutableList.copyOf(quads);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) ItemStack(net.minecraft.item.ItemStack) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 4 with IShaderItem

use of blusunrize.immersiveengineering.api.shader.IShaderItem in project ImmersiveEngineering by BluSunrize.

the class TileRenderShaderBanner method getBannerResourceLocation.

@Nullable
private ResourceLocation getBannerResourceLocation(TileEntityShaderBanner bannerObj) {
    String name = null;
    ShaderCase sCase = null;
    ItemStack shader = bannerObj.shader.getShaderItem();
    if (!shader.isEmpty() && shader.getItem() instanceof IShaderItem) {
        IShaderItem iShaderItem = ((IShaderItem) shader.getItem());
        name = iShaderItem.getShaderName(shader);
        if (CACHE.containsKey(name))
            return CACHE.get(name);
        sCase = iShaderItem.getShaderCase(shader, null, bannerObj.shader.getShaderType());
    }
    if (sCase != null) {
        ShaderLayer[] layers = sCase.getLayers();
        ResourceLocation textureLocation = new ResourceLocation("immersiveengineering", "bannershader/" + name);
        ClientUtils.mc().getTextureManager().loadTexture(textureLocation, new IEShaderLayerCompositeTexture(BASE_TEXTURE, layers));
        CACHE.put(name, textureLocation);
        return textureLocation;
    }
    return null;
}
Also used : IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) ResourceLocation(net.minecraft.util.ResourceLocation) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)4 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)4 ItemStack (net.minecraft.item.ItemStack)4 Pair (org.apache.commons.lang3.tuple.Pair)2 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 CapabilityShader (blusunrize.immersiveengineering.api.shader.CapabilityShader)1 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)1 IESmartObjModel (blusunrize.immersiveengineering.client.models.IESmartObjModel)1 IOBJModelCallback (blusunrize.immersiveengineering.client.models.IOBJModelCallback)1 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 Nullable (javax.annotation.Nullable)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ItemCameraTransforms (net.minecraft.client.renderer.block.model.ItemCameraTransforms)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 World (net.minecraft.world.World)1 OBJModel (net.minecraftforge.client.model.obj.OBJModel)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1