Search in sources :

Example 1 with GuiChassisPipe

use of logisticspipes.gui.GuiChassisPipe in project LogisticsPipes by RS485.

the class PipeLogisticsChassis method InventoryChanged.

@Override
public void InventoryChanged(IInventory inventory) {
    boolean reInitGui = false;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack stack = inventory.getStackInSlot(i);
        if (stack.isEmpty()) {
            if (_module.hasModule(i)) {
                _module.removeModule(i);
                reInitGui = true;
            }
            continue;
        }
        if (stack.getItem() instanceof ItemModule) {
            LogisticsModule current = _module.getModule(i);
            LogisticsModule next = ((ItemModule) stack.getItem()).getModuleForItem(stack, _module.getModule(i), this, this);
            Objects.requireNonNull(next, "getModuleForItem returned null for " + stack.toString());
            next.registerPosition(ModulePositionType.SLOT, i);
            next.registerCCEventQueuer(this);
            if (current != next) {
                _module.installModule(i, next);
                if (!MainProxy.isClient(getWorld())) {
                    ItemModuleInformationManager.readInformation(stack, next);
                }
            }
            inventory.setInventorySlotContents(i, stack);
        }
    }
    if (reInitGui) {
        if (MainProxy.isClient(getWorld())) {
            if (FMLClientHandler.instance().getClient().currentScreen instanceof GuiChassisPipe) {
                FMLClientHandler.instance().getClient().currentScreen.initGui();
            }
        }
    }
    if (MainProxy.isServer(getWorld())) {
        if (!localModeWatchers.isEmpty()) {
            MainProxy.sendToPlayerList(PacketHandler.getPacket(ChassisPipeModuleContent.class).setIdentList(ItemIdentifierStack.getListFromInventory(_moduleInventory)).setPosX(getX()).setPosY(getY()).setPosZ(getZ()), localModeWatchers);
        }
    }
}
Also used : GuiChassisPipe(logisticspipes.gui.GuiChassisPipe) LogisticsModule(logisticspipes.modules.LogisticsModule) ChassisPipeModuleContent(logisticspipes.network.packets.pipe.ChassisPipeModuleContent) ItemStack(net.minecraft.item.ItemStack) ItemModule(logisticspipes.items.ItemModule)

Aggregations

GuiChassisPipe (logisticspipes.gui.GuiChassisPipe)1 ItemModule (logisticspipes.items.ItemModule)1 LogisticsModule (logisticspipes.modules.LogisticsModule)1 ChassisPipeModuleContent (logisticspipes.network.packets.pipe.ChassisPipeModuleContent)1 ItemStack (net.minecraft.item.ItemStack)1