Search in sources :

Example 1 with InventorySlot

use of binnie.core.machines.inventory.InventorySlot in project Binnie by ForestryMC.

the class TransferRequest method transfer.

public TransferResult transfer(@Nullable EntityPlayer player, boolean doAdd) {
    ItemStack item = this.returnItem;
    if (item.isEmpty() || this.destination == null) {
        return TransferResult.FAILURE;
    }
    if (this.transferLiquids && this.destination instanceof ITankMachine && item.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
        ITankMachine tankMachine = (ITankMachine) this.destination;
        IFluidHandler fluidHandler = tankMachine.getHandler(targetTanks);
        if (fluidHandler != null) {
            ItemStack singleCopy = ItemHandlerHelper.copyStackWithSize(item, 1);
            FluidActionResult fluidActionResult;
            if (this.origin != null && doAdd) {
                IItemHandler itemHandler = new InvWrapper(this.origin);
                fluidActionResult = FluidUtil.tryEmptyContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                if (!fluidActionResult.isSuccess()) {
                    fluidActionResult = FluidUtil.tryFillContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                }
            } else {
                fluidActionResult = FluidUtil.tryEmptyContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                if (!fluidActionResult.isSuccess()) {
                    fluidActionResult = FluidUtil.tryFillContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                }
            }
            if (fluidActionResult.isSuccess()) {
                if (item.getCount() == 1) {
                    return new TransferResult(fluidActionResult.result);
                } else {
                    ItemStack itemCopy = item.copy();
                    itemCopy.shrink(1);
                    return new TransferResult(fluidActionResult.result, itemCopy);
                }
            }
            return TransferResult.FAILURE;
        }
    }
    if (!item.isEmpty()) {
        for (final int slot : this.targetSlots) {
            if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
                if (this.destination instanceof IInventorySlots) {
                    InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
                    if (inventorySlot != null && inventorySlot.isRecipe()) {
                        continue;
                    }
                }
                ItemStack stackInSlot = this.destination.getStackInSlot(slot);
                if (!stackInSlot.isEmpty()) {
                    if (item.isStackable()) {
                        final ItemStack merged = stackInSlot.copy();
                        final NonNullList<ItemStack> newStacks = mergeStacks(item.copy(), merged.copy());
                        item = newStacks.get(0);
                        if (!areItemsEqual(merged, newStacks.get(1))) {
                            this.insertedSlots.add(new TransferSlot(slot, this.destination));
                        }
                        if (doAdd) {
                            this.destination.setInventorySlotContents(slot, newStacks.get(1));
                        }
                        if (item.isEmpty()) {
                            return new TransferResult(ItemStack.EMPTY);
                        }
                    }
                }
            }
        }
    }
    if (!item.isEmpty()) {
        for (final int slot : this.targetSlots) {
            if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
                if (this.destination instanceof IInventorySlots) {
                    InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
                    if (inventorySlot != null && inventorySlot.isRecipe()) {
                        continue;
                    }
                }
                if (this.destination.getStackInSlot(slot).isEmpty()) {
                    this.insertedSlots.add(new TransferSlot(slot, this.destination));
                    if (doAdd) {
                        this.destination.setInventorySlotContents(slot, item.copy());
                    }
                    return new TransferResult(ItemStack.EMPTY);
                }
            }
        }
    }
    this.setReturnItem(item);
    return new TransferResult(item);
}
Also used : ITankMachine(binnie.core.machines.power.ITankMachine) IInventorySlots(binnie.core.machines.inventory.IInventorySlots) IItemHandler(net.minecraftforge.items.IItemHandler) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventorySlot(binnie.core.machines.inventory.InventorySlot) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 2 with InventorySlot

use of binnie.core.machines.inventory.InventorySlot in project Binnie by ForestryMC.

