Search in sources :

Example 1 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project malmo by Microsoft.

the class ObservationFromRayImplementation method findEntity.

static MovingObjectPosition findEntity(Vec3 eyePos, Vec3 lookVec, double depth, MovingObjectPosition mop, boolean includeTiles) {
    // Based on code in EntityRenderer.getMouseOver()
    if (mop != null)
        depth = mop.hitVec.distanceTo(eyePos);
    Vec3 searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
    Entity pointedEntity = null;
    Vec3 hitVec = null;
    Entity viewer = Minecraft.getMinecraft().thePlayer;
    List<?> list = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(viewer, viewer.getEntityBoundingBox().addCoord(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth).expand(1.0, 1.0, 1.0));
    double distance = depth;
    for (int i = 0; i < list.size(); ++i) {
        Entity entity = (Entity) list.get(i);
        if (entity.canBeCollidedWith() || includeTiles) {
            float border = entity.getCollisionBorderSize();
            AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double) border, (double) border, (double) border);
            MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(eyePos, searchVec);
            if (axisalignedbb.isVecInside(eyePos)) {
                // If entity is right inside our head?
                if (distance >= 0) {
                    pointedEntity = entity;
                    hitVec = (movingobjectposition == null) ? eyePos : mop.hitVec;
                    distance = 0.0D;
                }
            } else if (movingobjectposition != null) {
                double distToEnt = eyePos.distanceTo(movingobjectposition.hitVec);
                if (distToEnt < distance || distance == 0.0D) {
                    if (entity == entity.ridingEntity && !entity.canRiderInteract()) {
                        if (distance == 0.0D) {
                            pointedEntity = entity;
                            hitVec = movingobjectposition.hitVec;
                        }
                    } else {
                        pointedEntity = entity;
                        hitVec = movingobjectposition.hitVec;
                        distance = distToEnt;
                    }
                }
            }
        }
    }
    if (pointedEntity != null && (distance < depth || mop == null)) {
        MovingObjectPosition newMop = new MovingObjectPosition(pointedEntity, hitVec);
        return newMop;
    }
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Example 2 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

