Search in sources :

Example 1 with RequirementItemStack

use of buildcraft.core.blueprints.RequirementItemStack in project BuildCraft by BuildCraft.

the class GuiBuilder method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
    // We cannot do super here due to some crazy shenanigans with a dynamically
    // resized GUI.
    GlStateManager.color(1f, 1f, 1f, 1f);
    boolean isBlueprint = builder.getStackInSlot(0) != null;
    mc.renderEngine.bindTexture(REGULAR_TEXTURE);
    drawTexturedModalRect(guiLeft, guiTop, 0, 0, 176, ySize);
    mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE);
    if (isBlueprint) {
        drawTexturedModalRect(guiLeft + 169, guiTop, 169, 0, 256 - 169, ySize);
    }
    List<RequirementItemStack> needs = builder.getNeededItems();
    if (needs != null) {
        if (needs.size() > slots.size()) {
            getContainerBuilder().scrollbarWidget.hidden = false;
            getContainerBuilder().scrollbarWidget.setLength((needs.size() - slots.size() + 3) / 4);
        } else {
            getContainerBuilder().scrollbarWidget.hidden = true;
        }
        int offset = getContainerBuilder().scrollbarWidget.getPosition() * 4;
        for (int s = 0; s < slots.size(); s++) {
            int ts = offset + s;
            if (ts >= needs.size()) {
                ((SlotBuilderRequirement) slots.get(s)).stack = null;
            } else {
                ((SlotBuilderRequirement) slots.get(s)).stack = needs.get(ts);
            }
        }
        for (GuiButton b : (List<GuiButton>) buttonList) {
            b.visible = true;
        }
    } else {
        getContainerBuilder().scrollbarWidget.hidden = true;
        for (AdvancedSlot slot : slots) {
            ((SlotBuilderRequirement) slot).stack = null;
        }
        for (GuiButton b : (List<GuiButton>) buttonList) {
            b.visible = false;
        }
    }
    if (builder.getControlMode() == Mode.Off) {
        Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
        int extraX = guiLeft + OPTION_EXTRA_X_POS.getAsInt();
        int extraY = guiTop + OPTION_EXTRA_Y_POS.getAsInt();
        drawTexturedModalRect(extraX, extraY, CoreIconProvider.TURNED_OFF.getSprite(), 16, 16);
    }
    drawWidgets(x, y);
    if (isBlueprint) {
        drawBackgroundSlots(x, y);
        for (int i = 0; i < builder.fluidTanks.length; i++) {
            Tank tank = builder.fluidTanks[i];
            if (tank.getFluid() != null && tank.getFluid().amount > 0) {
                drawFluid(tank.getFluid(), guiLeft + 179 + 18 * i, guiTop + 145, 16, 47, tank.getCapacity());
            }
        }
        mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE);
        for (int i = 0; i < builder.fluidTanks.length; i++) {
            Tank tank = builder.fluidTanks[i];
            if (tank.getFluid() != null && tank.getFluid().amount > 0) {
                drawTexturedModalRect(guiLeft + 179 + 18 * i, guiTop + 145, 0, 54, 16, 47);
            }
        }
    }
    GlStateManager.color(1f, 1f, 1f, 1f);
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) RequirementItemStack(buildcraft.core.blueprints.RequirementItemStack) ArrayList(java.util.ArrayList) List(java.util.List) Tank(buildcraft.lib.fluids.Tank)

Example 2 with RequirementItemStack

use of buildcraft.core.blueprints.RequirementItemStack in project BuildCraft by BuildCraft.

the class TileBuilder method updateRequirements.

private void updateRequirements() {
    List<RequirementItemStack> reqCopy = null;
    if (currentBuilder instanceof BptBuilderBlueprint) {
        currentBuilder.initialize();
        reqCopy = ((BptBuilderBlueprint) currentBuilder).getNeededItems();
    }
    for (EntityPlayer p : guiWatchers) {
        BuildCraftCore.instance.sendToPlayer(p, getItemRequirementsPacket(reqCopy));
    }
}
Also used : RequirementItemStack(buildcraft.core.blueprints.RequirementItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint)

Example 3 with RequirementItemStack

use of buildcraft.core.blueprints.RequirementItemStack in project BuildCraft by BuildCraft.

the class BuilderTooltipHandler method itemTooltipEvent.

@SubscribeEvent
public void itemTooltipEvent(ItemTooltipEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    if (event.getItemStack() != null && player != null && player.openContainer != null && player.openContainer instanceof ContainerBuilder) {
        ContainerBuilder containerBuilder = (ContainerBuilder) player.openContainer;
        TileBuilder builder = containerBuilder.getBuilder();
        if (builder != null) {
            List<RequirementItemStack> needs = builder.getNeededItems();
            if (needs != null) {
                for (RequirementItemStack ris : needs) {
                    if (ris.stack == event.getItemStack()) {
                        event.getToolTip().add(TextFormatting.GRAY + "" + TextFormatting.ITALIC + "Needed: " + ris.size);
                    }
                }
            }
        }
    }
}
Also used : ContainerBuilder(buildcraft.builders.gui.ContainerBuilder) RequirementItemStack(buildcraft.core.blueprints.RequirementItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with RequirementItemStack

use of buildcraft.core.blueprints.RequirementItemStack in project BuildCraft by BuildCraft.

the class TileBuilder method getItemRequirementsPacket.

private Packet getItemRequirementsPacket(List<RequirementItemStack> itemsIn) {
    if (itemsIn != null) {
        final List<RequirementItemStack> items = new ArrayList<>();
        items.addAll(itemsIn);
        return new PacketCommand(this, "setItemRequirements", new CommandWriter() {

            @Override
            public void write(ByteBuf data) {
                data.writeMedium(items.size());
                for (RequirementItemStack rb : items) {
                    data.writeShort(Item.getIdFromItem(rb.stack.getItem()));
                    data.writeShort(rb.stack.getItemDamage());
                    data.writeMedium((rb.stack.hasTagCompound() ? 0x800000 : 0x000000) | Math.min(0x7FFFFF, rb.size));
                    if (rb.stack.hasTagCompound()) {
                        NetworkUtils.writeNBT(data, rb.stack.getTagCompound());
                    }
                }
            }
        });
    } else {
        return new PacketCommand(this, "clearItemRequirements", null);
    }
}
Also used : RequirementItemStack(buildcraft.core.blueprints.RequirementItemStack) ArrayList(java.util.ArrayList) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

RequirementItemStack (buildcraft.core.blueprints.RequirementItemStack)4 ArrayList (java.util.ArrayList)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ContainerBuilder (buildcraft.builders.gui.ContainerBuilder)1 BptBuilderBlueprint (buildcraft.core.blueprints.BptBuilderBlueprint)1 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)1 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)1 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)1 Tank (buildcraft.lib.fluids.Tank)1 ByteBuf (io.netty.buffer.ByteBuf)1 List (java.util.List)1 GuiButton (net.minecraft.client.gui.GuiButton)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1