diff --git a/engine/src/main/java/org/terasology/engine/world/chunks/Chunk.java b/engine/src/main/java/org/terasology/engine/world/chunks/Chunk.java index 29ebc0a06b0..c2049c49874 100644 --- a/engine/src/main/java/org/terasology/engine/world/chunks/Chunk.java +++ b/engine/src/main/java/org/terasology/engine/world/chunks/Chunk.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.world.chunks; @@ -35,7 +35,9 @@ public interface Chunk extends RenderableChunk { * @deprecated use {@link #getPosition()} */ @Deprecated - Vector3i getPosition(Vector3i dest); + default Vector3i getPosition(Vector3i dest) { + return dest.set(getPosition()); + } /** * Returns block at given position relative to the chunk. @@ -43,7 +45,9 @@ public interface Chunk extends RenderableChunk { * @param pos Position of the block relative to corner of the chunk * @return Block at given position */ - Block getBlock(Vector3ic pos); + default Block getBlock(Vector3ic pos) { + return getBlock(pos.x(), pos.y(), pos.z()); + } /** * Returns block at given position relative to the chunk. @@ -73,7 +77,9 @@ public interface Chunk extends RenderableChunk { * @param block Block to set block at given position to * @return Old Block at given position */ - Block setBlock(Vector3ic pos, Block block); + default Block setBlock(Vector3ic pos, Block block) { + return setBlock(pos.x(), pos.y(), pos.z(), block); + } /** * Sets one of the per-block custom data values at a given position relative to the chunk. @@ -97,7 +103,9 @@ public interface Chunk extends RenderableChunk { * @param pos Position of the block relative to the corner of the chunk * @param value New value to set the block to */ - void setExtraData(int index, Vector3ic pos, int value); + default void setExtraData(int index, Vector3ic pos, int value) { + setExtraData(index, pos.x(), pos.y(), pos.z(), value); + } /** * Returns one of the per-block custom data values at a given position relative to the chunk. @@ -117,7 +125,9 @@ public interface Chunk extends RenderableChunk { * @param pos Position of the block relative to the corner of the chunk * @return Selected extra data value at the given location */ - int getExtraData(int index, Vector3ic pos); + default int getExtraData(int index, Vector3ic pos) { + return getExtraData(index, pos.x(), pos.y(), pos.z()); + } /** @@ -160,7 +170,9 @@ default Vector3f getRenderPosition() { * @param dest Position in this chunk you want to transform * @return Transformed position */ - Vector3i chunkToWorldPosition(Vector3ic blockPos, Vector3i dest); + default Vector3i chunkToWorldPosition(Vector3ic blockPos, Vector3i dest) { + return chunkToWorldPosition(blockPos.x(), blockPos.y(), blockPos.z(), dest); + } /** @@ -202,29 +214,38 @@ default Vector3f getRenderPosition() { /** * @return Size of the chunk along the X axis. */ - int getChunkSizeX(); + default int getChunkSizeX() { + return Chunks.SIZE_X; + } /** * @return Size of the chunk along the Y axis. */ - int getChunkSizeY(); + default int getChunkSizeY() { + return Chunks.SIZE_Y; + } /** * @return Size of the chunk along the Z axis. */ - int getChunkSizeZ(); + default int getChunkSizeZ() { + return Chunks.SIZE_Z; + } /** * @return Chunk's Region */ BlockRegionc getRegion(); + /** * Returns the current amount of sunlight at given position relative to the chunk. * * @param pos Position of the block relative to corner of the chunk * @return Current sunlight */ - byte getSunlight(Vector3ic pos); + default byte getSunlight(Vector3ic pos) { + return getSunlight(pos.x(), pos.y(), pos.z()); + } /** * Returns the current amount of sunlight at given position relative to the chunk. @@ -243,7 +264,9 @@ default Vector3f getRenderPosition() { * @param amount Amount of sunlight to set this block to * @return False if the amount is same as the old value, true otherwise */ - boolean setSunlight(Vector3ic pos, byte amount); + default boolean setSunlight(Vector3ic pos, byte amount) { + return setSunlight(pos.x(), pos.y(), pos.z(), amount); + } /** * Sets the amount of sunlight at given position relative to the chunk. @@ -261,7 +284,9 @@ default Vector3f getRenderPosition() { * @param pos Position of the block relative to corner of the chunk * @return Current sunlight regeneration */ - byte getSunlightRegen(Vector3ic pos); + default byte getSunlightRegen(Vector3ic pos) { + return getSunlightRegen(pos.x(), pos.y(), pos.z()); + } /** * Returns current value of sunlight regeneration for given block relative to the chunk. @@ -280,7 +305,9 @@ default Vector3f getRenderPosition() { * @param amount Sunlight regeneration amount * @return False if the amount is same as the old value, true otherwise */ - boolean setSunlightRegen(Vector3ic pos, byte amount); + default boolean setSunlightRegen(Vector3ic pos, byte amount) { + return setSunlightRegen(pos.x(), pos.y(), pos.z(), amount); + } /** * Sets sunlight regeneration for given block relative to the chunk. @@ -299,7 +326,9 @@ default Vector3f getRenderPosition() { * @param pos Position of the block relative to corner of the chunk * @return Current lightness */ - byte getLight(Vector3ic pos); + default byte getLight(Vector3ic pos) { + return getLight(pos.x(), pos.y(), pos.z()); + } /** * Returns current amount of light for given block relative to the chunk. @@ -318,7 +347,9 @@ default Vector3f getRenderPosition() { * @param amount Lightness value * @return False if the amount is same as the old value, true otherwise */ - boolean setLight(Vector3ic pos, byte amount); + default boolean setLight(Vector3ic pos, byte amount) { + return setLight(pos.x(), pos.y(), pos.z(), amount); + } /** * Sets lightness for given block relative to the chunk. diff --git a/engine/src/main/java/org/terasology/engine/world/chunks/internal/ChunkImpl.java b/engine/src/main/java/org/terasology/engine/world/chunks/internal/ChunkImpl.java index 876e5cdbb25..e67c3bc6a20 100644 --- a/engine/src/main/java/org/terasology/engine/world/chunks/internal/ChunkImpl.java +++ b/engine/src/main/java/org/terasology/engine/world/chunks/internal/ChunkImpl.java @@ -1,4 +1,4 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.world.chunks.internal; @@ -8,15 +8,7 @@ import org.joml.Vector3ic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager; -import org.terasology.engine.world.chunks.blockdata.TeraArray; -import org.terasology.engine.world.chunks.blockdata.TeraDenseArray16Bit; -import org.terasology.engine.world.chunks.blockdata.TeraDenseArray8Bit; -import org.terasology.engine.world.chunks.blockdata.TeraSparseArray8Bit; -import org.terasology.joml.geom.AABBf; -import org.terasology.joml.geom.AABBfc; import org.terasology.engine.monitoring.chunk.ChunkMonitor; -import org.terasology.protobuf.EntityData; import org.terasology.engine.rendering.primitives.ChunkMesh; import org.terasology.engine.world.block.Block; import org.terasology.engine.world.block.BlockManager; @@ -24,8 +16,16 @@ import org.terasology.engine.world.chunks.Chunk; import org.terasology.engine.world.chunks.ChunkBlockIterator; import org.terasology.engine.world.chunks.Chunks; +import org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager; +import org.terasology.engine.world.chunks.blockdata.TeraArray; +import org.terasology.engine.world.chunks.blockdata.TeraDenseArray16Bit; +import org.terasology.engine.world.chunks.blockdata.TeraDenseArray8Bit; +import org.terasology.engine.world.chunks.blockdata.TeraSparseArray8Bit; import org.terasology.engine.world.chunks.deflate.TeraDeflator; import org.terasology.engine.world.chunks.deflate.TeraStandardDeflator; +import org.terasology.joml.geom.AABBf; +import org.terasology.joml.geom.AABBfc; +import org.terasology.protobuf.EntityData; import java.text.DecimalFormat; @@ -89,10 +89,10 @@ public ChunkImpl(Vector3ic chunkPos, TeraArray blocks, TeraArray[] extra, BlockM dirty = true; this.blockManager = blockManager; region = new BlockRegion( - chunkPos.x() * Chunks.SIZE_X, - chunkPos.y() * Chunks.SIZE_Y, - chunkPos.z() * Chunks.SIZE_Z) - .setSize(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z); + chunkPos.x() * getChunkSizeX(), + chunkPos.y() * getChunkSizeY(), + chunkPos.z() * getChunkSizeZ()) + .setSize(getChunkSizeX(), getChunkSizeY(), getChunkSizeZ()); ChunkMonitor.fireChunkCreated(this); } @@ -101,11 +101,6 @@ public Vector3ic getPosition() { return chunkPos; } - @Override - public Vector3i getPosition(Vector3i dest) { - return dest.set(chunkPos.x(), chunkPos.y(), chunkPos.z()); - } - @Override public boolean isDirty() { return dirty; @@ -130,12 +125,6 @@ public int getEstimatedMemoryConsumptionInBytes() { } - @Override - public Block getBlock(Vector3ic pos) { - short id = (short) blockData.get(pos.x(), pos.y(), pos.z()); - return blockManager.getBlock(id); - } - @Override public final Block getBlock(int x, int y, int z) { short id = (short) blockData.get(x, y, z); @@ -154,68 +143,33 @@ public Block setBlock(int x, int y, int z, Block block) { return blockManager.getBlock((short) oldValue); } - @Override - public Block setBlock(Vector3ic pos, Block block) { - return setBlock(pos.x(), pos.y(), pos.z(), block); - } - - @Override - public byte getSunlight(Vector3ic pos) { - return getSunlight(pos.x(), pos.y(), pos.z()); - } - @Override public byte getSunlight(int x, int y, int z) { return (byte) sunlightData.get(x, y, z); } - @Override - public boolean setSunlight(Vector3ic pos, byte amount) { - return setSunlight(pos.x(), pos.y(), pos.z(), amount); - } - @Override public boolean setSunlight(int x, int y, int z, byte amount) { Preconditions.checkArgument(amount >= 0 && amount <= Chunks.MAX_SUNLIGHT); return sunlightData.set(x, y, z, amount) != amount; } - @Override - public byte getSunlightRegen(Vector3ic pos) { - return getSunlightRegen(pos.x(), pos.y(), pos.z()); - } - @Override public byte getSunlightRegen(int x, int y, int z) { return (byte) sunlightRegenData.get(x, y, z); } - @Override - public boolean setSunlightRegen(Vector3ic pos, byte amount) { - return setSunlightRegen(pos.x(), pos.y(), pos.z(), amount); - } - @Override public boolean setSunlightRegen(int x, int y, int z, byte amount) { Preconditions.checkArgument(amount >= 0 && amount <= Chunks.MAX_SUNLIGHT_REGEN); return sunlightRegenData.set(x, y, z, amount) != amount; } - @Override - public byte getLight(Vector3ic pos) { - return getLight(pos.x(), pos.y(), pos.z()); - } - @Override public byte getLight(int x, int y, int z) { return (byte) lightData.get(x, y, z); } - @Override - public boolean setLight(Vector3ic pos, byte amount) { - return setLight(pos.x(), pos.y(), pos.z(), amount); - } - @Override public boolean setLight(int x, int y, int z, byte amount) { Preconditions.checkArgument(amount >= 0 && amount <= Chunks.MAX_LIGHT); @@ -227,11 +181,6 @@ public int getExtraData(int index, int x, int y, int z) { return extraData[index].get(x, y, z); } - @Override - public int getExtraData(int index, Vector3ic pos) { - return getExtraData(index, pos.x(), pos.y(), pos.z()); - } - @Override public void setExtraData(int index, int x, int y, int z, int value) { if (extraDataSnapshots != null && extraData[index] == extraDataSnapshots[index]) { @@ -240,11 +189,6 @@ public void setExtraData(int index, int x, int y, int z, int value) { extraData[index].set(x, y, z, value); } - @Override - public void setExtraData(int index, Vector3ic pos, int value) { - setExtraData(index, pos.x(), pos.y(), pos.z(), value); - } - @Override public Vector3i getChunkWorldOffset(Vector3i dest) { return dest.set(getChunkWorldOffsetX(), getChunkWorldOffsetY(), getChunkWorldOffsetZ()); @@ -265,11 +209,6 @@ public int getChunkWorldOffsetZ() { return chunkPos.z() * getChunkSizeZ(); } - @Override - public Vector3i chunkToWorldPosition(Vector3ic blockPos, Vector3i dest) { - return chunkToWorldPosition(blockPos.x(), blockPos.y(), blockPos.z(), dest); - } - @Override public Vector3i chunkToWorldPosition(int x, int y, int z, Vector3i dest) { return dest.set(chunkToWorldPositionX(x), chunkToWorldPositionY(y), chunkToWorldPositionZ(z)); @@ -466,10 +405,10 @@ public void markReady() { public void prepareForReactivation() { if (disposed) { disposed = false; - sunlightData = new TeraDenseArray8Bit(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z); - sunlightRegenData = new TeraDenseArray8Bit(Chunks.SIZE_X, Chunks.SIZE_Y, - Chunks.SIZE_Z); - lightData = new TeraDenseArray8Bit(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z); + sunlightData = new TeraDenseArray8Bit(getChunkSizeX(), getChunkSizeY(), getChunkSizeZ()); + sunlightRegenData = new TeraDenseArray8Bit(getChunkSizeX(), getChunkSizeY(), + getChunkSizeZ()); + lightData = new TeraDenseArray8Bit(getChunkSizeX(), getChunkSizeY(), getChunkSizeZ()); } } @@ -507,21 +446,6 @@ public BlockRegion getRegion() { return region; } - @Override - public int getChunkSizeX() { - return Chunks.SIZE_X; - } - - @Override - public int getChunkSizeY() { - return Chunks.SIZE_Y; - } - - @Override - public int getChunkSizeZ() { - return Chunks.SIZE_Z; - } - @Override public ChunkBlockIterator getBlockIterator() { return new ChunkBlockIteratorImpl(blockManager, getChunkWorldOffset(new Vector3i()), blockData); diff --git a/engine/src/main/java/org/terasology/engine/world/chunks/internal/PreLodChunk.java b/engine/src/main/java/org/terasology/engine/world/chunks/internal/PreLodChunk.java index 415b6743fd6..75911f16685 100644 --- a/engine/src/main/java/org/terasology/engine/world/chunks/internal/PreLodChunk.java +++ b/engine/src/main/java/org/terasology/engine/world/chunks/internal/PreLodChunk.java @@ -1,13 +1,13 @@ -// Copyright 2021 The Terasology Foundation +// Copyright 2022 The Terasology Foundation // SPDX-License-Identifier: Apache-2.0 package org.terasology.engine.world.chunks.internal; import org.joml.Vector3i; -import org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager; import org.terasology.engine.world.block.BlockManager; import org.terasology.engine.world.block.BlockRegion; import org.terasology.engine.world.chunks.Chunks; +import org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager; /** * A chunk that has a full set of data, but will be turned into @@ -22,16 +22,16 @@ public PreLodChunk(Vector3i pos, BlockManager blockManager, ExtraBlockDataManage @Override public int getChunkWorldOffsetX() { - return chunkPos.x() * (Chunks.SIZE_X - 2) - 1; + return chunkPos.x() * (getChunkSizeX() - 2) - 1; } @Override public int getChunkWorldOffsetY() { - return chunkPos.y() * (Chunks.SIZE_Y - 4) - 2; + return chunkPos.y() * (getChunkSizeY() - 4) - 2; } @Override public int getChunkWorldOffsetZ() { - return chunkPos.z() * (Chunks.SIZE_Z - 2) - 1; + return chunkPos.z() * (getChunkSizeZ() - 2) - 1; } }