Search in sources :

Example 6 with ShaderWrapper

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

the class ContainerModWorkbench method rebindSlots.

public void rebindSlots() {
    this.inventorySlots.clear();
    this.addSlotToContainer(new IESlot.UpgradeableItem(this, this.inv, 0, 24, 22, 1));
    slotCount = 1;
    ItemStack tool = this.getSlot(0).getStack();
    if (tool != null) {
        if (tool.getItem() instanceof IUpgradeableTool) {
            if (tool.getItem() instanceof ItemEngineersBlueprint)
                ((ItemEngineersBlueprint) tool.getItem()).updateOutputs(tool);
            this.toolInv = new InventoryStorageItem(this, tool);
            Slot[] slots = ((IUpgradeableTool) tool.getItem()).getWorkbenchSlots(this, tool, toolInv);
            if (slots != null)
                for (Slot s : slots) {
                    this.addSlotToContainer(s);
                    slotCount++;
                }
            ItemStack[] cont = ((IUpgradeableTool) tool.getItem()).getContainedItems(tool);
            this.toolInv.stackList = cont;
        }
        if (tool.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
            ShaderWrapper wrapper = tool.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
            if (wrapper != null) {
                this.shaderInv = new InventoryShader(this, wrapper);
                this.addSlotToContainer(new IESlot.Shader(this, shaderInv, 0, 130, 32, tool));
                slotCount++;
                this.shaderInv.shader = wrapper.getShaderItem();
            }
        }
    }
    bindPlayerInv(inventoryPlayer);
    ImmersiveEngineering.proxy.reInitGui();
}
Also used : ItemEngineersBlueprint(blusunrize.immersiveengineering.common.items.ItemEngineersBlueprint) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) IUpgradeableTool(blusunrize.immersiveengineering.api.tool.IUpgradeableTool) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ShaderWrapper

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

the class ManualPageShader method initPage.

