Search in sources :

Example 1 with BCPipeEventHandler

use of buildcraft.api.transport.pipe_bc8.BCPipeEventHandler 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 BCPipeEventHandler

use of buildcraft.api.transport.pipe_bc8.BCPipeEventHandler in project BuildCraft by BuildCraft.

the class BehaviourWood method onPipeAttemptConnect.

@BCPipeEventHandler
public void onPipeAttemptConnect(IPipeEventConnection_BC8.AttemptCreate event) {
    if (event instanceof IPipeEventConnection_BC8.AttemptCreate.Pipe) {
        AttemptCreate.Pipe pipeEvent = (AttemptCreate.Pipe) event;
        PipeBehaviour_BC8 other = pipeEvent.with().getBehaviour();
        if (other instanceof BehaviourWood) {
            event.disallow();
        }
    }
}
Also used : IPipeEventConnection_BC8(buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventConnection_BC8) PipeBehaviour_BC8(buildcraft.api.transport.pipe_bc8.PipeBehaviour_BC8) AttemptCreate(buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventConnection_BC8.AttemptCreate) BCPipeEventHandler(buildcraft.api.transport.pipe_bc8.BCPipeEventHandler)

Example 3 with BCPipeEventHandler

use of buildcraft.api.transport.pipe_bc8.BCPipeEventHandler 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 4 with BCPipeEventHandler

use of buildcraft.api.transport.pipe_bc8.BCPipeEventHandler 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)4 IPipeContentsEditableItem (buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem)2 EnumContentsJourneyPart (buildcraft.api.transport.pipe_bc8.EnumContentsJourneyPart)1 IConnection_BC8 (buildcraft.api.transport.pipe_bc8.IConnection_BC8)1 PipeBehaviour_BC8 (buildcraft.api.transport.pipe_bc8.PipeBehaviour_BC8)1 IPipeEventConnection_BC8 (buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventConnection_BC8)1 AttemptCreate (buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEventConnection_BC8.AttemptCreate)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