Search in sources :

Example 1 with ItemWire

use of buildcraft.transport.item.ItemWire in project BuildCraft by BuildCraft.

the class BlockPipeHolder method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return false;
    }
    RayTraceResult trace = rayTrace(world, pos, player);
    if (trace == null) {
        return false;
    }
    EnumFacing realSide = getPartSideHit(trace);
    if (realSide == null) {
        realSide = side;
    }
    if (trace.subHit > 6 && trace.subHit <= 12) {
        PipePluggable existing = tile.getPluggable(realSide);
        if (existing != null) {
            return existing.onPluggableActivate(player, trace, hitX, hitY, hitZ);
        }
    }
    EnumPipePart part = trace.subHit == 0 ? EnumPipePart.CENTER : EnumPipePart.fromFacing(realSide);
    ItemStack held = player.getHeldItem(hand);
    Item item = held.isEmpty() ? null : held.getItem();
    PipePluggable existing = tile.getPluggable(realSide);
    if (item instanceof IItemPluggable && existing == null) {
        IItemPluggable itemPlug = (IItemPluggable) item;
        PipePluggable plug = itemPlug.onPlace(held, tile, realSide, player, hand);
        if (plug == null) {
            return false;
        } else {
            tile.replacePluggable(realSide, plug);
            if (!player.capabilities.isCreativeMode) {
                held.shrink(1);
            }
            return true;
        }
    }
    if (item instanceof ItemWire) {
        EnumWirePart wirePartHit = getWirePartHit(trace);
        EnumWirePart wirePart;
        TilePipeHolder attachTile = tile;
        if (wirePartHit != null) {
            WireNode node = new WireNode(pos, wirePartHit);
            node = node.offset(trace.sideHit);
            wirePart = node.part;
            if (!node.pos.equals(pos)) {
                attachTile = getPipe(world, node.pos, false);
            }
        } else {
            wirePart = EnumWirePart.get((trace.hitVec.x % 1 + 1) % 1 > 0.5, (trace.hitVec.y % 1 + 1) % 1 > 0.5, (trace.hitVec.z % 1 + 1) % 1 > 0.5);
        }
        if (wirePart != null && attachTile != null) {
            boolean attached = attachTile.getWireManager().addPart(wirePart, EnumDyeColor.byMetadata(held.getMetadata()));
            attachTile.scheduleNetworkUpdate(IPipeHolder.PipeMessageReceiver.WIRES);
            if (attached && !player.capabilities.isCreativeMode) {
                held.shrink(1);
            }
            if (attached) {
                return true;
            }
        }
    }
    Pipe pipe = tile.getPipe();
    if (pipe == null) {
        return false;
    }
    if (pipe.behaviour.onPipeActivate(player, trace, hitX, hitY, hitZ, part)) {
        return true;
    }
    if (pipe.flow.onFlowActivate(player, trace, hitX, hitY, hitZ, part)) {
        return true;
    }
    return false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IItemPluggable(buildcraft.api.transport.IItemPluggable) RayTraceResult(net.minecraft.util.math.RayTraceResult) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) Item(net.minecraft.item.Item) ItemWire(buildcraft.transport.item.ItemWire) EnumWirePart(buildcraft.api.transport.EnumWirePart) WireNode(buildcraft.api.transport.WireNode) EnumPipePart(buildcraft.api.core.EnumPipePart) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EnumPipePart (buildcraft.api.core.EnumPipePart)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 WireNode (buildcraft.api.transport.WireNode)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 ItemWire (buildcraft.transport.item.ItemWire)1 Pipe (buildcraft.transport.pipe.Pipe)1 TilePipeHolder (buildcraft.transport.tile.TilePipeHolder)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1