Search in sources :

Example 1 with IMachine

use of binnie.core.machines.IMachine in project Binnie by ForestryMC.

the class ComponentInventory method markDirty.

@Override
public void markDirty() {
    IMachine machine = this.getMachine();
    machine.markDirty();
}
Also used : IMachine(binnie.core.machines.IMachine)

Example 2 with IMachine

use of binnie.core.machines.IMachine in project Binnie by ForestryMC.

the class PackageInoculator method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ComponentGeneticGUI(machine, GeneticsGUI.INOCULATOR);
    final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    InventorySlot slotSerumVial = inventory.addSlot(Inoculator.SLOT_SERUM_VIAL, getSlotRL("serum.active"));
    slotSerumVial.forbidInteraction();
    slotSerumVial.setReadOnly();
    final SlotValidator serumValid = new SerumSlotValidator();
    slotSerumVial.setValidator(serumValid);
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_SERUM_RESERVE, getSlotRL("serum.input"))) {
        slot.setValidator(serumValid);
        slot.forbidExtraction();
    }
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_SERUM_EXPENDED, getSlotRL("serum.output"))) {
        slot.setValidator(serumValid);
        slot.setReadOnly();
    }
    for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_RESERVE, getSlotRL("input"))) {
        slot.forbidExtraction();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    InventorySlot slotTarget = inventory.addSlot(Inoculator.SLOT_TARGET, getSlotRL("process"));
    slotTarget.setValidator(new ValidatorIndividualInoculate());
    slotTarget.setReadOnly();
    slotTarget.forbidInteraction();
    for (final InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_FINISHED, getSlotRL("output"))) {
        slot.setReadOnly();
        slot.forbidInsertion();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
    transfer.addRestock(Inoculator.SLOT_RESERVE, 9, 1);
    transfer.addRestock(Inoculator.SLOT_SERUM_RESERVE, 0);
    transfer.addStorage(Inoculator.SLOT_SERUM_VIAL, Inoculator.SLOT_SERUM_EXPENDED, (stack) -> Engineering.getCharges(stack) == 0);
    transfer.addStorage(Inoculator.SLOT_TARGET, Inoculator.SLOT_FINISHED, (stack) -> {
        if (!stack.isEmpty()) {
            IMachine machine1 = transfer.getMachine();
            MachineUtil machineUtil = machine1.getMachineUtil();
            if (!machineUtil.getStack(Inoculator.SLOT_SERUM_VIAL).isEmpty() && machine1.getInterface(InoculatorLogic.class).isValidSerum() != null) {
                return true;
            }
        }
        return false;
    });
    new ComponentPowerReceptor(machine, 15000);
    new InoculatorLogic(machine);
    new InoculatorFX(machine);
    new ComponentTankContainer(machine).addTank(Inoculator.TANK_VEKTOR, "input", 1000).setValidator(new BacteriaVectorTankValidator());
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IMachine(binnie.core.machines.IMachine) ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) ComponentGeneticGUI(binnie.genetics.machine.ComponentGeneticGUI) ComponentInventoryTransfer(binnie.core.machines.inventory.ComponentInventoryTransfer) ComponentTankContainer(binnie.core.machines.inventory.ComponentTankContainer) SlotValidator(binnie.core.machines.inventory.SlotValidator) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 3 with IMachine

use of binnie.core.machines.IMachine in project Binnie by ForestryMC.

the class ControlSequencerProgress method onUpdateClient.

