Search in sources :

Example 1 with EnumWireBetween

use of buildcraft.transport.wire.EnumWireBetween in project BuildCraft by BuildCraft.

the class BlockPipeHolder method removedByPlayer.

@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
    if (world.isRemote) {
        return false;
    }
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return super.removedByPlayer(state, world, pos, player, willHarvest);
    }
    NonNullList<ItemStack> toDrop = NonNullList.create();
    RayTraceResult trace = rayTrace(world, pos, player);
    EnumFacing side = null;
    EnumWirePart part = null;
    EnumWireBetween between = null;
    if (trace != null && trace.subHit > 6) {
        side = getPartSideHit(trace);
        part = getWirePartHit(trace);
        between = getWireBetweenHit(trace);
    }
    if (side != null) {
        removePluggable(side, tile, toDrop);
        if (!player.capabilities.isCreativeMode) {
            InventoryUtil.dropAll(world, pos, toDrop);
        }
        return false;
    } else if (part != null) {
        toDrop.add(new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(part).getMetadata()));
        tile.wireManager.removePart(part);
        if (!player.capabilities.isCreativeMode) {
            InventoryUtil.dropAll(world, pos, toDrop);
        }
        tile.scheduleNetworkUpdate(IPipeHolder.PipeMessageReceiver.WIRES);
        return false;
    } else if (between != null) {
        toDrop.add(new ItemStack(BCTransportItems.wire, between.to == null ? 2 : 1, tile.wireManager.getColorOfPart(between.parts[0]).getMetadata()));
        if (between.to == null) {
            tile.wireManager.removeParts(Arrays.asList(between.parts));
        } else {
            tile.wireManager.removePart(between.parts[0]);
        }
        if (!player.capabilities.isCreativeMode) {
            InventoryUtil.dropAll(world, pos, toDrop);
        }
        tile.scheduleNetworkUpdate(IPipeHolder.PipeMessageReceiver.WIRES);
        return false;
    } else {
        toDrop.addAll(getDrops(world, pos, state, 0));
        for (EnumFacing face : EnumFacing.VALUES) {
            removePluggable(face, tile, NonNullList.create());
        }
    }
    if (!player.capabilities.isCreativeMode) {
        InventoryUtil.dropAll(world, pos, toDrop);
    }
    return super.removedByPlayer(state, world, pos, player, willHarvest);
}
Also used : TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 2 with EnumWireBetween

use of buildcraft.transport.wire.EnumWireBetween in project BuildCraft by BuildCraft.

the class BlockPipeHolder method rayTrace.

@Nullable
public RayTraceResult rayTrace(World world, BlockPos pos, Vec3d start, Vec3d end) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return computeTrace(null, pos, start, end, FULL_BLOCK_AABB, 400);
    }
    RayTraceResult best = null;
    Pipe pipe = tile.getPipe();
    boolean computed = false;
    if (pipe != null) {
        computed = true;
        best = computeTrace(best, pos, start, end, BOX_CENTER, 0);
        for (EnumFacing face : EnumFacing.VALUES) {
            float conSize = pipe.getConnectedDist(face);
            if (conSize > 0) {
                AxisAlignedBB aabb = BOX_FACES[face.ordinal()];
                if (conSize != 0.25f) {
                    Vec3d center = VecUtil.offset(new Vec3d(0.5, 0.5, 0.5), face, 0.25 + (conSize / 2));
                    Vec3d radius = new Vec3d(0.25, 0.25, 0.25);
                    radius = VecUtil.replaceValue(radius, face.getAxis(), conSize / 2);
                    Vec3d min = center.subtract(radius);
                    Vec3d max = center.add(radius);
                    aabb = BoundingBoxUtil.makeFrom(min, max);
                }
                best = computeTrace(best, pos, start, end, aabb, face.ordinal() + 1);
            }
        }
    }
    for (EnumFacing face : EnumFacing.VALUES) {
        PipePluggable pluggable = tile.getPluggable(face);
        if (pluggable != null) {
            AxisAlignedBB bb = pluggable.getBoundingBox();
            best = computeTrace(best, pos, start, end, bb, face.ordinal() + 1 + 6);
            computed = true;
        }
    }
    for (EnumWirePart part : tile.getWireManager().parts.keySet()) {
        best = computeTrace(best, pos, start, end, part.boundingBox, part.ordinal() + 1 + 6 + 6);
        computed = true;
    }
    for (EnumWireBetween between : tile.getWireManager().betweens.keySet()) {
        best = computeTrace(best, pos, start, end, between.boundingBox, between.ordinal() + 1 + 6 + 6 + 8);
        computed = true;
    }
    if (!computed) {
        return computeTrace(null, pos, start, end, FULL_BLOCK_AABB, 400);
    }
    return best;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) Vec3d(net.minecraft.util.math.Vec3d) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween) Nullable(javax.annotation.Nullable)

Example 3 with EnumWireBetween

use of buildcraft.transport.wire.EnumWireBetween in project BuildCraft by BuildCraft.

the class BlockPipeHolder method addCollisionBoxToList.