private RaytraceResult doRayTrace(LogisticsTileGenericPipe tileG, CoreMultiBlockPipe pipe, Vec3 origin, Vec3 direction) {
    if (tileG == null) {
        return null;
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return null;
    }
    List<MovingObjectPosition> hits = new ArrayList<>();
    List<AxisAlignedBB> boxes = new ArrayList<>();
    pipe.addCollisionBoxesToList(boxes, null);
    while (hits.size() < boxes.size()) {
        hits.add(null);
    }
    for (int i = 0; i < boxes.size(); i++) {
        AxisAlignedBB bb = boxes.get(i);
        setBlockBoundsFromAbsolut(bb, tileG);
        hits.set(i, super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction));
    }
    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for (int i = 0; i < hits.size(); i++) {
        MovingObjectPosition hit = hits.get(i);
        if (hit == null) {
            continue;
        }
        double lengthSquared = hit.hitVec.squareDistanceTo(origin);
        if (lengthSquared < minLengthSquared) {
            minLengthSquared = lengthSquared;
            minIndex = i;
        }
    }
    // reset bounds
    setBlockBounds(0, 0, 0, 1, 1, 1);
    if (minIndex == -1) {
        return null;
    } else {
        return new RaytraceResult(Part.Pipe, hits.get(minIndex), //*
        pipe.getCompleteBox(), /*/
					boxes.get(minIndex).getOffsetBoundingBox(-tileG.xCoord, -tileG.yCoord, -tileG.zCoord)
					//*/
        ForgeDirection.UNKNOWN);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ArrayList(java.util.ArrayList)

Example 3 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

private RaytraceResult doRayTrace(LogisticsTileGenericPipe tileG, CoreUnroutedPipe pipe, Vec3 origin, Vec3 direction) {
    if (tileG == null) {
        return null;
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return null;
    }
    /**
		 * pipe hits along x, y, and z axis, gate (all 6 sides) [and
		 * wires+facades]
		 */
    MovingObjectPosition[] hits = new MovingObjectPosition[31];
    AxisAlignedBB[] boxes = new AxisAlignedBB[31];
    ForgeDirection[] sideHit = new ForgeDirection[31];
    Arrays.fill(sideHit, ForgeDirection.UNKNOWN);
    // pipe
    for (ForgeDirection side : LogisticsBlockGenericPipe.DIR_VALUES) {
        if (side == ForgeDirection.UNKNOWN || tileG.isPipeConnected(side)) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = getPipeBoundingBox(side);
            setBlockBounds(bb);
            boxes[side.ordinal()] = bb;
            hits[side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[side.ordinal()] = side;
        }
    }
    for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
        if (tileG.getPipePluggable(side) != null) {
            if (side != ForgeDirection.UNKNOWN && ignoreSideRayTrace)
                continue;
            AxisAlignedBB bb = tileG.getPipePluggable(side).getBoundingBox(side);
            setBlockBounds(bb);
            boxes[7 + side.ordinal()] = bb;
            hits[7 + side.ordinal()] = super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction);
            sideHit[7 + side.ordinal()] = side;
        }
    }
    // TODO: check wires
    // get closest hit
    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for (int i = 0; i < hits.length; i++) {
        MovingObjectPosition hit = hits[i];
        if (hit == null) {
            continue;
        }
        double lengthSquared = hit.hitVec.squareDistanceTo(origin);
        if (lengthSquared < minLengthSquared) {
            minLengthSquared = lengthSquared;
            minIndex = i;
        }
    }
    // reset bounds
    setBlockBounds(0, 0, 0, 1, 1, 1);
    if (minIndex == -1) {
        return null;
    } else {
        Part hitPart;
        if (minIndex < 7) {
            hitPart = Part.Pipe;
        } else {
            hitPart = Part.Pluggable;
        }
        return new RaytraceResult(hitPart, hits[minIndex], boxes[minIndex], sideHit[minIndex]);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 4 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project LogisticsPipes by RS485.

the class HSTubeCurve method addCollisionBoxesToList.

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addCollisionBoxesToList(List arraylist, AxisAlignedBB axisalignedbb) {
    double x = getX();
    double y = getY();
    double z = getZ();
    double angle = 0;
    double addOne = 0;
    double addTwo = 0;
    if (orientation.getRenderOrientation() == TurnDirection.NORTH_EAST) {
        angle = 3 * Math.PI / 2;
        addOne = LPConstants.PIPE_MAX_POS;
        addTwo = LPConstants.PIPE_MIN_POS;
        z -= 2;
        x += 1;
    } else if (orientation.getRenderOrientation() == TurnDirection.EAST_SOUTH) {
        angle = 2 * Math.PI / 2;
        addOne = LPConstants.PIPE_MIN_POS;
        addTwo = LPConstants.PIPE_MAX_POS;
        x += 3;
        z += 1;
    } else if (orientation.getRenderOrientation() == TurnDirection.SOUTH_WEST) {
        angle = Math.PI / 2;
        addOne = LPConstants.PIPE_MAX_POS;
        addTwo = LPConstants.PIPE_MIN_POS;
        z += 3;
    } else if (orientation.getRenderOrientation() == TurnDirection.WEST_NORTH) {
        angle = 0;
        addOne = LPConstants.PIPE_MIN_POS;
        addTwo = LPConstants.PIPE_MAX_POS;
        x -= 2;
    }
    for (int i = 0; i < 49; i++) {
        double xOne = x;
        double yMin = y + LPConstants.PIPE_MIN_POS;
        double zOne = z;
        double xTwo = x;
        double yMax = y + LPConstants.PIPE_MAX_POS;
        double zTwo = z;
        xOne += (2 + addOne) * Math.sin(angle + (2 * Math.PI / 200 * (i)));
        zOne += (2 + addOne) * Math.cos(angle + (2 * Math.PI / 200 * (i + 2)));
        xTwo += (2 + addTwo) * Math.sin(angle + (2 * Math.PI / 200 * (i + 1)));
        zTwo += (2 + addTwo) * Math.cos(angle + (2 * Math.PI / 200 * (i)));
        AxisAlignedBB box = AxisAlignedBB.getBoundingBox(Math.min(xOne, xTwo), yMin, Math.min(zOne, zTwo), Math.max(xOne, xTwo), yMax, Math.max(zOne, zTwo));
        if (box != null && (axisalignedbb == null || axisalignedbb.intersectsWith(box))) {
            arraylist.add(box);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 5 with AxisAlignedBB

use of net.minecraft.util.AxisAlignedBB in project LogisticsPipes by RS485.

the class HSTubeLine method addCollisionBoxesToList.

@Override
public void addCollisionBoxesToList(List arraylist, AxisAlignedBB axisalignedbb) {
    DoubleCoordinates pos = getLPPosition();
    LPPositionSet<DoubleCoordinates> set = new LPPositionSet<>(DoubleCoordinates.class);
    set.addFrom(LineTubeRenderer.tubeLine.get(orientation.getRenderOrientation()).bounds().toAABB());
    set.stream().forEach(o -> o.add(pos));
    AxisAlignedBB box = set.toABB();
    if (box != null && (axisalignedbb == null || axisalignedbb.intersectsWith(box))) {
        arraylist.add(box);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) LPPositionSet(logisticspipes.utils.LPPositionSet) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Aggregations

AxisAlignedBB (net.minecraft.util.AxisAlignedBB)123 Entity (net.minecraft.entity.Entity)40 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)24 TileEntity (net.minecraft.tileentity.TileEntity)20 Vec3 (net.minecraft.util.Vec3)20 ArrayList (java.util.ArrayList)16 ItemStack (net.minecraft.item.ItemStack)16 List (java.util.List)15 Block (net.minecraft.block.Block)15 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 EntityItem (net.minecraft.entity.item.EntityItem)13 SideOnly (cpw.mods.fml.relauncher.SideOnly)10 World (net.minecraft.world.World)7 Pos (com.builtbroken.mc.imp.transform.vector.Pos)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 Iterator (java.util.Iterator)5 BlockPos (net.minecraft.util.BlockPos)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4