Search in sources :

Example 1 with IPipeEventContents_BC8

use of buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventContents_BC8 in project BuildCraft by BuildCraft.

the class TravellingItem_BC8 method tick.

@BCPipeEventHandler
public void tick(IPipeEvent_BC8.Tick tick) {
    if (item.getProperties().getValue(PipeAPI_BC8.ITEM_PAUSED)) {
        // Just so we render them properly, and so we need to stop this from ticking in the near future
        tickStarted++;
        tickFinished++;
        return;
    }
    if (tick instanceof IPipeEvent_BC8.Tick.Client)
        return;
    EnumContentsJourneyPart direction = item.getJourneyPart();
    if (direction == EnumContentsJourneyPart.JUST_ENTERED) {
        // Setup ourselves NOW, but tick the rest later
        double normalizedSpeed = item.getSpeed() * PipeTransportItem_BC8.SPEED_NORMALIZER;
        IPipeEventContents_BC8.ChangeSpeed changeSpeed = null;
        pipe.fireEvent(changeSpeed);
        // normalizedSpeed = changeSpeed.getNormalizedSpeed();
        item.setSpeed(normalizedSpeed / PipeTransportItem_BC8.SPEED_NORMALIZER);
        double distance = 0.25;
        IConnection_BC8 connection = pipe.getConnections().get(item.getDirection().getOpposite());
        if (connection != null)
            distance += connection.getLength();
        // generate our new timings (when we will next tick)
        genTimings(pipe.getWorld().getTotalWorldTime(), distance);
        // Update the client with our new timings
        pipe.sendClientUpdate(this);
        // Tick next tick not this tick
        return;
    }
    if (tick.getCurrentTick() < tickFinished)
        return;
    if (direction == EnumContentsJourneyPart.TO_CENTER) {
    // We need to find out where we are going, and the new speed of ourselves
    } else {
    /* We must be going to the end of the pipe, so we need to insert ourselves into the next pipe, or into an
             * inventory (if one exists) */
    }
}
Also used : IPipeEvent_BC8(buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEvent_BC8) EnumContentsJourneyPart(buildcraft.api.transport.pipe_bc8.EnumContentsJourneyPart) IConnection_BC8(buildcraft.api.transport.pipe_bc8.IConnection_BC8) IPipeEventContents_BC8(buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventContents_BC8) BCPipeEventHandler(buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)

Example 2 with IPipeEventContents_BC8

use of buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventContents_BC8 in project BuildCraft by BuildCraft.

the class PipeTransportItem_BC8 method itemInsertion.

@BCPipeEventHandler
public void itemInsertion(IPipeEventContents_BC8.Enter enter) {
    // If somebody else has already handled this then don't even bother to handle it
    if (enter.hasBeenHandled())
        return;
    // if we are the limit then don't add it either
    int stacks = enter.getPipe().getProperties().getValue(PipeAPI_BC8.STACK_COUNT);
    // Note that a travelling item will probably add it to itself at this point.
    if (stacks >= PipeTransportItems.MAX_PIPE_STACKS)
        return;
    // Setup the item to make it tick immediately
    IPipeContentsEditableItem item = (IPipeContentsEditableItem) enter.getContents();
    item.setJourneyPart(EnumContentsJourneyPart.JUST_ENTERED);
    item.setDirection(enter.getFrom().getOpposite());
    long now = pipe.getWorld().getTotalWorldTime();
    TravellingItem_BC8 travellingItem = new TravellingItem_BC8(pipe, item, now, now);
    /* Actually add the item to the bus, which will make it render itself, tick itself, send client updates, etc. */
    if (pipe.addEventListener(travellingItem)) {
        // Tell the event that we have consumed the item, but only if it was actually added to the bus
        enter.handle();
    }
}
Also used : IPipeContentsEditableItem(buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem) BCPipeEventHandler(buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)

Aggregations

BCPipeEventHandler (buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)2 EnumContentsJourneyPart (buildcraft.api.transport.pipe_bc8.EnumContentsJourneyPart)1 IConnection_BC8 (buildcraft.api.transport.pipe_bc8.IConnection_BC8)1 IPipeContentsEditableItem (buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem)1 IPipeEventContents_BC8 (buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventContents_BC8)1 IPipeEvent_BC8 (buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEvent_BC8)1