// Collisions
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isPistonMoving) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        addCollisionBoxToList(pos, entityBox, collidingBoxes, FULL_BLOCK_AABB);
        return;
    }
    boolean added = false;
    Pipe pipe = tile.getPipe();
    if (pipe != null) {
        addCollisionBoxToList(pos, entityBox, collidingBoxes, BOX_CENTER);
        added = true;
        for (EnumFacing face : EnumFacing.VALUES) {
            float conSize = pipe.getConnectedDist(face);
            if (conSize > 0) {
                AxisAlignedBB aabb = BOX_FACES[face.ordinal()];
                if (conSize != 0.25f) {
                    Vec3d center = VecUtil.offset(new Vec3d(0.5, 0.5, 0.5), face, 0.25 + (conSize / 2));
                    Vec3d radius = new Vec3d(0.25, 0.25, 0.25);
                    radius = VecUtil.replaceValue(radius, face.getAxis(), conSize / 2);
                    Vec3d min = center.subtract(radius);
                    Vec3d max = center.add(radius);
                    aabb = BoundingBoxUtil.makeFrom(min, max);
                }
                addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
            }
        }
    }
    for (EnumFacing face : EnumFacing.VALUES) {
        PipePluggable pluggable = tile.getPluggable(face);
        if (pluggable != null) {
            AxisAlignedBB bb = pluggable.getBoundingBox();
            addCollisionBoxToList(pos, entityBox, collidingBoxes, bb);
            added = true;
        }
    }
    for (EnumWirePart part : tile.getWireManager().parts.keySet()) {
        addCollisionBoxToList(pos, entityBox, collidingBoxes, part.boundingBox);
        added = true;
    }
    for (EnumWireBetween between : tile.getWireManager().betweens.keySet()) {
        addCollisionBoxToList(pos, entityBox, collidingBoxes, between.boundingBox);
        added = true;
    }
    if (!added) {
        addCollisionBoxToList(pos, entityBox, collidingBoxes, FULL_BLOCK_AABB);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) Vec3d(net.minecraft.util.math.Vec3d) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 4 with EnumWireBetween

use of buildcraft.transport.wire.EnumWireBetween in project BuildCraft by BuildCraft.

the class PipeWireRenderer method renderWires.

public static void renderWires(TilePipeHolder pipe, double x, double y, double z, BufferBuilder bb) {
    int combinedLight = pipe.getWorld().getCombinedLight(pipe.getPipePos(), 0);
    int skyLight = combinedLight >> 16 & 0xFFFF;
    int blockLight = combinedLight & 0xFFFF;
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    for (Map.Entry<EnumWirePart, EnumDyeColor> partColor : pipe.getWireManager().parts.entrySet()) {
        EnumWirePart part = partColor.getKey();
        EnumDyeColor color = partColor.getValue();
        boolean isOn = pipe.wireManager.isPowered(part);
        int idx = getIndex(part, color, isOn);
        if (wireRenderingCache[idx] == -1) {
            wireRenderingCache[idx] = compileWire(part, color, isOn);
        }
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, isOn ? 240 : blockLight, skyLight);
        GlStateManager.callList(wireRenderingCache[idx]);
    }
    for (Map.Entry<EnumWireBetween, EnumDyeColor> betweenColor : pipe.getWireManager().betweens.entrySet()) {
        EnumWireBetween between = betweenColor.getKey();
        EnumDyeColor color = betweenColor.getValue();
        boolean isOn = pipe.wireManager.isPowered(between.parts[0]);
        int idx = getIndex(between, color, isOn);
        if (wireRenderingCache[idx] == -1) {
            wireRenderingCache[idx] = compileWire(between, color, isOn);
        }
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, isOn ? 240 : blockLight, skyLight);
        GlStateManager.callList(wireRenderingCache[idx]);
    }
    GlStateManager.popMatrix();
    GlStateManager.enableLighting();
    /*
         * Directly rendering (like with a gllist) changes the colour directly, so we need to change the opengl state
         * directly
         */
    GL11.glColor3f(1, 1, 1);
    GlStateManager.color(1, 1, 1, 1);
}
Also used : EnumWirePart(buildcraft.api.transport.EnumWirePart) Map(java.util.Map) EnumMap(java.util.EnumMap) EnumDyeColor(net.minecraft.item.EnumDyeColor) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Example 5 with EnumWireBetween

use of buildcraft.transport.wire.EnumWireBetween 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)

Aggregations

EnumWirePart (buildcraft.api.transport.EnumWirePart)6 EnumWireBetween (buildcraft.transport.wire.EnumWireBetween)6 TilePipeHolder (buildcraft.transport.tile.TilePipeHolder)5 EnumFacing (net.minecraft.util.EnumFacing)5 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)4 Pipe (buildcraft.transport.pipe.Pipe)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 Vec3d (net.minecraft.util.math.Vec3d)3 ItemStack (net.minecraft.item.ItemStack)2 PipeDefinition (buildcraft.api.transport.pipe.PipeDefinition)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 Item (net.minecraft.item.Item)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1