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;
}
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);
}
}
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]);
}
}
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);
}
}
}
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);
}
}
Aggregations