the class BreweryMachine method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ExtraTreeMachine.ComponentExtraTreeGUI(machine, ExtraTreesGUID.BREWERY);
    final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    for (final InventorySlot slot : inventory.addSlotArray(SLOT_RECIPE_GRAINS, new ResourceLocation(Constants.CORE_MOD_ID, "gui.slot.grain"))) {
        slot.setValidator(new SlotValidatorBreweryGrain());
        slot.setType(InventorySlot.Type.Recipe);
    }
    for (final InventorySlot slot : inventory.addSlotArray(SLOTS_INVENTORY, new ResourceLocation(Constants.CORE_MOD_ID, "gui.slot.inventory"))) {
        slot.forbidExtraction();
    }
    final InventorySlot yeast = inventory.addSlot(SLOT_YEAST, getSlotRL("yeast"));
    yeast.setValidator(new SlotValidatorBreweryYeast());
    yeast.setType(InventorySlot.Type.Recipe);
    final InventorySlot ingredient = inventory.addSlot(SLOT_RECIPE_INPUT, getSlotRL("ingredient"));
    ingredient.setValidator(new SlotValidatorBreweryIngredient());
    ingredient.setType(InventorySlot.Type.Recipe);
    final ComponentTankContainer tanks = new ComponentTankContainer(machine);
    TankSlot input = tanks.addTank(TANK_INPUT, "input", 5000);
    input.setValidator(new TankValidatorFermentInput());
    input.forbidExtraction();
    final TankSlot output = tanks.addTank(TANK_OUTPUT, "output", 5000);
    output.setValidator(new TankValidatorFermentOutput());
    output.setReadOnly();
    new ComponentPowerReceptor(machine);
    new BreweryLogic(machine);
}
Also used : SlotValidatorBreweryYeast(binnie.extratrees.machines.brewery.window.SlotValidatorBreweryYeast) ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) SlotValidatorBreweryIngredient(binnie.extratrees.machines.brewery.window.SlotValidatorBreweryIngredient) SlotValidatorBreweryGrain(binnie.extratrees.machines.brewery.window.SlotValidatorBreweryGrain) ComponentTankContainer(binnie.core.machines.inventory.ComponentTankContainer) TankValidatorFermentInput(binnie.extratrees.machines.brewery.window.TankValidatorFermentInput) ResourceLocation(net.minecraft.util.ResourceLocation) TankSlot(binnie.core.machines.inventory.TankSlot) TankValidatorFermentOutput(binnie.extratrees.machines.brewery.window.TankValidatorFermentOutput) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 3 with InventorySlot

use of binnie.core.machines.inventory.InventorySlot in project Binnie by ForestryMC.

the class PackageAnalyser method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ComponentGeneticGUI(machine, GeneticsGUI.ANALYSER);
    ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    for (InventorySlot slot : inventory.addSlotArray(Analyser.SLOT_RESERVE, getSlotRL("input"))) {
        slot.setValidator(new SlotValidatorUnanalysed());
        slot.forbidExtraction();
    }
    InventorySlot slotTarget = inventory.addSlot(Analyser.SLOT_TARGET, getSlotRL("analyse"));
    slotTarget.setReadOnly();
    slotTarget.forbidInteraction();
    InventorySlot slotDye = inventory.addSlot(Analyser.SLOT_DYE, getSlotRL("dye"));
    slotDye.forbidExtraction();
    slotDye.setValidator(new DyeSlotValidator());
    for (InventorySlot slot : inventory.addSlotArray(Analyser.SLOT_FINISHED, getSlotRL("output"))) {
        slot.forbidInsertion();
        slot.setReadOnly();
    }
    ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
    transfer.addRestock(Analyser.SLOT_RESERVE, 6, 1);
    transfer.addStorage(6, Analyser.SLOT_FINISHED, ManagerGenetics::isAnalysed);
    new ComponentChargedSlots(machine).addCharge(13);
    new ComponentPowerReceptor(machine, 500);
    new AnalyserLogic(machine);
    new AnalyserFX(machine);
}
Also used : ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) ManagerGenetics(binnie.core.genetics.ManagerGenetics) ComponentChargedSlots(binnie.core.machines.inventory.ComponentChargedSlots) ComponentGeneticGUI(binnie.genetics.machine.ComponentGeneticGUI) ComponentInventoryTransfer(binnie.core.machines.inventory.ComponentInventoryTransfer) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 4 with InventorySlot

use of binnie.core.machines.inventory.InventorySlot in project Binnie by ForestryMC.

the class PackagePolymeriser method createMachine.

