Search in sources :

Example 6 with PipeEventHandler

use of buildcraft.api.transport.pipe.PipeEventHandler in project BuildCraft by BuildCraft.

the class FilterEventHandler method sideCheck.

@PipeEventHandler
public static void sideCheck(PipeEventItem.SideCheck event) {
    for (EnumFacing side : EnumFacing.VALUES) {
        if (!event.isAllowed(side)) {
            continue;
        }
        IPipe neighbour = event.holder.getNeighbourPipe(side);
        if (neighbour == null) {
            continue;
        }
        PipePluggable neighbourPlug = neighbour.getHolder().getPluggable(side.getOpposite());
        PipePluggable atPlug = event.holder.getPluggable(side);
        if (neighbourPlug instanceof PluggableLens) {
            EnumDyeColor colourAt = event.colour;
            if (atPlug instanceof PluggableLens) {
                PluggableLens lens = (PluggableLens) atPlug;
                if (!lens.isFilter) {
                    colourAt = lens.colour;
                }
            }
            PluggableLens lens = (PluggableLens) neighbourPlug;
            if (lens.isFilter) {
                if (colourAt == lens.colour) {
                    event.increasePriority(side);
                } else if (colourAt == null) {
                    event.decreasePriority(side);
                }
            }
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) IPipe(buildcraft.api.transport.pipe.IPipe) EnumDyeColor(net.minecraft.item.EnumDyeColor) PipeEventHandler(buildcraft.api.transport.pipe.PipeEventHandler)

Example 7 with PipeEventHandler

use of buildcraft.api.transport.pipe.PipeEventHandler in project BuildCraft by BuildCraft.

the class PipeBehaviourStripes method onDrop.

@PipeEventHandler
public void onDrop(PipeEventItem.Drop event) {
    if (direction == null) {
        return;
    }
    IPipeHolder holder = pipe.getHolder();
    World world = holder.getPipeWorld();
    BlockPos pos = holder.getPipePos();
    FakePlayer player = BuildCraftAPI.fakePlayerProvider.getFakePlayer((WorldServer) world, holder.getOwner(), pos);
    player.inventory.clear();
    // set the main hand of the fake player to the stack
    player.inventory.setInventorySlotContents(player.inventory.currentItem, event.getStack());
    if (PipeApi.stripeRegistry.handleItem(world, pos, direction, event.getStack(), player, this)) {
        event.setStack(StackUtil.EMPTY);
        for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
            ItemStack stack = player.inventory.removeStackFromSlot(i);
            if (!stack.isEmpty()) {
                sendItem(stack, direction);
            }
        }
    }
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) FakePlayer(net.minecraftforge.common.util.FakePlayer) PipeEventHandler(buildcraft.api.transport.pipe.PipeEventHandler)

Aggregations

PipeEventHandler (buildcraft.api.transport.pipe.PipeEventHandler)7 ItemStack (net.minecraft.item.ItemStack)4 EnumFacing (net.minecraft.util.EnumFacing)4 ArrayList (java.util.ArrayList)2 IPipe (buildcraft.api.transport.pipe.IPipe)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1 PipeEvent (buildcraft.api.transport.pipe.PipeEvent)1 ItemEntry (buildcraft.api.transport.pipe.PipeEventItem.ItemEntry)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 ActionPipeColor (buildcraft.transport.statements.ActionPipeColor)1 MethodHandle (java.lang.invoke.MethodHandle)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1 FluidStack (net.minecraftforge.fluids.FluidStack)1