Search in sources :

Example 1 with TubeStack

use of com.bluepowermod.part.tube.TubeStack in project BluePower by Qmunity.

the class MessageSyncMachineBacklog method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    super.toBytes(buf);
    buf.writeInt(stacks.size());
    for (TubeStack stack : stacks) {
        NBTTagCompound tag = new NBTTagCompound();
        stack.writeToNBT(tag);
        ByteBufUtils.writeTag(buf, tag);
    }
}
Also used : TubeStack(com.bluepowermod.part.tube.TubeStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with TubeStack

use of com.bluepowermod.part.tube.TubeStack in project BluePower by Qmunity.

the class TileMachineBase method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    NBTTagList nbttaglist = new NBTTagList();
    for (TubeStack tubeStack : internalItemStackBuffer) {
        if (tubeStack != null) {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            tubeStack.writeToNBT(nbttagcompound1);
            nbttaglist.appendTag(nbttagcompound1);
        }
    }
    compound.setTag("ItemBuffer", nbttaglist);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) TubeStack(com.bluepowermod.part.tube.TubeStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with TubeStack

use of com.bluepowermod.part.tube.TubeStack in project BluePower by Qmunity.

the class TileManager method acceptItemFromTube.

@Override
public TubeStack acceptItemFromTube(TubeStack stack, ForgeDirection from, boolean simulate) {
    if (from == getFacingDirection().getOpposite()) {
        // if (!isBufferEmpty()) return stack;
        int itemsAccepted = acceptedItems(stack.stack);
        if (itemsAccepted > 0) {
            if (itemsAccepted >= stack.stack.stackSize) {
                ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), stack.stack, from, simulate);
                if (rejectedStack == null || rejectedStack.stackSize != stack.stack.stackSize) {
                    if (!simulate) {
                        rejectTicker = 0;
                        sendUpdatePacket();
                    }
                }
                if (rejectedStack == null) {
                    return null;
                } else {
                    stack.stack = rejectedStack;
                    return stack;
                }
            }
            TubeStack injectedStack = stack.copy();
            stack.stack.stackSize -= itemsAccepted;
            injectedStack.stack.stackSize = itemsAccepted;
            ItemStack rejectedStack = IOHelper.insert(getTileCache(getFacingDirection()), injectedStack.stack, from, simulate);
            if (rejectedStack == null || rejectedStack.stackSize != injectedStack.stack.stackSize) {
                if (!simulate) {
                    rejectTicker = 0;
                    sendUpdatePacket();
                }
            }
            if (rejectedStack != null) {
                stack.stack.stackSize += rejectedStack.stackSize;
            }
        }
    }
    stack.setTarget(null, null);
    return super.acceptItemFromTube(stack, from, simulate);
}
Also used : TubeStack(com.bluepowermod.part.tube.TubeStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with TubeStack

use of com.bluepowermod.part.tube.TubeStack in project BluePower by Qmunity.

the class WidgetTabItemLister method render.

@Override
public void render(FontRenderer fontRenderer, float zLevel, float partialTicks) {
    this.setText(showingItems.size() == 0 ? "gui.bluepower:tab.stuffed.noItems" : "");
    super.render(fontRenderer, zLevel, partialTicks);
    if (isDoneExpanding()) {
        if (showingItems.size() > 0) {
            Gui.drawRect(getBaseX() + 7, getAffectedY() + 16, getBaseX() + Math.min(MAX_ITEMS_X, showingItems.size()) * 18 + 9, getAffectedY() + 36 + (showingItems.size() - 1) / MAX_ITEMS_X * 18, 0xFFAAAAAA);
        }
        for (int i = 0; i < MAX_ITEMS_X; i++) {
            for (int j = 0; i + j * MAX_ITEMS_X < showingItems.size(); j++) {
                TubeStack stack = showingItems.get(i + j * MAX_ITEMS_X);
                int x = getBaseX() + i * 18 + 9;
                int y = getAffectedY() + j * 18 + 18;
                if (stack.color != TubeColor.NONE) {
                    Gui.drawRect(x, y, x + 16, y + 16, 0xFF000000 + ItemDye.field_150922_c[stack.color.ordinal()]);
                }
                renderItem(fontRenderer, x, y, stack.stack);
            }
        }
    }
}
Also used : TubeStack(com.bluepowermod.part.tube.TubeStack)

Example 5 with TubeStack

use of com.bluepowermod.part.tube.TubeStack in project BluePower by Qmunity.

the class IOHelper method insert.

public static ItemStack insert(TileEntity tile, ItemStack itemStack, ForgeDirection direction, TubeColor color, boolean simulate) {
    if (tile == null || itemStack == null)
        return itemStack;
    if (tile instanceof ITubeConnection) {
        TubeStack tubeStack = ((ITubeConnection) tile).acceptItemFromTube(new TubeStack(itemStack, direction.getOpposite(), color), direction, simulate);
        if (tubeStack == null)
            return null;
        return tubeStack.stack;
    }
    IInventory inv = getInventoryForTE(tile);
    if (inv != null)
        return insert(inv, itemStack, direction.ordinal(), simulate);
    PneumaticTube tube = MultipartCompatibility.getPart(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, PneumaticTube.class);
    if (tube != null) {
        // we don't need to check connections, that's catched earlier.
        TubeLogic logic = tube.getLogic();
        return logic.injectStack(itemStack, direction.getOpposite(), color, simulate) ? null : itemStack;
    }
    return itemStack;
}
Also used : ITubeConnection(com.bluepowermod.api.tube.ITubeConnection) IInventory(net.minecraft.inventory.IInventory) PneumaticTube(com.bluepowermod.part.tube.PneumaticTube) TubeStack(com.bluepowermod.part.tube.TubeStack) TubeLogic(com.bluepowermod.part.tube.TubeLogic)

Aggregations

TubeStack (com.bluepowermod.part.tube.TubeStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ITubeConnection (com.bluepowermod.api.tube.ITubeConnection)1 PneumaticTube (com.bluepowermod.part.tube.PneumaticTube)1 TubeLogic (com.bluepowermod.part.tube.TubeLogic)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1