use of net.minecraft.util.Vec3 in project malmo by Microsoft.
the class ObservationFromRayImplementation method buildMouseOverData.
/** Build the json object for the object under the cursor, whether it is a block or a creature.<br>
* If there is any data to be returned, the json will be added in a subnode called "LineOfSight".
* @param json a JSON object into which the info for the object under the mouse will be added.
*/
public static void buildMouseOverData(JsonObject json) {
// We could use Minecraft.getMinecraft().objectMouseOver but it's limited to the block reach distance, and
// doesn't register floating tile items.
// Ideally use Minecraft.timer.renderPartialTicks - but we don't need sub-tick resolution.
float partialTicks = 0;
Entity viewer = Minecraft.getMinecraft().thePlayer;
// Hard-coded for now - in future will be parameterised via the XML.
float depth = 50;
Vec3 eyePos = viewer.getPositionEyes(partialTicks);
Vec3 lookVec = viewer.getLook(partialTicks);
Vec3 searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
MovingObjectPosition mop = Minecraft.getMinecraft().theWorld.rayTraceBlocks(eyePos, searchVec, false, false, false);
MovingObjectPosition mopEnt = findEntity(eyePos, lookVec, depth, mop, true);
if (mopEnt != null)
mop = mopEnt;
if (mop == null) {
// Nothing under the mouse.
return;
}
// Calculate ranges for player interaction:
double hitDist = mop.hitVec.distanceTo(eyePos);
double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
double entityReach = Minecraft.getMinecraft().playerController.extendedReach() ? 6.0 : 3.0;
JsonObject jsonMop = new JsonObject();
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
// We're looking at a block - send block data:
jsonMop.addProperty("hitType", "block");
jsonMop.addProperty("x", mop.hitVec.xCoord);
jsonMop.addProperty("y", mop.hitVec.yCoord);
jsonMop.addProperty("z", mop.hitVec.zCoord);
IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(mop.getBlockPos());
List<IProperty> extraProperties = new ArrayList<IProperty>();
DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(state, extraProperties);
jsonMop.addProperty("type", db.getType().value());
if (db.getColour() != null)
jsonMop.addProperty("colour", db.getColour().value());
if (db.getVariant() != null)
jsonMop.addProperty("variant", db.getVariant().getValue());
if (db.getFace() != null)
jsonMop.addProperty("facing", db.getFace().value());
if (extraProperties.size() > 0) {
// Add the extra properties that aren't covered by colour/variant/facing.
for (IProperty prop : extraProperties) {
String key = "prop_" + prop.getName();
if (prop.getValueClass() == Boolean.class)
jsonMop.addProperty(key, Boolean.valueOf(state.getValue(prop).toString()));
else if (prop.getValueClass() == Integer.class)
jsonMop.addProperty(key, Integer.valueOf(state.getValue(prop).toString()));
else
jsonMop.addProperty(key, state.getValue(prop).toString());
}
}
jsonMop.addProperty("inRange", hitDist <= blockReach);
jsonMop.addProperty("distance", hitDist);
} else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
// Looking at an entity:
Entity entity = mop.entityHit;
if (entity != null) {
jsonMop.addProperty("x", entity.posX);
jsonMop.addProperty("y", entity.posY);
jsonMop.addProperty("z", entity.posZ);
String name = entity.getName();
String hitType = "entity";
if (entity instanceof EntityItem) {
ItemStack is = ((EntityItem) entity).getEntityItem();
DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
if (di.getColour() != null)
jsonMop.addProperty("colour", di.getColour().value());
if (di.getVariant() != null)
jsonMop.addProperty("variant", di.getVariant().getValue());
jsonMop.addProperty("stackSize", is.stackSize);
name = di.getType();
hitType = "item";
}
jsonMop.addProperty("type", name);
jsonMop.addProperty("hitType", hitType);
}
jsonMop.addProperty("inRange", hitDist <= entityReach);
jsonMop.addProperty("distance", hitDist);
}
json.add("LineOfSight", jsonMop);
}
use of net.minecraft.util.Vec3 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.Vec3 in project BluePower by Qmunity.
the class GateNullCell method drawHighlight.
@Override
public boolean drawHighlight(QMovingObjectPosition mop, EntityPlayer player, float frame) {
Vec3d hit = new Vec3d(mop.hitVec).sub(mop.blockX, mop.blockY, mop.blockZ).rotateUndo(getFace(), Vec3d.center);
Vec3 pos = player.getPosition(frame);
ItemStack held = player.getCurrentEquippedItem();
if (held == null)
return false;
if (held.getItem() instanceof ItemPart) {
IPart part = ((ItemPart) held.getItem()).createPart(held, player, null, null);
if (part == null)
return false;
if (!(part instanceof PartRedwireFaceUninsulated))
return false;
PartRedwireFace wire = (PartRedwireFace) part;
RenderHelper renderer = RenderHelper.instance;
renderer.fullReset();
renderer.setRenderCoords(getWorld(), getX(), getY(), getZ());
double height = 2 / 16D;
IIcon wireIcon = IconSupplier.wire;
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
Tessellator.instance.startDrawingQuads();
Tessellator.instance.addTranslation((float) -pos.xCoord, (float) -pos.yCoord, (float) -pos.zCoord);
{
switch(getFace()) {
case DOWN:
break;
case UP:
renderer.addTransformation(new Rotation(180, 180, 0, Vec3d.center));
break;
case NORTH:
renderer.addTransformation(new Rotation(90, 0, 0, Vec3d.center));
break;
case SOUTH:
renderer.addTransformation(new Rotation(-90, 0, 0, Vec3d.center));
break;
case WEST:
renderer.addTransformation(new Rotation(0, 0, -90, Vec3d.center));
break;
case EAST:
renderer.addTransformation(new Rotation(0, 0, 90, Vec3d.center));
break;
default:
break;
}
int rotation = getRotation();
if (rotation != -1)
renderer.addTransformation(new Rotation(0, 90 * -rotation, 0));
renderer.setOpacity(0.5);
renderer.setColor(WireHelper.getColorForPowerLevel(wire.getRedwireType(ForgeDirection.UNKNOWN), (byte) (255 / 2)));
ForgeDirection dir = ForgeDirection.NORTH;
if (getRotation() % 2 == 1)
dir = dir.getRotation(getFace());
if (hit.getY() > 2 / 16D) {
if (typeB == null) {
renderer.renderBox(new Vec3dCube(0 / 16D, 2 / 16D, 7 / 16D, 2 / 16D, 10 / 16D, 9 / 16D), wireIcon);
renderer.renderBox(new Vec3dCube(14 / 16D, 2 / 16D, 7 / 16D, 16 / 16D, 10 / 16D, 9 / 16D), wireIcon);
renderer.renderBox(new Vec3dCube(0 / 16D, 10 / 16D, 7 / 16D, 16 / 16D, 12 / 16D, 9 / 16D), wireIcon);
}
} else {
if (typeA == null)
renderer.renderBox(new Vec3dCube(7 / 16D, 2 / 16D, 0 / 16D, 9 / 16D, 2 / 16D + height, 16 / 16D), wireIcon);
}
renderer.fullReset();
}
Tessellator.instance.addTranslation((float) pos.xCoord, (float) pos.yCoord, (float) pos.zCoord);
Tessellator.instance.draw();
GL11.glDisable(GL11.GL_BLEND);
return true;
} else if (held.getItem() instanceof IScrewdriver) {
// List<Vec3dCube> l = new ArrayList<Vec3dCube>();
// super.addBoxes(l);
// boolean def = false;
// for (Vec3dCube c : l)
// if (mop.getCube().equals(c.clone().rotate(getFace(), Vec3d.center).rotate(0, 90 * -getRotation(), 0, Vec3d.center)))
// def = true;
// if (def || hit.getY() <= 2 / 16D) {
// Vec3dCube c = Vec3dCube.merge(getSelectionBoxes()).expand(0.001);
//
// GL11.glEnable(GL11.GL_BLEND);
// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// GL11.glDisable(GL11.GL_TEXTURE_2D);
// GL11.glColor4f(0, 0, 0, 0.4F);
// GL11.glLineWidth(2);
// GL11.glDepthMask(true);
// GL11.glPushMatrix();
//
// Tessellator var2 = Tessellator.instance;
// var2.startDrawing(3);
// Tessellator.instance.addTranslation((float) -pos.xCoord + getX(), (float) -pos.yCoord + getY(), (float) -pos.zCoord
// + getZ());
// var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
// var2.draw();
// var2.startDrawing(3);
// var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
// var2.draw();
// var2.startDrawing(1);
// var2.addVertex(c.getMinX(), c.getMinY(), c.getMinZ());
// var2.addVertex(c.getMinX(), c.getMaxY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMinY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMinZ());
// var2.addVertex(c.getMaxX(), c.getMinY(), c.getMaxZ());
// var2.addVertex(c.getMaxX(), c.getMaxY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMinY(), c.getMaxZ());
// var2.addVertex(c.getMinX(), c.getMaxY(), c.getMaxZ());
// Tessellator.instance.addTranslation((float) pos.xCoord - getX(), (float) pos.yCoord - getY(), (float) pos.zCoord - getZ());
// var2.draw();
//
// GL11.glPopMatrix();
// GL11.glDepthMask(false);
// GL11.glEnable(GL11.GL_TEXTURE_2D);
// GL11.glDisable(GL11.GL_BLEND);
//
// return true;
// }
//
// return true;
}
return false;
}
use of net.minecraft.util.Vec3 in project LogisticsPipes by RS485.
the class LogisticsBlockGenericPipe method doRayTrace.
public RaytraceResult doRayTrace(World world, int x, int y, int z, EntityPlayer player) {
double reachDistance = 5;
if (player instanceof EntityPlayerMP) {
reachDistance = ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance();
}
double eyeHeight = world.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight();
Vec3 lookVec = player.getLookVec();
Vec3 origin = Vec3.createVectorHelper(player.posX, player.posY + eyeHeight, player.posZ);
Vec3 direction = origin.addVector(lookVec.xCoord * reachDistance, lookVec.yCoord * reachDistance, lookVec.zCoord * reachDistance);
return doRayTrace(world, x, y, z, origin, direction);
}
use of net.minecraft.util.Vec3 in project LogisticsPipes by RS485.
the class LogisticsBlockGenericPipe method collisionRayTrace.
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).pipe instanceof PipeBlockRequestTable) {
setBlockBoundsBasedOnState(world, x, y, z);
origin = origin.addVector((-x), (-y), (-z));
direction = direction.addVector((-x), (-y), (-z));
this.setBlockBounds(0, 0, 0, 1, 1, 1);
Vec3 vec32 = origin.getIntermediateWithXValue(direction, minX);
Vec3 vec33 = origin.getIntermediateWithXValue(direction, maxX);
Vec3 vec34 = origin.getIntermediateWithYValue(direction, minY);
Vec3 vec35 = origin.getIntermediateWithYValue(direction, maxY);
Vec3 vec36 = origin.getIntermediateWithZValue(direction, minZ);
Vec3 vec37 = origin.getIntermediateWithZValue(direction, maxZ);
if (!isVecInsideYZBounds(vec32)) {
vec32 = null;
}
if (!isVecInsideYZBounds(vec33)) {
vec33 = null;
}
if (!isVecInsideXZBounds(vec34)) {
vec34 = null;
}
if (!isVecInsideXZBounds(vec35)) {
vec35 = null;
}
if (!isVecInsideXYBounds(vec36)) {
vec36 = null;
}
if (!isVecInsideXYBounds(vec37)) {
vec37 = null;
}
Vec3 vec38 = null;
if (vec32 != null && (vec38 == null || origin.squareDistanceTo(vec32) < origin.squareDistanceTo(vec38))) {
vec38 = vec32;
}
if (vec33 != null && (vec38 == null || origin.squareDistanceTo(vec33) < origin.squareDistanceTo(vec38))) {
vec38 = vec33;
}
if (vec34 != null && (vec38 == null || origin.squareDistanceTo(vec34) < origin.squareDistanceTo(vec38))) {
vec38 = vec34;
}
if (vec35 != null && (vec38 == null || origin.squareDistanceTo(vec35) < origin.squareDistanceTo(vec38))) {
vec38 = vec35;
}
if (vec36 != null && (vec38 == null || origin.squareDistanceTo(vec36) < origin.squareDistanceTo(vec38))) {
vec38 = vec36;
}
if (vec37 != null && (vec38 == null || origin.squareDistanceTo(vec37) < origin.squareDistanceTo(vec38))) {
vec38 = vec37;
}
if (vec38 == null) {
return null;
} else {
byte b0 = -1;
if (vec38 == vec32) {
b0 = 4;
}
if (vec38 == vec33) {
b0 = 5;
}
if (vec38 == vec34) {
b0 = 0;
}
if (vec38 == vec35) {
b0 = 1;
}
if (vec38 == vec36) {
b0 = 2;
}
if (vec38 == vec37) {
b0 = 3;
}
return new MovingObjectPosition(x, y, z, b0, vec38.addVector(x, y, z));
}
}
RaytraceResult raytraceResult = doRayTrace(world, x, y, z, origin, direction);
if (raytraceResult == null) {
return null;
} else {
return raytraceResult.movingObjectPosition;
}
}
Aggregations