@Override
public void onUpdateClient() {
    super.onUpdateClient();
    IMachine machine = Machine.getMachine(Window.get(this).getInventory());
    MachineUtil machineUtil = machine.getMachineUtil();
    ItemStack stackTarget = machineUtil.getStack(Sequencer.SLOT_TARGET);
    if (stackTarget.isEmpty()) {
        this.textControl.setValue("");
    } else {
        Random rand = new Random(stackTarget.getDisplayName().length());
        StringBuilder text = new StringBuilder();
        for (int i = 0; i < 65; ++i) {
            int k = rand.nextInt(4);
            String code = CODES[k];
            if (rand.nextFloat() < this.progress) {
                text.append(TextFormatting.RESET).append(COLORS[k]).append(TextFormatting.BOLD).append(code);
            } else {
                text.append(TextFormatting.RESET).append(TextFormatting.GRAY).append(TextFormatting.OBFUSCATED).append(TextFormatting.BOLD).append(code);
            }
        }
        this.textControl.setValue(text.toString());
    }
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IMachine(binnie.core.machines.IMachine) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IMachine

use of binnie.core.machines.IMachine in project Binnie by ForestryMC.

the class PackageSplicer method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ComponentGeneticGUI(machine, GeneticsGUI.SPLICER);
    final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    InventorySlot slotSerumVial = inventory.addSlot(Splicer.SLOT_SERUM_VIAL, getSlotRL("serum.active"));
    slotSerumVial.forbidInteraction();
    slotSerumVial.setReadOnly();
    final SlotValidator serumValid = new SerumSlotValidator();
    slotSerumVial.setValidator(serumValid);
    for (InventorySlot slot : inventory.addSlotArray(Splicer.SLOT_SERUM_RESERVE, getSlotRL("serum.input"))) {
        slot.setValidator(serumValid);
        slot.forbidExtraction();
    }
    for (InventorySlot slot : inventory.addSlotArray(Splicer.SLOT_SERUM_EXPENDED, getSlotRL("serum.output"))) {
        slot.setValidator(serumValid);
        slot.setReadOnly();
    }
    for (InventorySlot slot : inventory.addSlotArray(Splicer.SLOT_RESERVE, getSlotRL("input"))) {
        slot.forbidExtraction();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    InventorySlot slotTarget = inventory.addSlot(Splicer.SLOT_TARGET, getSlotRL("process"));
    slotTarget.setValidator(new ValidatorIndividualInoculate());
    slotTarget.setReadOnly();
    slotTarget.forbidInteraction();
    for (InventorySlot slot : inventory.addSlotArray(Splicer.SLOT_FINISHED, getSlotRL("output"))) {
        slot.setReadOnly();
        slot.forbidInsertion();
        slot.setValidator(new ValidatorIndividualInoculate());
    }
    final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
    transfer.addRestock(Splicer.SLOT_RESERVE, Splicer.SLOT_TARGET, 1);
    transfer.addRestock(Splicer.SLOT_SERUM_RESERVE, Splicer.SLOT_SERUM_VIAL);
    transfer.addStorage(Splicer.SLOT_SERUM_VIAL, Splicer.SLOT_SERUM_EXPENDED, (stack) -> Engineering.getCharges(stack) == 0);
    transfer.addStorage(Splicer.SLOT_TARGET, Splicer.SLOT_FINISHED, (stack) -> {
        if (!stack.isEmpty()) {
            IMachine machine1 = transfer.getMachine();
            MachineUtil machineUtil = machine1.getMachineUtil();
            if (!machineUtil.getStack(Splicer.SLOT_SERUM_VIAL).isEmpty() && machine1.getInterface(SplicerLogic.class).isValidSerum() != null) {
                return true;
            }
        }
        return false;
    });
    new ComponentPowerReceptor(machine, 20000);
    new SplicerLogic(machine);
    new SplicerFX(machine);
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IMachine(binnie.core.machines.IMachine) ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) SlotValidator(binnie.core.machines.inventory.SlotValidator) ComponentGeneticGUI(binnie.genetics.machine.ComponentGeneticGUI) ComponentInventoryTransfer(binnie.core.machines.inventory.ComponentInventoryTransfer) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 5 with IMachine

use of binnie.core.machines.IMachine in project Binnie by ForestryMC.

the class WindowCompartment method initialiseClient.

// TODO: Clean Up, Localise
@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    IInventory inventory = this.getInventory();
    IMachine machine = Machine.getMachine(inventory);
    MachinePackage machinePackage = machine.getPackage();
    this.setTitle(machinePackage.getDisplayName());
    int x = 16;
    final int y = 32;
    final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class);
    Integer[] tabs1 = new Integer[0];
    Integer[] tabs2 = new Integer[0];
    if (inv.getTabCount() == 4) {
        tabs1 = new Integer[] { 0, 1 };
        tabs2 = new Integer[] { 2, 3 };
    }
    if (inv.getTabCount() == 6) {
        tabs1 = new Integer[] { 0, 1, 2 };
        tabs2 = new Integer[] { 3, 4, 5 };
    }
    if (inv.getTabCount() == 8) {
        tabs1 = new Integer[] { 0, 1, 2, 3 };
        tabs2 = new Integer[] { 4, 5, 6, 7 };
    }
    final boolean doubleTabbed = tabs2.length > 0;
    final int compartmentPageWidth = 16 + 18 * inv.getPageSize() / 5;
    final int compartmentPageHeight = 106;
    final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24);
    final int compartmentHeight = compartmentPageHeight;
    final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight);
    final ControlTabBar<Integer> tab = new ControlTabBar<>(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1), (x1, y1, w, h, value) -> {
        return new CompartmentTabIcon(this, x1, y1, w, h, value);
    });
    final String[] tabHelp = { "Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately." };
    tab.addHelp(tabHelp);
    tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> {
        if (event.getValue() == null) {
            return;
        }
        final NBTTagCompound nbt = new NBTTagCompound();
        final int i = (Integer) event.getValue();
        nbt.setByte("i", (byte) i);
        Window.get(tab).sendClientAction("tab-change", nbt);
        WindowCompartment.this.currentTab = i;
    });
    x += 24;
    final ControlPages<Integer> compartmentPages = new ControlPages<>(controlCompartment, 24, 0, compartmentPageWidth, compartmentPageHeight);
    final ControlPage[] page = new ControlPage[inv.getTabCount()];
    for (int p = 0; p < inv.getTabCount(); ++p) {
        page[p] = new ControlPage<>(compartmentPages, p);
    }
    CraftGUIUtil.linkWidgets(tab, compartmentPages);
    int i = 0;
    for (int p2 = 0; p2 < inv.getTabCount(); ++p2) {
        final ControlPage thisPage = page[p2];
        final Panel panel = new CompartmentCenterPanel(this, thisPage);
        this.panels.put(panel, p2);
        final int[] slotsIDs = new int[inv.getPageSize()];
        for (int k = 0; k < inv.getPageSize(); ++k) {
            slotsIDs[k] = i++;
        }
        new ControlSlotArray.Builder(thisPage, 8, 8, inv.getPageSize() / 5, 5).create(slotsIDs);
    }
    x += compartmentPageWidth;
    if (tabs2.length > 0) {
        final ControlTabBar<Integer> tab2 = new ControlTabBar<>(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2), (x1, y1, w, h, value) -> {
            return new CompartmentTabIcon(this, x1, y1, w, h, value);
        });
        tab2.setValue(tabs1[0]);
        tab2.addHelp(tabHelp);
        tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> {
            if (event.getValue() == null) {
                return;
            }
            final NBTTagCompound nbt = new NBTTagCompound();
            final int iVal = (Integer) event.getValue();
            nbt.setByte("i", (byte) iVal);
            Window.get(tab).sendClientAction("tab-change", nbt);
            WindowCompartment.this.currentTab = iVal;
        });
        CraftGUIUtil.linkWidgets(tab2, compartmentPages);
        x += 24;
    }
    x += 16;
    this.setSize(new Point(Math.max(32 + compartmentWidth, 252), this.getHeight()));
    controlCompartment.setPosition(new Point((this.getWidth() - controlCompartment.getWidth()) / 2, controlCompartment.getYPos()));
    final ControlPlayerInventory invent = new ControlPlayerInventory(this, true);
    final ControlSlide slide = new ControlSlide(this, 0, 134, 136, 92, Alignment.LEFT);
    slide.setLabel("Tab Properties");
    slide.setSlide(false);
    slide.addHelp("Tab Properties");
    slide.addHelp("The label, colour and icon of the Tab can be altered here. Clicking on the icon with a held item will change it.");
    final Panel tabPropertyPanel = new Panel(slide, 16, 8, 112, 76, MinecraftGUI.PanelType.GRAY);
    int y2 = 4;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Name:");
    final Panel parent = tabPropertyPanel;
    final int x2 = 4;
    y2 += 12;
    (this.tabName = new ControlTextEdit(parent, x2, y2, 104, 12)).addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, this.tabName, event -> {
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        currentTab.setName(event.getValue());
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Tab Icon: ");
    (this.tabIcon = new ControlItemDisplay(tabPropertyPanel, 58, y2 - 4)).setItemStack(new ItemStack(Items.PAPER));
    this.tabIcon.addAttribute(Attribute.MOUSE_OVER);
    this.tabIcon.addSelfEventHandler(EventMouse.Down.class, event -> {
        if (WindowCompartment.this.getHeldItemStack().isEmpty()) {
            return;
        }
        final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
        final ItemStack stack = WindowCompartment.this.getHeldItemStack().copy();
        stack.setCount(1);
        currentTab.setIcon(stack);
        final NBTTagCompound nbt = new NBTTagCompound();
        currentTab.writeToNBT(nbt);
        WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
    });
    this.tabColour = new ControlColourSelector(tabPropertyPanel, 82, y2 - 4, 16, 16, EnumColor.WHITE);
    this.tabIcon.addHelp("Icon for Current Tab");
    this.tabIcon.addHelp("Click here with an item to change");
    y2 += 20;
    new ControlText(tabPropertyPanel, new Point(4, y2), "Colour: ");
    final int cw = 8;
    final Panel panelColour = new Panel(tabPropertyPanel, 40, y2 - 4, cw * 8 + 2, cw * 2 + 1, MinecraftGUI.PanelType.GRAY);
    for (int cc = 0; cc < 16; ++cc) {
        final ControlColourSelector color = new ControlColourSelector(panelColour, 1 + cw * (cc % 8), 1 + cw * (cc / 8), cw, cw, EnumColor.values()[cc]);
        color.addSelfEventHandler(EventMouse.Down.class, event -> {
            final binnie.core.machines.storage.CompartmentTab currentTab = WindowCompartment.this.getCurrentTab();
            currentTab.setColor(color.getValue());
            final NBTTagCompound nbt = new NBTTagCompound();
            currentTab.writeToNBT(nbt);
            WindowCompartment.this.sendClientAction("comp-change-tab", nbt);
        });
        color.addHelp("Colour Selector");
        color.addHelp("Select a colour to highlight the current tab");
    }
    y2 += 20;
    final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight);
    searchButton.addHelp("Search Button");
    searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items.");
}
Also used : ControlItemDisplay(binnie.core.gui.minecraft.control.ControlItemDisplay) ControlSlotArray(binnie.core.gui.minecraft.control.ControlSlotArray) ControlPage(binnie.core.gui.controls.page.ControlPage) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Control(binnie.core.gui.controls.core.Control) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) ControlSlide(binnie.core.gui.minecraft.control.ControlSlide) IInventory(net.minecraft.inventory.IInventory) IMachine(binnie.core.machines.IMachine) ControlText(binnie.core.gui.controls.ControlText) Point(binnie.core.gui.geometry.Point) MachinePackage(binnie.core.machines.MachinePackage) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) ControlButton(binnie.core.gui.controls.button.ControlButton) Panel(binnie.core.gui.window.Panel) ControlPages(binnie.core.gui.controls.page.ControlPages) EventMouse(binnie.core.gui.events.EventMouse) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IMachine (binnie.core.machines.IMachine)6 MachineUtil (binnie.core.machines.MachineUtil)3 ItemStack (net.minecraft.item.ItemStack)3 ComponentInventorySlots (binnie.core.machines.inventory.ComponentInventorySlots)2 ComponentInventoryTransfer (binnie.core.machines.inventory.ComponentInventoryTransfer)2 InventorySlot (binnie.core.machines.inventory.InventorySlot)2 SlotValidator (binnie.core.machines.inventory.SlotValidator)2 ComponentPowerReceptor (binnie.core.machines.power.ComponentPowerReceptor)2 ComponentGeneticGUI (binnie.genetics.machine.ComponentGeneticGUI)2 Random (java.util.Random)2 ControlText (binnie.core.gui.controls.ControlText)1 ControlTextEdit (binnie.core.gui.controls.ControlTextEdit)1 ControlButton (binnie.core.gui.controls.button.ControlButton)1 Control (binnie.core.gui.controls.core.Control)1 ControlPage (binnie.core.gui.controls.page.ControlPage)1 ControlPages (binnie.core.gui.controls.page.ControlPages)1 ControlTabBar (binnie.core.gui.controls.tab.ControlTabBar)1 EventMouse (binnie.core.gui.events.EventMouse)1 Point (binnie.core.gui.geometry.Point)1 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)1