Fixed RotatingServerContext

- RotatingServerContext now rotates coordinates, too
- Fixed a bug caused by the implementation of push methods by
TransformingServerContext
- Fixed unbounded recursion in WorldGenericRO.hasTile(Vec3i, BlockFace,
int)
This commit is contained in:
OLEGSHA 2021-08-15 23:54:25 +03:00
parent 54c66d28d6
commit 82872c7cf3
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
3 changed files with 30 additions and 12 deletions

View File

@ -137,7 +137,8 @@ public interface WorldGenericRO<
* @return {@code true} iff the tile exists
*/
default boolean hasTile(Vec3i location, BlockFace face, int layer) {
return hasTile(location, face, layer);
TS stack = getTilesOrNull(location, face);
return stack != null && stack.size() > layer;
}
default boolean isChunkLoaded(Vec3i chunkPos) {

View File

@ -19,6 +19,7 @@ package ru.windcorp.progressia.server.world.context.impl;
import glm.vec._3.i.Vec3i;
import ru.windcorp.progressia.common.world.rels.AbsFace;
import ru.windcorp.progressia.common.world.rels.AxisRotations;
import ru.windcorp.progressia.common.world.rels.RelFace;
import ru.windcorp.progressia.server.world.context.ServerTileContext;
@ -31,14 +32,18 @@ public class RotatingServerContext extends TransformingServerContext {
this.up = up;
}
public AbsFace getUp() {
return up;
}
@Override
protected void transform(Vec3i userLocation, Vec3i output) {
output.set(userLocation.x, userLocation.y, userLocation.z);
AxisRotations.resolve(userLocation, up, output);
}
@Override
protected void untransform(Vec3i parentLocation, Vec3i output) {
output.set(parentLocation.x, parentLocation.y, parentLocation.z);
AxisRotations.relativize(parentLocation, up, output);
}
@Override

View File

@ -35,7 +35,7 @@ public abstract class TransformingServerContext extends FilterServerContext {
private final Vec3i location = new Vec3i();
private boolean isLocationValid = false;
private RelFace face;
private RelFace face = null;
private final List<Vec3i> vectorCache = new ArrayList<>(1);
@ -107,28 +107,40 @@ public abstract class TransformingServerContext extends FilterServerContext {
@Override
public ServerBlockContext push(Vec3i userLocation) {
transform(userLocation, location);
Vec3i parentLocation = grabVector(userLocation);
super.push(parentLocation);
releaseVector(parentLocation);
location.set(userLocation.x, userLocation.y, userLocation.z);
isLocationValid = true;
super.push(location);
face = null;
return this;
}
@Override
public ServerTileStackContext push(Vec3i userLocation, RelFace userFace) {
transform(userLocation, location);
Vec3i parentLocation = grabVector(userLocation);
super.push(parentLocation, transform(userFace));
releaseVector(parentLocation);
location.set(userLocation.x, userLocation.y, userLocation.z);
isLocationValid = true;
face = transform(userFace);
super.push(location, face);
face = userFace;
return this;
}
@Override
public ServerTileContext push(Vec3i userLocation, RelFace userFace, int layer) {
transform(userLocation, location);
Vec3i parentLocation = grabVector(userLocation);
super.push(parentLocation, transform(userFace), layer);
releaseVector(parentLocation);
location.set(userLocation.x, userLocation.y, userLocation.z);
isLocationValid = true;
face = transform(userFace);
super.push(location, face, layer);
face = userFace;
return this;
}