Search in sources :

Example 1 with RaytraceResult

use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method doRayTrace.

public RaytraceResult doRayTrace(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer entityPlayer) {
    List<RaytraceResult> allHits = doRayTraceAll(world, pos, entityPlayer);
    Vec3d origin = Util.getEyePosition(entityPlayer);
    return RaytraceResult.getClosestHit(origin, allHits);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 2 with RaytraceResult

use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method getSelectedBoundingBox.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
    TileConduitBundle te = getTileEntity(world, pos);
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (te == null) {
        // FIXME is this valid?
        return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
    }
    IConduitBundle con = te;
    BoundingBox minBB = null;
    if (!YetaUtil.isSolidFacadeRendered(con, player)) {
        List<RaytraceResult> results = doRayTraceAll(world, pos, player);
        Iterator<RaytraceResult> iter = results.iterator();
        while (iter.hasNext()) {
            CollidableComponent component = iter.next().component;
            if (component != null && component.conduitType == null && component.data != ConduitConnectorType.EXTERNAL) {
                iter.remove();
            }
        }
        // This is an ugly special case, TODO fix this
        for (RaytraceResult hit : results) {
            IRedstoneConduit cond = con.getConduit(IRedstoneConduit.class);
            CollidableComponent component = hit.component;
            EnumFacing dir = component == null ? null : component.dir;
            if (cond != null && component != null && dir != null && cond.getExternalConnections().contains(dir) && component.data == InsulatedRedstoneConduit.COLOR_CONTROLLER_ID) {
                minBB = component.bound;
            }
        }
        if (minBB == null) {
            RaytraceResult hit = RaytraceResult.getClosestHit(Util.getEyePosition(player), results);
            CollidableComponent component = hit == null ? null : hit.component;
            if (component != null) {
                EnumFacing dir = component.dir;
                minBB = component.bound;
                if (dir != null && component.conduitType == null) {
                    dir = dir.getOpposite();
                    float trans = 0.0125f;
                    minBB = minBB.translate(dir.getFrontOffsetX() * trans, dir.getFrontOffsetY() * trans, dir.getFrontOffsetZ() * trans);
                    float scale = 0.7f;
                    minBB = minBB.scale(1 + Math.abs(dir.getFrontOffsetX()) * scale, 1 + Math.abs(dir.getFrontOffsetY()) * scale, 1 + Math.abs(dir.getFrontOffsetZ()) * scale);
                } else {
                    minBB = minBB.scale(1.09, 1.09, 1.09);
                }
            }
        }
    } else {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    if (minBB == null) {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    return new AxisAlignedBB(pos.getX() + minBB.minX, pos.getY() + minBB.minY, pos.getZ() + minBB.minZ, pos.getX() + minBB.maxX, pos.getY() + minBB.maxY, pos.getZ() + minBB.maxZ);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IRedstoneConduit(crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with RaytraceResult

use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method handleConduitProbeClick.

private boolean handleConduitProbeClick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, @Nonnull IConduitBundle bundle, @Nonnull ItemStack stack) {
    if (stack.getItemDamage() != 1) {
        // not in copy paste mode
        return false;
    }
    RaytraceResult rr = doRayTrace(world, pos, player);
    if (rr == null) {
        return false;
    }
    CollidableComponent component = rr.component;
    if (component == null) {
        return false;
    }
    EnumFacing dir = component.dir;
    if (dir == null) {
        return false;
    }
    return ItemConduitProbe.copyPasteSettings(player, stack, bundle, dir);
}
Also used : CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) EnumFacing(net.minecraft.util.EnumFacing) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 4 with RaytraceResult

use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.

the class InsulatedRedstoneConduit method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull RaytraceResult res, @Nonnull List<RaytraceResult> all) {
    World world = getBundle().getEntity().getWorld();
    if (!world.isRemote) {
        DyeColor col = DyeColor.getColorFromDye(player.getHeldItem(hand));
        if (col != null && res.component != null) {
            setSignalColor(res.component.dir, col);
            return true;
        } else if (ToolUtil.isToolEquipped(player, hand)) {
            if (res != null && res.component != null) {
                EnumFacing connDir = res.component.dir;
                EnumFacing faceHit = res.movingObjectPosition.sideHit;
                boolean colorHit = false;
                if (all != null && containsExternalConnection(connDir)) {
                    for (RaytraceResult rtr : all) {
                        if (rtr != null && rtr.component != null && COLOR_CONTROLLER_ID.equals(rtr.component.data)) {
                            colorHit = true;
                        }
                    }
                }
                if (colorHit) {
                    setSignalColor(connDir, DyeColor.getNext(getSignalColor(connDir)));
                    return true;
                } else if (connDir == null || connDir == faceHit) {
                    BlockPos pos = getBundle().getLocation().offset(faceHit);
                    Block id = world.getBlockState(pos).getBlock();
                    if (id == ConduitRegistry.getConduitModObjectNN().getBlock()) {
                        IRedstoneConduit neighbour = ConduitUtil.getConduit(world, pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
                        if (neighbour != null && neighbour.getConnectionMode(faceHit.getOpposite()) == ConnectionMode.DISABLED) {
                            neighbour.setConnectionMode(faceHit.getOpposite(), ConnectionMode.NOT_SET);
                        }
                        setConnectionMode(faceHit, ConnectionMode.NOT_SET);
                        return ConduitUtil.connectConduits(this, faceHit);
                    }
                    forceConnectionMode(faceHit, ConnectionMode.IN_OUT);
                    return true;
                } else if (externalConnections.contains(connDir)) {
                    if (network != null) {
                        network.destroyNetwork();
                    }
                    externalConnectionRemoved(connDir);
                    forceConnectionMode(connDir, ConnectionMode.DISABLED);
                    return true;
                } else if (containsConduitConnection(connDir)) {
                    BlockPos pos = getBundle().getLocation().offset(connDir);
                    IRedstoneConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().getWorld(), pos.getX(), pos.getY(), pos.getZ(), IRedstoneConduit.class);
                    if (neighbour != null) {
                        if (network != null) {
                            network.destroyNetwork();
                        }
                        if (neighbour.getNetwork() != null) {
                            neighbour.getNetwork().destroyNetwork();
                        }
                        neighbour.conduitConnectionRemoved(connDir.getOpposite());
                        conduitConnectionRemoved(connDir);
                        neighbour.connectionsChanged();
                        connectionsChanged();
                        updateNetwork();
                        neighbour.updateNetwork();
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DyeColor(com.enderio.core.common.util.DyeColor) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult)

Example 5 with RaytraceResult

use of crazypants.enderio.base.conduit.RaytraceResult in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method doRayTraceAll.

@Nonnull
protected NNList<RaytraceResult> doRayTraceAll(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d origin, @Nonnull Vec3d direction, EntityPlayer player) {
    TileEntity te = world.getTileEntity(pos);
    if (!(te instanceof IConduitBundle)) {
        return NNList.emptyList();
    }
    IConduitBundle bundle = (IConduitBundle) te;
    NNList<RaytraceResult> hits = new NNList<RaytraceResult>();
    if (YetaUtil.isSolidFacadeRendered(bundle, player)) {
        setBlockBounds(0, 0, 0, 1, 1, 1);
        RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
        if (hitPos != null) {
            hits.add(new RaytraceResult(new CollidableComponent(null, BoundingBox.UNIT_CUBE, hitPos.sideHit, null), hitPos));
        }
    } else {
        ConduitDisplayMode mode = YetaUtil.getDisplayMode(player);
        for (CollidableComponent component : new ArrayList<CollidableComponent>(bundle.getCollidableComponents())) {
            if (mode.isAll() || component.conduitType == null || YetaUtil.renderConduit(player, component.conduitType)) {
                setBlockBounds(component.bound.minX, component.bound.minY, component.bound.minZ, component.bound.maxX, component.bound.maxY, component.bound.maxZ);
                RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
                if (hitPos != null) {
                    hits.add(new RaytraceResult(component, hitPos));
                }
            }
        }
        // safety to prevent unbreakable empty bundles in case of a bug
        if (bundle.getConduits().isEmpty() && !YetaUtil.isFacadeHidden(bundle, player)) {
            setBlockBounds(0, 0, 0, 1, 1, 1);
            RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
            if (hitPos != null) {
                hits.add(new RaytraceResult(null, hitPos));
            }
        }
    }
    setBlockBounds(0, 0, 0, 1, 1, 1);
    return hits;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) NNList(com.enderio.core.common.util.NNList) RayTraceResult(net.minecraft.util.math.RayTraceResult) ArrayList(java.util.ArrayList) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull)

Aggregations

RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)8 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)4 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)4 Nonnull (javax.annotation.Nonnull)3 EnumFacing (net.minecraft.util.EnumFacing)3 NNList (com.enderio.core.common.util.NNList)2 ItemStack (net.minecraft.item.ItemStack)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 DyeColor (com.enderio.core.common.util.DyeColor)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 IConduit (crazypants.enderio.base.conduit.IConduit)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 IRedstoneConduit (crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit)1 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1