Search in sources :

Example 1 with ModuleActiveSupplier

use of logisticspipes.modules.ModuleActiveSupplier in project LogisticsPipes by RS485.

the class SlotFinderNumberPacket method processPacket.

@Override
@SuppressWarnings("unchecked")
public void processPacket(EntityPlayer player) {
    IInventory inv = this.getTile(player.worldObj, IInventory.class);
    if (inv instanceof ISidedInventory) {
        inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
    }
    IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
    Slot result = null;
    if (((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot).slotNumber == inventorySlot) {
        result = ((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot);
    }
    if (result == null) {
        for (Slot slotObject : (List<Slot>) player.openContainer.inventorySlots) {
            if (slotObject.slotNumber == inventorySlot) {
                result = slotObject;
                break;
            }
        }
    }
    if (result == null) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    }
    int resultIndex = -1;
    if (resultIndex == -1) {
        ItemStack content = result.getStack();
        if (content != null) {
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (content == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
        } else {
            ItemStack dummyStack = new ItemStack(Blocks.stone, 0, 0);
            NBTTagCompound nbt = new NBTTagCompound();
            //Make it unique
            nbt.setBoolean("LPStackFinderBoolean", true);
            dummyStack.setTagCompound(nbt);
            result.putStack(dummyStack);
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (dummyStack == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
            if (resultIndex == -1) {
                for (int i = 0; i < util.getSizeInventory(); i++) {
                    ItemStack stack = util.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (ItemIdentifier.get(stack).equals(ItemIdentifier.get(dummyStack)) && stack.stackSize == dummyStack.stackSize) {
                        resultIndex = i;
                        break;
                    }
                }
            }
            result.putStack(null);
        }
    }
    if (resultIndex == -1) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    } else {
        //Copy pipe to coordinates to use the getPipe method
        setPosX(getPipePosX());
        setPosY(getPipePosY());
        setPosZ(getPipePosZ());
        ModuleActiveSupplier module = this.getLogisticsModule(player, ModuleActiveSupplier.class);
        if (module != null) {
            module.slotArray[slot] = resultIndex;
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Slot(net.minecraft.inventory.Slot) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ModuleActiveSupplier

use of logisticspipes.modules.ModuleActiveSupplier in project LogisticsPipes by RS485.

the class SupplierPipeLimitedPacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    ModuleActiveSupplier module = this.getLogisticsModule(player, ModuleActiveSupplier.class);
    if (module == null) {
        return;
    }
    module.setLimited(isLimited());
    if (MainProxy.isClient(player.worldObj)) {
        refresh();
    } else {
        MainProxy.sendPacketToPlayer(PacketHandler.getPacket(SupplierPipeLimitedPacket.class).setLimited(isLimited()).setPacketPos(this), player);
    }
}
Also used : ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier)

Example 3 with ModuleActiveSupplier

use of logisticspipes.modules.ModuleActiveSupplier in project LogisticsPipes by RS485.

the class SupplierPipeModePacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    final ModuleActiveSupplier module = this.getLogisticsModule(player, ModuleActiveSupplier.class);
    if (module == null) {
        return;
    }
    int mode;
    if (module.hasPatternUpgrade()) {
        mode = module.getPatternMode().ordinal() + 1;
        if (mode >= PatternMode.values().length) {
            mode = 0;
        }
        module.setPatternMode(PatternMode.values()[mode]);
    } else {
        mode = module.getSupplyMode().ordinal() + 1;
        if (mode >= SupplyMode.values().length) {
            mode = 0;
        }
        module.setSupplyMode(SupplyMode.values()[mode]);
    }
    MainProxy.sendPacketToPlayer(PacketHandler.getPacket(SupplierPipeMode.class).setHasPatternUpgrade(module.hasPatternUpgrade()).setInteger(mode).setPacketPos(this), player);
}
Also used : ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier)

Example 4 with ModuleActiveSupplier

use of logisticspipes.modules.ModuleActiveSupplier in project LogisticsPipes by RS485.

the class ActiveSupplierInHand method getContainer.

@Override
public DummyContainer getContainer(EntityPlayer player) {
    DummyContainer dummy = new DummyModuleContainer(player, getInvSlot());
    if (!(((DummyModuleContainer) dummy).getModule() instanceof ModuleActiveSupplier)) {
        return null;
    }
    ((DummyModuleContainer) dummy).setInventory(((ModuleActiveSupplier) ((DummyModuleContainer) dummy).getModule()).getDummyInventory());
    dummy.addNormalSlotsForPlayerInventory(8, 60);
    //Pipe slots
    for (int pipeSlot = 0; pipeSlot < 9; pipeSlot++) {
        dummy.addDummySlot(pipeSlot, 8 + pipeSlot * 18, 18);
    }
    return dummy;
}
Also used : DummyContainer(logisticspipes.utils.gui.DummyContainer) ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier) DummyModuleContainer(logisticspipes.utils.gui.DummyModuleContainer)

Example 5 with ModuleActiveSupplier

use of logisticspipes.modules.ModuleActiveSupplier in project LogisticsPipes by RS485.

the class ActiveSupplierSlot method getContainer.

@Override
public DummyContainer getContainer(EntityPlayer player) {
    ModuleActiveSupplier module = this.getLogisticsModule(player.getEntityWorld(), ModuleActiveSupplier.class);
    if (module == null) {
        return null;
    }
    DummyContainer dummy = new DummyContainer(player.inventory, module.getDummyInventory());
    dummy.addNormalSlotsForPlayerInventory(18, 97);
    for (int row = 0; row < 3; row++) {
        for (int column = 0; column < 3; column++) {
            dummy.addDummySlot(column + row * 3, 72 + column * 18, 18 + row * 18);
        }
    }
    return dummy;
}
Also used : ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier) DummyContainer(logisticspipes.utils.gui.DummyContainer)

Aggregations

ModuleActiveSupplier (logisticspipes.modules.ModuleActiveSupplier)6 DummyContainer (logisticspipes.utils.gui.DummyContainer)2 List (java.util.List)1 GuiSupplierPipe (logisticspipes.gui.GuiSupplierPipe)1 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)1 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)1 DummyModuleContainer (logisticspipes.utils.gui.DummyModuleContainer)1 IInventory (net.minecraft.inventory.IInventory)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 Slot (net.minecraft.inventory.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)1