3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-03 08:21:06 +02:00

Allow GeyserWorldManager to be overwritten while still holding a cache (#2036)

Dieser Commit ist enthalten in:
Camotoy 2021-03-14 12:26:47 -04:00 committet von GitHub
Ursprung ba64a7a489
Commit 1d8961c498
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 11 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -52,7 +52,7 @@ public class GeyserSpigotFallbackWorldManager extends GeyserSpigotWorldManager {
} }
@Override @Override
public boolean hasMoreBlockDataThanChunkCache() { public boolean hasOwnChunkCache() {
return false; return false;
} }

Datei anzeigen

@ -140,7 +140,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
} }
@Override @Override
public boolean hasMoreBlockDataThanChunkCache() { public boolean hasOwnChunkCache() {
return true; return true;
} }

Datei anzeigen

@ -29,7 +29,6 @@ import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column; import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 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.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.utils.MathUtils; import org.geysermc.connector.utils.MathUtils;
@ -38,14 +37,15 @@ public class ChunkCache {
private final boolean cache; private final boolean cache;
private final Long2ObjectMap<Column> chunks = new Long2ObjectOpenHashMap<>(); private final Long2ObjectMap<Column> chunks;
public ChunkCache(GeyserSession session) { public ChunkCache(GeyserSession session) {
if (session.getConnector().getWorldManager().getClass() == GeyserBootstrap.DEFAULT_CHUNK_MANAGER.getClass()) { if (session.getConnector().getWorldManager().hasOwnChunkCache()) {
this.cache = session.getConnector().getConfig().isCacheChunks();
} else {
this.cache = false; // To prevent Spigot from initializing 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) { public Column addToCache(Column chunk) {

Datei anzeigen

@ -73,7 +73,7 @@ public class GeyserWorldManager extends WorldManager {
} }
@Override @Override
public boolean hasMoreBlockDataThanChunkCache() { public boolean hasOwnChunkCache() {
// This implementation can only fetch data from the session chunk cache // This implementation can only fetch data from the session chunk cache
return false; return false;
} }

Datei anzeigen

@ -88,14 +88,14 @@ public abstract class WorldManager {
public abstract void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk section); 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> * <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 * 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. * 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 * @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. * Gets the Java biome data for the specified chunk.

Datei anzeigen

@ -91,7 +91,7 @@ public class ChunkUtils {
BitSet waterloggedPaletteIds = new BitSet(); BitSet waterloggedPaletteIds = new BitSet();
BitSet pistonOrFlowerPaletteIds = 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 // 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; boolean shouldCheckWorldManagerOnMissingSections = isNonFullChunk && worldManagerHasMoreBlockDataThanCache;