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();
}
}
}
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);
}
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);
}
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;
}
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);
}
Aggregations