@Override
public void initPage(GuiManual gui, int x, int y, List<GuiButton> pageButtons) {
    EntityPlayer player = ManualUtils.mc().thePlayer;
    String username = player.getName();
    unlocked = ShaderRegistry.receivedShaders.get(username).contains(shader.getName());
    shaderItem = new ItemStack(ShaderRegistry.itemShader);
    shaderItem.setTagCompound(new NBTTagCompound());
    shaderItem.getTagCompound().setString("shader_name", shader.getName());
    replicationCost = shader.replicationCost;
    if (unlocked) {
        ArrayList<ItemStack> list = new ArrayList<ItemStack>();
        for (ItemStack is : ShaderRegistry.itemExamples) if (is != null && is.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
            ItemStack s = is.copy();
            ShaderWrapper wrapper = s.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
            if (wrapper != null) {
                wrapper.setShaderItem(shaderItem);
                list.add(s);
            }
        }
        exampleItems = list.toArray(new ItemStack[list.size()]);
        example = 0;
        if (exampleItems.length > 1) {
            pageButtons.add(new GuiButtonManualNavigation(gui, 100, x + 50, y, 10, 16, 0));
            pageButtons.add(new GuiButtonManualNavigation(gui, 101, x + 100, y, 10, 16, 1));
        }
    } else
        exampleItems = null;
    this.text = "§lRarity: §r" + " " + shader.rarity.rarityName;
    if (unlocked) {
        String set = shader.info_set == null || shader.info_set.isEmpty() ? null : ManualUtils.attemptStringTranslation(Lib.DESC_INFO + "shader.set.%s", shader.info_set);
        String reference = shader.info_reference == null || shader.info_reference.isEmpty() ? null : ManualUtils.attemptStringTranslation(Lib.DESC_INFO + "shader.reference.%s", shader.info_reference);
        String details = shader.info_details == null || shader.info_details.isEmpty() ? null : ManualUtils.attemptStringTranslation(Lib.DESC_INFO + "shader.details.%s", shader.info_details);
        if (set != null)
            this.text += "<br><br>" + I18n.format("desc.immersiveengineering.info.shader.set") + " " + set;
        if (reference != null)
            this.text += "<br><br>" + I18n.format("desc.immersiveengineering.info.shader.reference") + "<br>" + reference;
        if (details != null)
            this.text += "<br><br>" + I18n.format("desc.immersiveengineering.info.shader.details") + "<br>" + details;
        String cost = Integer.toString(replicationCost.inputSize);
        if (!ApiUtils.hasPlayerIngredient(gui.mc.thePlayer, replicationCost) && !gui.mc.thePlayer.capabilities.isCreativeMode)
            cost = TextFormatting.RED + cost;
        pageButtons.add(new GuiButtonManual(gui, 102, x + 50, y + 138, 70, 12, TextFormatting.BOLD + I18n.format("ie.manual.entry.shaderList.order") + " " + cost + "x   ").setTextColour(gui.getManual().getTextColour(), gui.getManual().getHighlightColour()));
    } else {
        this.text += "<br><br>" + I18n.format("ie.manual.entry.shaderList.noInfo");
        if (player.capabilities.isCreativeMode)
            pageButtons.add(new GuiButtonManual(gui, 103, x + 10, y + 80, 100, 16, I18n.format("ie.manual.entry.shaderList.unlock")).setTextColour(gui.getManual().getTextColour(), gui.getManual().getHighlightColour()));
    }
    super.initPage(gui, x, y, pageButtons);
}
Also used : GuiButtonManual(blusunrize.lib.manual.gui.GuiButtonManual) GuiButtonManualNavigation(blusunrize.lib.manual.gui.GuiButtonManualNavigation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ShaderWrapper

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

the class IESmartObjModel method buildQuads.

private ImmutableList<BakedQuad> buildQuads() {
    List<BakedQuad> quads = Lists.newArrayList();
    ItemStack shader = null;
    ShaderCase sCase = null;
    IOBJModelCallback callback = null;
    Object callbackObject = null;
    if (this.tempStack != null && tempStack.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
        ShaderWrapper wrapper = tempStack.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
        shader = wrapper.getShaderItem();
        if (shader != null && 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);
        shader = wrapper.getShaderItem();
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, wrapper.getShaderType());
    }
    if (this.tempStack != null && 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;
    }
    int maxPasses = 1;
    if (sCase != null)
        maxPasses = sCase.getLayers().length;
    for (int pass = 0; pass < maxPasses; pass++) {
        ShaderLayer shaderLayer = sCase != null ? sCase.getLayers()[pass] : null;
        for (Group g : getModel().getMatLib().getGroups().values()) {
            if (callback != null)
                if (!callback.shouldRenderGroup(callbackObject, g.getName()))
                    continue;
            if (sCase != null)
                if (!sCase.renderModelPartForPass(shader, tempStack, g.getName(), pass))
                    continue;
            Set<Face> faces = Collections.synchronizedSet(new LinkedHashSet<Face>());
            Optional<TRSRTransformation> transform = Optional.absent();
            if (this.getState() instanceof OBJState) {
                OBJState state = (OBJState) this.getState();
                if (state.parent != null)
                    transform = state.parent.apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                if (state.getGroupsWithVisibility(true).contains(g.getName()))
                    faces.addAll(g.applyTransform(transform));
            } else {
                transform = getState().apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                faces.addAll(g.applyTransform(transform));
            }
            int argb = 0xffffffff;
            if (sCase != null)
                argb = sCase.getARGBColourModifier(shader, tempStack, g.getName(), pass);
            else if (callback != null)
                argb = callback.getRenderColour(callbackObject, g.getName());
            float[] colour = { (argb >> 16 & 255) / 255f, (argb >> 8 & 255) / 255f, (argb & 255) / 255f, (argb >> 24 & 255) / 255f };
            for (Face f : faces) {
                tempSprite = null;
                if (this.getModel().getMatLib().getMaterial(f.getMaterialName()).isWhite() && !"null".equals(f.getMaterialName())) {
                    for (Vertex v : f.getVertices()) if (!v.getMaterial().equals(this.getModel().getMatLib().getMaterial(v.getMaterial().getName())))
                        v.setMaterial(this.getModel().getMatLib().getMaterial(v.getMaterial().getName()));
                    tempSprite = ModelLoader.White.INSTANCE;
                } else {
                    if (sCase != null) {
                        ResourceLocation rl = sCase.getReplacementSprite(shader, tempStack, g.getName(), pass);
                        if (rl != null)
                            tempSprite = ClientUtils.getSprite(rl);
                    }
                    if (tempSprite == null && callback != null)
                        tempSprite = callback.getTextureReplacement(callbackObject, f.getMaterialName());
                    if (tempSprite == null && tempState != null && texReplace != null) {
                        String s = texReplace.get(g.getName());
                        if (s != null)
                            tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(s);
                    }
                    if (tempSprite == null && !"null".equals(f.getMaterialName()))
                        tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(this.getModel().getMatLib().getMaterial(f.getMaterialName()).getTexture().getTextureLocation().toString());
                }
                if (tempSprite != null) {
                    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(getFormat());
                    builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
                    builder.setTexture(tempSprite);
                    builder.setQuadTint(pass);
                    Normal faceNormal = f.getNormal();
                    TextureCoordinate[] uvs = new TextureCoordinate[4];
                    boolean renderFace = true;
                    for (int i = 0; i < 4; i++) {
                        Vertex vertex = f.getVertices()[i];
                        //V-Flip is processed here already, rather than in the later method, since it's needed for easy UV comparissons on the Shader Layers
                        uvs[i] = vertex.hasTextureCoordinate() ? new TextureCoordinate(vertex.getTextureCoordinate().u, 1 - vertex.getTextureCoordinate().v, vertex.getTextureCoordinate().w) : TextureCoordinate.getDefaultUVs()[i];
                        if (shaderLayer != null) {
                            double[] texBounds = shaderLayer.getTextureBounds();
                            if (texBounds != null) {
                                if (//if any uvs are outside the layers bounds
                                texBounds[0] > uvs[i].u || uvs[i].u > texBounds[2] || texBounds[1] > uvs[i].v || uvs[i].v > texBounds[3]) {
                                    renderFace = false;
                                    break;
                                }
                                double dU = texBounds[2] - texBounds[0];
                                double dV = texBounds[3] - texBounds[1];
                                //Rescaling to the partial bounds that the texture represents
                                uvs[i].u = (float) ((uvs[i].u - texBounds[0]) / dU);
                                uvs[i].v = (float) ((uvs[i].v - texBounds[1]) / dV);
                            }
                            //Rescaling to the selective area of the texture that is used
                            double[] cutBounds = shaderLayer.getCutoutBounds();
                            if (cutBounds != null) {
                                double dU = cutBounds[2] - cutBounds[0];
                                double dV = cutBounds[3] - cutBounds[1];
                                uvs[i].u = (float) (cutBounds[0] + dU * uvs[i].u);
                                uvs[i].v = (float) (cutBounds[1] + dV * uvs[i].v);
                            }
                        }
                    }
                    if (renderFace) {
                        for (int i = 0; i < 4; i++) putVertexData(builder, f.getVertices()[i], faceNormal, uvs[i], tempSprite, colour);
                        quads.add(builder.build());
                    }
                }
            }
        }
    }
    if (callback != null)
        quads = callback.modifyQuads(callbackObject, quads);
    return ImmutableList.copyOf(quads);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) ResourceLocation(net.minecraft.util.ResourceLocation) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ItemStack(net.minecraft.item.ItemStack) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack)

Aggregations

ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)8 ItemStack (net.minecraft.item.ItemStack)4 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)1 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)1 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)1 IUpgradeableTool (blusunrize.immersiveengineering.api.tool.IUpgradeableTool)1 GuiBlastFurnace (blusunrize.immersiveengineering.client.gui.GuiBlastFurnace)1 ItemEngineersBlueprint (blusunrize.immersiveengineering.common.items.ItemEngineersBlueprint)1 GuiButtonManual (blusunrize.lib.manual.gui.GuiButtonManual)1 GuiButtonManualNavigation (blusunrize.lib.manual.gui.GuiButtonManualNavigation)1 ArrayList (java.util.ArrayList)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Slot (net.minecraft.inventory.Slot)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1