@Override
public void createMachine(Machine machine) {
    new ComponentGeneticGUI(machine, GeneticsGUI.POLYMERISER);
    ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    // Slot Gold
    InventorySlot slotGold = inventory.addSlot(Polymeriser.SLOT_GOLD, getSlotRL("catalyst"));
    slotGold.setValidator(new SlotValidator.Item(new ItemStack(Items.GOLD_NUGGET, 1), ModuleMachine.getSpriteNugget()));
    slotGold.forbidExtraction();
    // Slot Serum
    InventorySlot slotSerum = inventory.addSlot(Polymeriser.SLOT_SERUM, getSlotRL("process"));
    slotSerum.setValidator(new SlotValidatorUnfilledSerum());
    slotSerum.forbidInteraction();
    slotSerum.setReadOnly();
    for (InventorySlot slot : inventory.addSlotArray(Polymeriser.SLOT_SERUM_RESERVE, getSlotRL("input"))) {
        slot.setValidator(new SlotValidatorUnfilledSerum());
        slot.forbidExtraction();
    }
    for (InventorySlot slot : inventory.addSlotArray(Polymeriser.SLOT_SERUM_FINISHED, getSlotRL("output"))) {
        slot.setReadOnly();
    }
    ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine);
    transfer.addRestock(Polymeriser.SLOT_SERUM_RESERVE, Polymeriser.SLOT_SERUM, 1);
    transfer.addStorage(Polymeriser.SLOT_SERUM, Polymeriser.SLOT_SERUM_FINISHED, (stack) -> !stack.isItemDamaged());
    ComponentTankContainer tank = new ComponentTankContainer(machine);
    tank.addTank(Polymeriser.TANK_BACTERIA, "input", 1000).setValidator(new BacteriaTankValidator());
    tank.addTank(Polymeriser.TANK_DNA, "input", 1000).setValidator(new DnaTankValidator());
    new ComponentChargedSlots(machine).addCharge(1);
    new ComponentPowerReceptor(machine, 8000);
    new PolymeriserLogic(machine);
    new PolymeriserFX(machine);
}
Also used : ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) InventorySlot(binnie.core.machines.inventory.InventorySlot) ComponentChargedSlots(binnie.core.machines.inventory.ComponentChargedSlots) ComponentGeneticGUI(binnie.genetics.machine.ComponentGeneticGUI) ComponentInventoryTransfer(binnie.core.machines.inventory.ComponentInventoryTransfer) ComponentTankContainer(binnie.core.machines.inventory.ComponentTankContainer) ItemStack(net.minecraft.item.ItemStack) SlotValidator(binnie.core.machines.inventory.SlotValidator) ComponentPowerReceptor(binnie.core.machines.power.ComponentPowerReceptor)

Example 5 with InventorySlot

use of binnie.core.machines.inventory.InventorySlot in project Binnie by ForestryMC.

the class PackageDesigner method createMachine.

@Override
public void createMachine(final Machine machine) {
    new ComponentBotanyGUI(machine, BotanyGUI.TILEWORKER);
    final ComponentInventorySlots inventory = new ComponentInventorySlots(machine);
    InventorySlot mortarSlot = inventory.addSlot(DesignerSlots.ADHESIVE_SLOT, new ResourceLocation(Constants.BOTANY_MOD_ID, "gui.slot.mortar"));
    mortarSlot.setValidator(new SlotValidatorDesignAdhesive(this.type));
    InventorySlot ceramicSlot1 = inventory.addSlot(DesignerSlots.DESIGN_SLOT_1, new ResourceLocation(Constants.BOTANY_MOD_ID, "gui.slot.ceramic"));
    ceramicSlot1.setValidator(new SlotValidatorDesignMaterial(this.type));
    InventorySlot ceramicSlot2 = inventory.addSlot(DesignerSlots.DESIGN_SLOT_2, new ResourceLocation(Constants.BOTANY_MOD_ID, "gui.slot.ceramic"));
    ceramicSlot2.setValidator(new SlotValidatorDesignMaterial(this.type));
    new ComponentDesignerRecipe(machine, this.type);
}
Also used : ComponentDesignerRecipe(binnie.design.gui.ComponentDesignerRecipe) ComponentInventorySlots(binnie.core.machines.inventory.ComponentInventorySlots) ComponentBotanyGUI(binnie.botany.machines.ComponentBotanyGUI) ResourceLocation(net.minecraft.util.ResourceLocation) InventorySlot(binnie.core.machines.inventory.InventorySlot) SlotValidatorDesignAdhesive(binnie.design.gui.SlotValidatorDesignAdhesive) SlotValidatorDesignMaterial(binnie.design.gui.SlotValidatorDesignMaterial)

Aggregations

InventorySlot (binnie.core.machines.inventory.InventorySlot)17 ComponentInventorySlots (binnie.core.machines.inventory.ComponentInventorySlots)13 ComponentPowerReceptor (binnie.core.machines.power.ComponentPowerReceptor)12 SlotValidator (binnie.core.machines.inventory.SlotValidator)10 ComponentInventoryTransfer (binnie.core.machines.inventory.ComponentInventoryTransfer)9 ComponentGeneticGUI (binnie.genetics.machine.ComponentGeneticGUI)9 ComponentTankContainer (binnie.core.machines.inventory.ComponentTankContainer)8 ComponentChargedSlots (binnie.core.machines.inventory.ComponentChargedSlots)5 TankSlot (binnie.core.machines.inventory.TankSlot)3 ItemStack (net.minecraft.item.ItemStack)3 IMachine (binnie.core.machines.IMachine)2 MachineUtil (binnie.core.machines.MachineUtil)2 EthanolTankValidator (binnie.genetics.machine.EthanolTankValidator)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ComponentBotanyGUI (binnie.botany.machines.ComponentBotanyGUI)1 ManagerGenetics (binnie.core.genetics.ManagerGenetics)1 Point (binnie.core.gui.geometry.Point)1 CustomSlot (binnie.core.gui.minecraft.CustomSlot)1 WindowInventory (binnie.core.gui.minecraft.WindowInventory)1 IInventorySlots (binnie.core.machines.inventory.IInventorySlots)1