Skip to content

Commit

Permalink
Allow GeyserWorldManager to be overwritten while still holding a cache (
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy authored Mar 14, 2021
1 parent ba64a7a commit 1d8961c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk
}

@Override
public boolean hasMoreBlockDataThanChunkCache() {
public boolean hasOwnChunkCache() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk
}

@Override
public boolean hasMoreBlockDataThanChunkCache() {
public boolean hasOwnChunkCache() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.utils.MathUtils;
Expand All @@ -38,14 +37,15 @@ public class ChunkCache {

private final boolean cache;

private final Long2ObjectMap<Column> chunks = new Long2ObjectOpenHashMap<>();
private final Long2ObjectMap<Column> chunks;

public ChunkCache(GeyserSession session) {
if (session.getConnector().getWorldManager().getClass() == GeyserBootstrap.DEFAULT_CHUNK_MANAGER.getClass()) {
this.cache = session.getConnector().getConfig().isCacheChunks();
} else {
if (session.getConnector().getWorldManager().hasOwnChunkCache()) {
this.cache = false; // To prevent Spigot from initializing
} else {
this.cache = session.getConnector().getConfig().isCacheChunks();
}
chunks = cache ? new Long2ObjectOpenHashMap<>() : null;
}

public Column addToCache(Column chunk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk
}

@Override
public boolean hasMoreBlockDataThanChunkCache() {
public boolean hasOwnChunkCache() {
// This implementation can only fetch data from the session chunk cache
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public int getBlockAt(GeyserSession session, Vector3i vector) {
public abstract void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk section);

/**
* Checks whether or not this world manager has access to more block data than the chunk cache.
* Checks whether or not this world manager requires a separate chunk cache/has access to more block data than the chunk cache.
* <p>
* Some world managers (e.g. Spigot) can provide access to block data outside of the chunk cache, and even with chunk caching disabled. This
* method provides a means to check if this manager has this capability.
*
* @return whether or not this world manager has access to more block data than the chunk cache
*/
public abstract boolean hasMoreBlockDataThanChunkCache();
public abstract boolean hasOwnChunkCache();

/**
* Gets the Java biome data for the specified chunk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static ChunkData translateToBedrock(GeyserSession session, Column column,
BitSet waterloggedPaletteIds = new BitSet();
BitSet pistonOrFlowerPaletteIds = new BitSet();

boolean worldManagerHasMoreBlockDataThanCache = session.getConnector().getWorldManager().hasMoreBlockDataThanChunkCache();
boolean worldManagerHasMoreBlockDataThanCache = session.getConnector().getWorldManager().hasOwnChunkCache();

// If the received packet was a full chunk update, null sections in the chunk are guaranteed to also be null in the world manager
boolean shouldCheckWorldManagerOnMissingSections = isNonFullChunk && worldManagerHasMoreBlockDataThanCache;
Expand Down

0 comments on commit 1d8961c

Please sign in to comment.