use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class PacketDecal method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
decalName = in.readUTF();
Vector3d position = new Vector3d();
position.x = (in.readDouble());
position.y = (in.readDouble());
position.z = (in.readDouble());
Vector3d orientation = new Vector3d();
orientation.x = (in.readDouble());
orientation.y = (in.readDouble());
orientation.z = (in.readDouble());
Vector3d size = new Vector3d();
size.x = (in.readDouble());
size.y = (in.readDouble());
size.z = (in.readDouble());
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
cpp.getContext().getDecalsManager().drawDecal(position, orientation, size, decalName);
}
}
use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class EntityComponentRotation method getDirectionLookingAt.
/**
* @return A vector3d for the direction
*/
public Vector3dc getDirectionLookingAt() {
Vector3d direction = new Vector3d();
double a = ((-getHorizontalRotation()) / 360f * 2 * Math.PI);
double b = ((getVerticalRotation()) / 360f * 2 * Math.PI);
direction.x = (-Math.sin(a) * Math.cos(b));
direction.y = (-Math.sin(b));
direction.z = (-Math.cos(a) * Math.cos(b));
return direction.normalize();
}
use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class EntityBase method moveWithoutCollisionRestrain.
@Override
public void moveWithoutCollisionRestrain(double mx, double my, double mz) {
Vector3d pos = new Vector3d(positionComponent.getLocation());
pos.x = (pos.x() + mx);
pos.y = (pos.y() + my);
pos.z = (pos.z() + mz);
positionComponent.setPosition(pos);
}
use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class Math2 method mix.
public static Vector3d mix(Vector3d a, Vector3d b, double f) {
Vector3d vec = new Vector3d();
vec.x = (mixd(a.x, b.x, f));
vec.y = (mixd(a.y, b.y, f));
vec.z = (mixd(a.z, b.z, f));
return vec;
}
use of org.joml.Vector3d in project chunkstories by Hugobros3.
the class ServerPlayer method updateTrackedEntities.
// Entity tracking
public void updateTrackedEntities() {
EntityControllable controlledEntity = this.controlledEntity;
if (controlledEntity == null)
return;
// Cache (idk if HotSpot makes it redudant but whatever)
double world_size = controlledEntity.getWorld().getWorldSize();
Location controlledEntityLocation = controlledEntity.getLocation();
double ENTITY_VISIBILITY_SIZE = 192;
Iterator<Entity> inRangeEntitiesIterator = controlledEntity.getWorld().getEntitiesInBox(controlledEntityLocation, new Vector3d(ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE));
while (inRangeEntitiesIterator.hasNext()) {
Entity e = inRangeEntitiesIterator.next();
// && chunk != null;
boolean shouldTrack = e.shouldBeTrackedBy(this);
boolean contains = subscribedEntities.contains(e);
if (shouldTrack && !contains)
this.subscribe(e);
if (!shouldTrack && contains)
this.unsubscribe(e);
}
Iterator<Entity> subscribedEntitiesIterator = subscribedEntities.iterator();
while (subscribedEntitiesIterator.hasNext()) {
Entity e = subscribedEntitiesIterator.next();
Location loc = e.getLocation();
// Distance calculations
double dx = LoopingMathHelper.moduloDistance(controlledEntityLocation.x(), loc.x(), world_size);
double dy = Math.abs(controlledEntityLocation.y() - loc.y());
double dz = LoopingMathHelper.moduloDistance(controlledEntityLocation.z(), loc.z(), world_size);
boolean inRange = (dx < ENTITY_VISIBILITY_SIZE && dz < ENTITY_VISIBILITY_SIZE && dy < ENTITY_VISIBILITY_SIZE);
// Reasons other than distance to stop tracking this entity
if (!e.shouldBeTrackedBy(this) || !inRange)
this.unsubscribe(e);
// No need to do anything as the component system handles the updates
}
}
Aggregations