From a6fd81ba1e81900bf424ab6e9592037f9830ee58 Mon Sep 17 00:00:00 2001 From: OLEGSHA Date: Mon, 16 Aug 2021 13:05:57 +0300 Subject: [PATCH] Contexts now only accept RelFace; fixed tile placement crash --- .../world/context/BlockDataContext.java | 6 +- .../world/context/BlockDataContextRO.java | 6 +- .../context/BlockGenericContextRO.java | 17 +++--- .../context/BlockGenericContextWO.java | 11 ++-- .../world/generic/context/WorldContexts.java | 8 +-- .../context/WorldGenericContextRO.java | 58 ++----------------- .../context/WorldGenericContextWO.java | 5 +- .../common/world/tile/PacketAddTile.java | 2 +- .../common/world/tile/PacketAffectTile.java | 14 +++-- .../world/context/ServerBlockContext.java | 10 ++-- .../world/context/ServerBlockContextRO.java | 10 ++-- .../impl/DefaultServerContextImpl.java | 16 ++--- .../impl/DefaultServerContextLogic.java | 13 ++--- .../context/impl/FilterServerContext.java | 17 +++--- .../context/impl/ReportingServerContext.java | 5 +- .../impl/TransformingServerContext.java | 33 +++++------ .../windcorp/progressia/test/TestContent.java | 2 +- .../progressia/test/TestTileLogicGrass.java | 4 +- 18 files changed, 94 insertions(+), 143 deletions(-) diff --git a/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContext.java b/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContext.java index 36e7dbe..e535014 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContext.java +++ b/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContext.java @@ -21,8 +21,8 @@ import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.generic.context.BlockGenericContextWO; -import ru.windcorp.progressia.common.world.rels.AbsRelation; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; import ru.windcorp.progressia.common.world.tile.TileData; public interface BlockDataContext @@ -45,8 +45,8 @@ public interface BlockDataContext } @Override - default BlockDataContext pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default BlockDataContext pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContextRO.java b/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContextRO.java index 8d75845..621cc9a 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContextRO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/context/BlockDataContextRO.java @@ -21,8 +21,8 @@ import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.generic.context.BlockGenericContextRO; -import ru.windcorp.progressia.common.world.rels.AbsRelation; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; import ru.windcorp.progressia.common.world.tile.TileData; public interface BlockDataContextRO @@ -44,8 +44,8 @@ public interface BlockDataContextRO } @Override - default BlockDataContextRO pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default BlockDataContextRO pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextRO.java b/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextRO.java index cacbe45..8984ad3 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextRO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextRO.java @@ -20,9 +20,8 @@ package ru.windcorp.progressia.common.world.generic.context; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.Context; import ru.windcorp.progressia.common.world.generic.*; -import ru.windcorp.progressia.common.world.rels.AbsRelation; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; /** * A {@link Context} referencing a world with a block location specified. The @@ -68,7 +67,7 @@ public interface BlockGenericContextRO< * @param layer the layer of the tile * @return {@code true} iff the tile exists */ - default boolean hasTile(BlockFace face, int layer) { + default boolean hasTile(RelFace face, int layer) { return hasTile(getLocation(), face, layer); } @@ -80,7 +79,7 @@ public interface BlockGenericContextRO< * @param tag the tag of the tile * @return {@code true} iff the tile exists */ - default boolean isTagValid(BlockFace face, int tag) { + default boolean isTagValid(RelFace face, int tag) { return isTagValid(getLocation(), face, tag); } @@ -97,7 +96,7 @@ public interface BlockGenericContextRO< * @param layer the layer of the tile stack that the tile occupies * @return the tile or {@code null} if the position does not contain a tile */ - default T getTile(BlockFace face, int layer) { + default T getTile(RelFace face, int layer) { return getTile(getLocation(), face, layer); } @@ -115,7 +114,7 @@ public interface BlockGenericContextRO< * @param tag the tag of the tile * @return the tile or {@code null} if the position does not contain a tile */ - default T getTileByTag(BlockFace face, int tag) { + default T getTileByTag(RelFace face, int tag) { return getTileByTag(getLocation(), face, tag); } @@ -129,7 +128,7 @@ public interface BlockGenericContextRO< * @return the count of tiles in the tile stack or {@code -1} if the tile * stack could not exist */ - default int getTileCount(BlockFace face) { + default int getTileCount(RelFace face) { return getTileCount(face); } @@ -148,8 +147,8 @@ public interface BlockGenericContextRO< } @Override - default BlockGenericContextRO pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default BlockGenericContextRO pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextWO.java b/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextWO.java index c1fa216..3555c09 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextWO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/context/BlockGenericContextWO.java @@ -20,9 +20,8 @@ package ru.windcorp.progressia.common.world.generic.context; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.Context; import ru.windcorp.progressia.common.world.generic.*; -import ru.windcorp.progressia.common.world.rels.AbsRelation; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; /** * A writable {@link Context} referencing a world with a block location @@ -59,7 +58,7 @@ public interface BlockGenericContextWO< * @param face the face of the block to add the tile to * @param tile the tile to add */ - default void addTile(BlockFace face, T tile) { + default void addTile(RelFace face, T tile) { addTile(getLocation(), face, tile); } @@ -72,7 +71,7 @@ public interface BlockGenericContextWO< * @param face the of the block to remove the tile from * @param tag the tag of the tile to remove */ - default void removeTile(BlockFace face, int tag) { + default void removeTile(RelFace face, int tag) { removeTile(getLocation(), face, tag); } @@ -91,8 +90,8 @@ public interface BlockGenericContextWO< } @Override - default BlockGenericContextWO pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default BlockGenericContextWO pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldContexts.java b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldContexts.java index 5cf9f44..f8953d3 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldContexts.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldContexts.java @@ -21,9 +21,9 @@ package ru.windcorp.progressia.common.world.generic.context; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.Context; import ru.windcorp.progressia.common.world.rels.AbsFace; -import ru.windcorp.progressia.common.world.rels.AbsRelation; import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; /** * This class defines several {@link Context} subinterfaces that are further @@ -139,7 +139,7 @@ class WorldContexts { * system * @return the face expressed in absolute coordinate system */ - AbsFace toAbsolute(BlockFace contextFace); + AbsFace toAbsolute(RelFace contextFace); /** * Converts the provided face given in the absolute coordinate @@ -221,8 +221,8 @@ class WorldContexts { * @return this object * @see #pop() */ - default Block pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default Block pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } /** diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextRO.java b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextRO.java index 59707e9..ec188d1 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextRO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextRO.java @@ -20,11 +20,9 @@ package ru.windcorp.progressia.common.world.generic.context; import java.util.Collection; import java.util.function.Consumer; -import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.Context; import ru.windcorp.progressia.common.world.generic.*; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; /** @@ -76,7 +74,7 @@ public interface WorldGenericContextRO< * @param layer the layer of the tile stack that the tile occupies * @return the tile or {@code null} if the position does not contain a tile */ - T getTile(Vec3i location, BlockFace face, int layer); + T getTile(Vec3i location, RelFace face, int layer); /** * Retrieves the tile at the specified position and the tile's tag. This @@ -92,7 +90,7 @@ public interface WorldGenericContextRO< * @param tag the tag of the tile * @return the tile or {@code null} if the position does not contain a tile */ - T getTileByTag(Vec3i location, BlockFace face, int tag); + T getTileByTag(Vec3i location, RelFace face, int tag); /** * Determines whether the specified position has a tile. @@ -102,7 +100,7 @@ public interface WorldGenericContextRO< * @param layer the layer of the tile * @return {@code true} iff the tile exists */ - boolean hasTile(Vec3i location, BlockFace face, int layer); + boolean hasTile(Vec3i location, RelFace face, int layer); /** * Determines whether the specified position has a tile with the given tag. @@ -112,7 +110,7 @@ public interface WorldGenericContextRO< * @param tag the tag of the tile * @return {@code true} iff the tile exists */ - boolean isTagValid(Vec3i location, BlockFace face, int tag); + boolean isTagValid(Vec3i location, RelFace face, int tag); /** * Counts the amount of tiles in the specified tile stack. @@ -124,7 +122,7 @@ public interface WorldGenericContextRO< * @return the count of tiles in the tile stack or {@code -1} if the tile * stack could not exist */ - int getTileCount(Vec3i location, BlockFace face); + int getTileCount(Vec3i location, RelFace face); /** * Retrieves a listing of all entities. {@link #forEachEntity(Consumer)} @@ -143,52 +141,6 @@ public interface WorldGenericContextRO< */ E getEntity(long entityId); - /* - * Convenience methods - */ - - /** - * Iterates all entities safely - */ - default void forEachEntity(Consumer action) { - getEntities().forEach(action); - } - - /** - * Iterates all entities in cuboid safely - */ - default void forEachEntityIn(Vec3i min, Vec3i max, Consumer action) { - forEachEntity(e -> { - Vec3 pos = e.getPosition(); - if (pos.x < min.x || pos.y < min.y || pos.z < min.z || pos.x > max.x || pos.y > max.y || pos.z > max.z) { - action.accept(e); - } - }); - } - - /** - * Iterates all entities in cuboid safely - */ - default void forEachEntityIn(Vec3 min, Vec3 max, Consumer action) { - forEachEntity(e -> { - Vec3 pos = e.getPosition(); - if (pos.x < min.x || pos.y < min.y || pos.z < min.z || pos.x > max.x || pos.y > max.y || pos.z > max.z) { - action.accept(e); - } - }); - } - - /** - * Iterates all entities with ID safely - */ - default void forEachEntityWithId(String id, Consumer action) { - forEachEntity(e -> { - if (id.equals(e.getId())) { - action.accept(e); - } - }); - } - /* * Subcontexting */ diff --git a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextWO.java b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextWO.java index 3f27b17..d1dac01 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextWO.java +++ b/src/main/java/ru/windcorp/progressia/common/world/generic/context/WorldGenericContextWO.java @@ -22,7 +22,6 @@ import ru.windcorp.progressia.common.state.StateChange; import ru.windcorp.progressia.common.state.StatefulObject; import ru.windcorp.progressia.common.world.context.Context; import ru.windcorp.progressia.common.world.generic.*; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; /** @@ -76,7 +75,7 @@ public interface WorldGenericContextWO< * @param face the face of the block to add the tile to * @param tile the tile to add */ - void addTile(Vec3i location, BlockFace face, T tile); + void addTile(Vec3i location, RelFace face, T tile); /** * Requests that a tile identified by its tag is removed from the specified @@ -88,7 +87,7 @@ public interface WorldGenericContextWO< * @param face the of the block to remove the tile from * @param tag the tag of the tile to remove */ - void removeTile(Vec3i location, BlockFace face, int tag); + void removeTile(Vec3i location, RelFace face, int tag); /** * Requests that the referenced tile is removed from its tile stack. If the diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java index 1655446..a2f805e 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAddTile.java @@ -44,7 +44,7 @@ public class PacketAddTile extends PacketAffectTile { } public void set(TileData tile, Vec3i blockInWorld, AbsFace face) { - super.set(blockInWorld, face, -1); + super.set(blockInWorld, face, TAG_NOT_APPLICABLE); this.tileId = tile.getId(); } diff --git a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java index 41cffef..747dfa6 100644 --- a/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java +++ b/src/main/java/ru/windcorp/progressia/common/world/tile/PacketAffectTile.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.common.world.tile; import java.io.DataInput; @@ -34,6 +34,12 @@ public abstract class PacketAffectTile extends PacketAffectChunk { private AbsFace face; private int tag; + /** + * Indicates to the safeguards in {@link #set(Vec3i, AbsFace, int)} that the + * concept of a tile tag is not applicable to this action. + */ + protected static final int TAG_NOT_APPLICABLE = -2; + public PacketAffectTile(String id) { super(id); } @@ -51,10 +57,10 @@ public abstract class PacketAffectTile extends PacketAffectChunk { } public void set(Vec3i blockInWorld, AbsFace face, int tag) { - if (tag < 0) { - throw new IllegalArgumentException("Cannot affect tile with tag -1"); + if (tag < 0 && tag != TAG_NOT_APPLICABLE) { + throw new IllegalArgumentException("Cannot affect tile with tag " + tag); } - + this.blockInWorld.set(blockInWorld.x, blockInWorld.y, blockInWorld.z); this.face = face; this.tag = tag; diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContext.java b/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContext.java index 6b66ba0..e0b5c70 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContext.java @@ -19,8 +19,8 @@ package ru.windcorp.progressia.server.world.context; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.BlockDataContext; -import ru.windcorp.progressia.common.world.rels.AbsRelation; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; public interface ServerBlockContext extends BlockDataContext, ServerWorldContext, ServerBlockContextRO { @@ -40,8 +40,8 @@ public interface ServerBlockContext extends BlockDataContext, ServerWorldContext } @Override - default ServerBlockContext.Logic pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default ServerBlockContext.Logic pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override @@ -70,8 +70,8 @@ public interface ServerBlockContext extends BlockDataContext, ServerWorldContext } @Override - default ServerBlockContext pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default ServerBlockContext pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContextRO.java b/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContextRO.java index 8ef355e..1fdb90e 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContextRO.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/ServerBlockContextRO.java @@ -21,8 +21,8 @@ import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.context.BlockDataContextRO; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.generic.context.BlockGenericContextRO; -import ru.windcorp.progressia.common.world.rels.AbsRelation; import ru.windcorp.progressia.common.world.rels.RelFace; +import ru.windcorp.progressia.common.world.rels.RelRelation; import ru.windcorp.progressia.server.world.block.BlockLogic; import ru.windcorp.progressia.server.world.tile.TileLogic; @@ -45,8 +45,8 @@ public interface ServerBlockContextRO extends ServerWorldContextRO, BlockDataCon } @Override - default ServerBlockContextRO.Logic pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default ServerBlockContextRO.Logic pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override @@ -75,8 +75,8 @@ public interface ServerBlockContextRO extends ServerWorldContextRO, BlockDataCon } @Override - default ServerBlockContextRO pushRelative(AbsRelation direction) { - return push(getLocation().add_(direction.getVector())); + default ServerBlockContextRO pushRelative(RelRelation direction) { + return push(getLocation().add_(direction.getRelVector())); } @Override diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextImpl.java b/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextImpl.java index aeda6e8..7d4f6cf 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextImpl.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextImpl.java @@ -318,7 +318,7 @@ class DefaultServerContextImpl extends DefaultServerContext } @Override - public AbsFace toAbsolute(BlockFace contextFace) { + public AbsFace toAbsolute(RelFace contextFace) { return contextFace.resolve(AbsFace.POS_Z); } @@ -362,19 +362,19 @@ class DefaultServerContextImpl extends DefaultServerContext } @Override - public TileData getTile(Vec3i location, BlockFace face, int layer) { + public TileData getTile(Vec3i location, RelFace face, int layer) { assert requireContextRole(Role.WORLD); return world.getTile(location, face, layer); } @Override - public boolean hasTile(Vec3i location, BlockFace face, int layer) { + public boolean hasTile(Vec3i location, RelFace face, int layer) { assert requireContextRole(Role.WORLD); return world.hasTile(location, face, layer); } @Override - public TileData getTileByTag(Vec3i location, BlockFace face, int tag) { + public TileData getTileByTag(Vec3i location, RelFace face, int tag) { assert requireContextRole(Role.WORLD); TileDataStack stack = world.getTilesOrNull(location, face); if (stack == null) @@ -386,7 +386,7 @@ class DefaultServerContextImpl extends DefaultServerContext } @Override - public boolean isTagValid(Vec3i location, BlockFace face, int tag) { + public boolean isTagValid(Vec3i location, RelFace face, int tag) { assert requireContextRole(Role.WORLD); TileDataStack stack = world.getTilesOrNull(location, face); if (stack == null) @@ -404,7 +404,7 @@ class DefaultServerContextImpl extends DefaultServerContext } @Override - public int getTileCount(Vec3i location, BlockFace face) { + public int getTileCount(Vec3i location, RelFace face) { assert requireContextRole(Role.TILE_STACK); TileDataStack stack = world.getTilesOrNull(frame.location, frame.face); if (stack == null) @@ -453,13 +453,13 @@ class DefaultServerContextImpl extends DefaultServerContext } @Override - public void addTile(Vec3i location, BlockFace face, TileData tile) { + public void addTile(Vec3i location, RelFace face, TileData tile) { assert requireContextRole(Role.WORLD); world.getTiles(location, face).addFarthest(tile); } @Override - public void removeTile(Vec3i location, BlockFace face, int tag) { + public void removeTile(Vec3i location, RelFace face, int tag) { assert requireContextRole(Role.WORLD); TileDataStack stack = world.getTilesOrNull(location, face); if (stack == null) diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextLogic.java b/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextLogic.java index 640a475..d6bb661 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextLogic.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/impl/DefaultServerContextLogic.java @@ -24,7 +24,6 @@ import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.rels.AbsFace; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.server.Server; @@ -97,7 +96,7 @@ public class DefaultServerContextLogic implements ServerTileContext.Logic { } @Override - public AbsFace toAbsolute(BlockFace contextFace) { + public AbsFace toAbsolute(RelFace contextFace) { return parent.toAbsolute(contextFace); } @@ -112,13 +111,13 @@ public class DefaultServerContextLogic implements ServerTileContext.Logic { } @Override - public TileLogic getTile(Vec3i location, BlockFace face, int layer) { + public TileLogic getTile(Vec3i location, RelFace face, int layer) { TileData data = parent.getTile(location, face, layer); return data == null ? null : TileLogicRegistry.getInstance().get(data.getId()); } @Override - public TileLogic getTileByTag(Vec3i location, BlockFace face, int tag) { + public TileLogic getTileByTag(Vec3i location, RelFace face, int tag) { TileData data = parent.getTileByTag(location, face, tag); return data == null ? null : TileLogicRegistry.getInstance().get(data.getId()); } @@ -129,12 +128,12 @@ public class DefaultServerContextLogic implements ServerTileContext.Logic { } @Override - public boolean hasTile(Vec3i location, BlockFace face, int layer) { + public boolean hasTile(Vec3i location, RelFace face, int layer) { return parent.hasTile(location, face, layer); } @Override - public boolean isTagValid(Vec3i location, BlockFace face, int tag) { + public boolean isTagValid(Vec3i location, RelFace face, int tag) { return parent.isTagValid(location, face, tag); } @@ -144,7 +143,7 @@ public class DefaultServerContextLogic implements ServerTileContext.Logic { } @Override - public int getTileCount(Vec3i location, BlockFace face) { + public int getTileCount(Vec3i location, RelFace face) { return parent.getTileCount(location, face); } diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/impl/FilterServerContext.java b/src/main/java/ru/windcorp/progressia/server/world/context/impl/FilterServerContext.java index 677f9d3..80c5073 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/impl/FilterServerContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/impl/FilterServerContext.java @@ -28,7 +28,6 @@ import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.generic.EntityGeneric; import ru.windcorp.progressia.common.world.rels.AbsFace; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.server.Server; @@ -99,12 +98,12 @@ public abstract class FilterServerContext implements ServerTileContext { } @Override - public void addTile(Vec3i location, BlockFace face, TileData tile) { + public void addTile(Vec3i location, RelFace face, TileData tile) { parent.addTile(location, face, tile); } @Override - public void removeTile(Vec3i location, BlockFace face, int tag) { + public void removeTile(Vec3i location, RelFace face, int tag) { parent.removeTile(location, face, tag); } @@ -149,27 +148,27 @@ public abstract class FilterServerContext implements ServerTileContext { } @Override - public TileData getTile(Vec3i location, BlockFace face, int layer) { + public TileData getTile(Vec3i location, RelFace face, int layer) { return parent.getTile(location, face, layer); } @Override - public TileData getTileByTag(Vec3i location, BlockFace face, int tag) { + public TileData getTileByTag(Vec3i location, RelFace face, int tag) { return parent.getTileByTag(location, face, tag); } @Override - public boolean hasTile(Vec3i location, BlockFace face, int layer) { + public boolean hasTile(Vec3i location, RelFace face, int layer) { return parent.hasTile(location, face, layer); } @Override - public boolean isTagValid(Vec3i location, BlockFace face, int tag) { + public boolean isTagValid(Vec3i location, RelFace face, int tag) { return parent.isTagValid(location, face, tag); } @Override - public int getTileCount(Vec3i location, BlockFace face) { + public int getTileCount(Vec3i location, RelFace face) { return parent.getTileCount(location, face); } @@ -212,7 +211,7 @@ public abstract class FilterServerContext implements ServerTileContext { } @Override - public AbsFace toAbsolute(BlockFace contextFace) { + public AbsFace toAbsolute(RelFace contextFace) { return parent.toAbsolute(contextFace); } diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/impl/ReportingServerContext.java b/src/main/java/ru/windcorp/progressia/server/world/context/impl/ReportingServerContext.java index 302a47f..732b2a0 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/impl/ReportingServerContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/impl/ReportingServerContext.java @@ -24,6 +24,7 @@ import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.generic.EntityGeneric; import ru.windcorp.progressia.common.world.rels.BlockFace; +import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.server.world.context.ServerTileContext; @@ -83,7 +84,7 @@ public class ReportingServerContext extends FilterServerContext { } @Override - public void addTile(Vec3i location, BlockFace face, TileData tile) { + public void addTile(Vec3i location, RelFace face, TileData tile) { if (passToParent) { super.addTile(location, face, tile); } @@ -93,7 +94,7 @@ public class ReportingServerContext extends FilterServerContext { } @Override - public void removeTile(Vec3i location, BlockFace face, int tag) { + public void removeTile(Vec3i location, RelFace face, int tag) { if (passToParent) { super.removeTile(location, face, tag); } diff --git a/src/main/java/ru/windcorp/progressia/server/world/context/impl/TransformingServerContext.java b/src/main/java/ru/windcorp/progressia/server/world/context/impl/TransformingServerContext.java index 1fb387e..9c0be6c 100644 --- a/src/main/java/ru/windcorp/progressia/server/world/context/impl/TransformingServerContext.java +++ b/src/main/java/ru/windcorp/progressia/server/world/context/impl/TransformingServerContext.java @@ -23,7 +23,6 @@ import java.util.List; import glm.vec._3.i.Vec3i; import ru.windcorp.progressia.common.world.block.BlockData; import ru.windcorp.progressia.common.world.rels.AbsFace; -import ru.windcorp.progressia.common.world.rels.BlockFace; import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.common.world.tile.TileData; import ru.windcorp.progressia.server.world.context.ServerBlockContext; @@ -163,8 +162,8 @@ public abstract class TransformingServerContext extends FilterServerContext { } @Override - public AbsFace toAbsolute(BlockFace contextFace) { - return super.toAbsolute(transform(contextFace.relativize(AbsFace.POS_Z))); + public AbsFace toAbsolute(RelFace contextFace) { + return super.toAbsolute(transform(contextFace)); } @Override @@ -206,77 +205,77 @@ public abstract class TransformingServerContext extends FilterServerContext { } @Override - public boolean hasTile(Vec3i userLocation, BlockFace userFace, int layer) { + public boolean hasTile(Vec3i userLocation, RelFace userFace, int layer) { Vec3i parentLocation = grabVector(userLocation); try { - return super.hasTile(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), layer); + return super.hasTile(parentLocation, transform(userFace), layer); } finally { releaseVector(parentLocation); } } @Override - public TileData getTile(Vec3i userLocation, BlockFace userFace, int layer) { + public TileData getTile(Vec3i userLocation, RelFace userFace, int layer) { Vec3i parentLocation = grabVector(userLocation); try { - return super.getTile(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), layer); + return super.getTile(parentLocation, transform(userFace), layer); } finally { releaseVector(parentLocation); } } @Override - public boolean isTagValid(Vec3i userLocation, BlockFace userFace, int tag) { + public boolean isTagValid(Vec3i userLocation, RelFace userFace, int tag) { Vec3i parentLocation = grabVector(userLocation); try { - return super.isTagValid(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), tag); + return super.isTagValid(parentLocation, transform(userFace), tag); } finally { releaseVector(parentLocation); } } @Override - public TileData getTileByTag(Vec3i userLocation, BlockFace userFace, int tag) { + public TileData getTileByTag(Vec3i userLocation, RelFace userFace, int tag) { Vec3i parentLocation = grabVector(userLocation); try { - return super.getTileByTag(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), tag); + return super.getTileByTag(parentLocation, transform(userFace), tag); } finally { releaseVector(parentLocation); } } @Override - public int getTileCount(Vec3i userLocation, BlockFace userFace) { + public int getTileCount(Vec3i userLocation, RelFace userFace) { Vec3i parentLocation = grabVector(userLocation); try { - return super.getTileCount(parentLocation, transform(userFace.relativize(AbsFace.POS_Z))); + return super.getTileCount(parentLocation, transform(userFace)); } finally { releaseVector(parentLocation); } } @Override - public void addTile(Vec3i userLocation, BlockFace userFace, TileData tile) { + public void addTile(Vec3i userLocation, RelFace userFace, TileData tile) { Vec3i parentLocation = grabVector(userLocation); try { - super.addTile(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), tile); + super.addTile(parentLocation, transform(userFace), tile); } finally { releaseVector(parentLocation); } } @Override - public void removeTile(Vec3i userLocation, BlockFace userFace, int tag) { + public void removeTile(Vec3i userLocation, RelFace userFace, int tag) { Vec3i parentLocation = grabVector(userLocation); try { - super.removeTile(parentLocation, transform(userFace.relativize(AbsFace.POS_Z)), tag); + super.removeTile(parentLocation, transform(userFace), tag); } finally { releaseVector(parentLocation); } diff --git a/src/main/java/ru/windcorp/progressia/test/TestContent.java b/src/main/java/ru/windcorp/progressia/test/TestContent.java index 7b9122f..fe972a4 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestContent.java +++ b/src/main/java/ru/windcorp/progressia/test/TestContent.java @@ -428,7 +428,7 @@ public class TestContent { return; if (server.getWorld().getData().getTiles(blockInWorld, face).isFull()) return; - server.createAbsoluteContext().addTile(blockInWorld, face, tile); + server.createAbsoluteContext().addTile(blockInWorld, face.relativize(AbsFace.POS_Z), tile); } private static void registerMisc() { diff --git a/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java b/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java index c197ce1..8a42bee 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java +++ b/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java @@ -18,7 +18,6 @@ package ru.windcorp.progressia.test; -import ru.windcorp.progressia.common.world.rels.AbsFace; import ru.windcorp.progressia.common.world.rels.RelFace; import ru.windcorp.progressia.server.world.block.BlockLogic; import ru.windcorp.progressia.server.world.context.ServerTileContext; @@ -65,8 +64,7 @@ public class TestTileLogicGrass extends HangingTileLogic implements TickableTile } private boolean isBlockAboveTransparent(ServerTileContextRO context) { - // TODO rework - context.pushRelative(RelFace.UP.resolve(AbsFace.POS_Z)); + context.pushRelative(RelFace.UP); BlockLogic block = context.logic().getBlock(); return context.popAndReturn(block == null || block.isTransparent(context)); }