Search in sources :

Example 1 with PipeDefinition

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

the class BlockPipeHolder method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null || target == null) {
        return ItemStack.EMPTY;
    }
    if (target.subHit <= 6) {
        Pipe pipe = tile.getPipe();
        if (pipe != null) {
            PipeDefinition def = pipe.getDefinition();
            Item item = (Item) PipeApi.pipeRegistry.getItemForPipe(def);
            if (item != null) {
                int meta = pipe.getColour() == null ? 0 : pipe.getColour().getMetadata() + 1;
                return new ItemStack(item, 1, meta);
            }
        }
    } else if (target.subHit <= 12) {
        int pluggableHit = target.subHit - 7;
        EnumFacing face = EnumFacing.VALUES[pluggableHit];
        PipePluggable plug = tile.getPluggable(face);
        if (plug != null) {
            return plug.getPickStack();
        }
    } else {
        EnumWirePart part = null;
        EnumWireBetween between = null;
        if (target.subHit > 6) {
            part = getWirePartHit(target);
            between = getWireBetweenHit(target);
        }
        if (part != null && tile.wireManager.getColorOfPart(part) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(part).getMetadata());
        } else if (between != null && tile.wireManager.getColorOfPart(between.parts[0]) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(between.parts[0]).getMetadata());
        }
    }
    return ItemStack.EMPTY;
}
Also used : TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) Item(net.minecraft.item.Item) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) ItemStack(net.minecraft.item.ItemStack) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 2 with PipeDefinition

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

the class TilePipeHolder method onPlacedBy.

// Misc
@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
    super.onPlacedBy(placer, stack);
    Item item = stack.getItem();
    if (item instanceof IItemPipe) {
        PipeDefinition definition = ((IItemPipe) item).getDefinition();
        this.pipe = new Pipe(this, definition);
        eventBus.registerHandler(pipe.behaviour);
        eventBus.registerHandler(pipe.flow);
        if (pipe.flow instanceof IFlowItems) {
            eventBus.registerHandler(FilterEventHandler.class);
        }
        int meta = stack.getMetadata();
        if (meta > 0 && meta <= 16) {
            pipe.setColour(EnumDyeColor.byMetadata(meta - 1));
        }
    }
    scheduleRenderUpdate();
}
Also used : Item(net.minecraft.item.Item) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) IPipe(buildcraft.api.transport.pipe.IPipe) Pipe(buildcraft.transport.pipe.Pipe) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 3 with PipeDefinition

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

the class SchematicBlockPipe method computeRequiredItems.

@Nonnull
@Override
public List<ItemStack> computeRequiredItems() {
    try {
        ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
        PipeDefinition definition = PipeRegistry.INSTANCE.loadDefinition(tileNbt.getCompoundTag("pipe").getString("def"));
        EnumDyeColor color = NBTUtilBC.readEnum(tileNbt.getCompoundTag("pipe").getTag("col"), EnumDyeColor.class);
        Item item = (Item) PipeApi.pipeRegistry.getItemForPipe(definition);
        if (item != null) {
            builder.add(new ItemStack(item, 1, color == null ? 0 : color.getMetadata() + 1));
        }
        return builder.build();
    } catch (InvalidInputDataException e) {
        throw new RuntimeException(e);
    }
}
Also used : Item(net.minecraft.item.Item) InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) ImmutableList(com.google.common.collect.ImmutableList) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor) Nonnull(javax.annotation.Nonnull)

Aggregations

PipeDefinition (buildcraft.api.transport.pipe.PipeDefinition)3 Item (net.minecraft.item.Item)3 Pipe (buildcraft.transport.pipe.Pipe)2 ItemStack (net.minecraft.item.ItemStack)2 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 IItemPipe (buildcraft.api.transport.pipe.IItemPipe)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 TilePipeHolder (buildcraft.transport.tile.TilePipeHolder)1 EnumWireBetween (buildcraft.transport.wire.EnumWireBetween)1 ImmutableList (com.google.common.collect.ImmutableList)1 Nonnull (javax.annotation.Nonnull)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 EnumFacing (net.minecraft.util.EnumFacing)1