Search in sources :

Example 1 with IPipeContentsEditableItem

use of buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem in project BuildCraft by BuildCraft.

the class TravellingItem_BC8 method itemInsertion.

// Event handlers
@BCPipeEventHandler
public void itemInsertion(Enter enter) {
    /* PipeTransportItem will NOT handle it if the number of stacks is greater than or equal to the max, so it falls
         * down to us to handle it. */
    if (enter.hasBeenHandled())
        return;
    // Only handle the insertion if its an item
    if (enter.getContents() instanceof IPipeContentsEditableItem) {
        // Check if the pipe already has a lot of items, if it doesn't, then just ignore it.
        int stacks = enter.getPipe().getProperties().getValue(PipeAPI_BC8.STACK_COUNT);
        if (stacks < PipeTransportItems.MAX_PIPE_STACKS)
            return;
        IPipeContentsEditableItem item = (IPipeContentsEditableItem) enter.getContents();
        long now = enter.getPipe().getWorld().getTotalWorldTime();
        double dist = getWayThrough(now);
        /* Don't add it to ourself if we are far enough away from the entrance. tryEncompass will check for us to
             * see if we are using going in the same direction. */
        if (dist > 0.25)
            return;
        /* If an item is about to be added to a pipe, try and add it to this item rather than creating a new item */
        if (tryEncompass(item)) {
            // Let everybody know that we have handled this item, so no-one else needs to
            enter.handle();
        }
    }
}
Also used : IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem) BCPipeEventHandler(buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)

Example 2 with IPipeContentsEditableItem

use of buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem in project BuildCraft by BuildCraft.

the class TravellingItem_BC8 method readFromNBT.

@Override
public TravellingItem_BC8 readFromNBT(NBTBase nbt) {
    NBTTagCompound tag = (NBTTagCompound) nbt;
    IPipeContentsEditableItem item = this.item.readFromNBT(tag.getCompoundTag("item"));
    long started = tag.getLong("tickStarted");
    long finished = tag.getLong("tickFinished");
    return new TravellingItem_BC8(pipe, item, started, finished);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem)

Example 3 with IPipeContentsEditableItem

use of buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem in project BuildCraft by BuildCraft.

the class TravellingItem_BC8 method readFromByteBuf.

@Override
public TravellingItem_BC8 readFromByteBuf(ByteBuf buf) {
    IPipeContentsEditableItem item = this.item.readFromByteBuf(buf);
    long now = pipe.getWorld().getTotalWorldTime();
    long started = now + buf.readLong();
    long finished = now + buf.readLong();
    return new TravellingItem_BC8(pipe, item, started, finished);
}
Also used : IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem)

Example 4 with IPipeContentsEditableItem

use of buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem in project BuildCraft by BuildCraft.

the class BehaviourWood method extract.

/**
 * @param items The number of items you can extract
 * @return The amount of power used
 */
private int extract(int availableEnergy) {
    IConnection_BC8 connection = pipe.getConnections().get(extractionFace.face);
    if (connection == null)
        return 0;
    IExtractable_BC8 extractable = pipe.getConnections().get(extractionFace).getExtractor();
    IInsertable_BC8 insertable = PipeAPI_BC8.INSERTION_MANAGER.getInsertableFor(pipe);
    IPipeContentsEditable contents = extractType(availableEnergy, insertable, extractable);
    if (contents == null)
        return 0;
    int energyRequired = getEnergyCost(contents);
    boolean inserted;
    if (contents instanceof IPipeContentsEditableItem) {
        inserted = insertable.tryInsertItems((IPipeContentsEditableItem) contents, pipe, extractionFace.face.getOpposite(), false);
    } else {
        inserted = insertable.tryInsertFluid((IPipeContentsEditableFluid) contents, pipe, extractionFace.face.getOpposite(), false);
    }
    if (!inserted)
        throw new IllegalStateException("Cannot NOT insert!");
    return energyRequired;
}
Also used : IInsertable_BC8(buildcraft.api.transport.pipe_bc8.IInsertionManager.IInsertable_BC8) IExtractable_BC8(buildcraft.api.transport.pipe_bc8.IExtractionManager.IExtractable_BC8) IPipeContentsEditableFluid(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableFluid) IPipeContentsEditable(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable) IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem) IConnection_BC8(buildcraft.api.transport.pipe_bc8.IConnection_BC8)

Example 5 with IPipeContentsEditableItem

use of buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem in project BuildCraft by BuildCraft.

the class PipeContentsEditableItem method readFromNBT.

@Override
public IPipeContentsEditableItem readFromNBT(NBTBase nbt) {
    NBTTagCompound tag = (NBTTagCompound) nbt;
    ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("stack"));
    EnumContentsJourneyPart journeyPart = NBTUtilBC.readEnum(tag.getTag("journeyPart"), EnumContentsJourneyPart.class);
    EnumFacing direction = NBTUtilBC.readEnum(tag.getTag("direction"), EnumFacing.class);
    double speed = tag.getDouble("speed");
    IPipePropertyProviderEditable provider = propertyProvider.readFromNBT(tag.getTag("properties"));
    return new PipeContentsEditableItem(provider, stack, journeyPart, direction, speed);
}
Also used : IPipePropertyProviderEditable(buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyProviderEditable) IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumContentsJourneyPart(buildcraft.api.transport.pipe_bc8.EnumContentsJourneyPart) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IPipeContentsEditableItem (buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem)6 BCPipeEventHandler (buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumContentsJourneyPart (buildcraft.api.transport.pipe_bc8.EnumContentsJourneyPart)1 IConnection_BC8 (buildcraft.api.transport.pipe_bc8.IConnection_BC8)1 IExtractable_BC8 (buildcraft.api.transport.pipe_bc8.IExtractionManager.IExtractable_BC8)1 IInsertable_BC8 (buildcraft.api.transport.pipe_bc8.IInsertionManager.IInsertable_BC8)1 IPipeContentsEditable (buildcraft.api.transport.pipe_bc8.IPipeContentsEditable)1 IPipeContentsEditableFluid (buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableFluid)1 IPipePropertyProviderEditable (buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyProviderEditable)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1