From 65c49190cb664f65fd2e3bd17a1bdc1917d9f4c8 Mon Sep 17 00:00:00 2001 From: sarthakpatel Date: Wed, 5 Apr 2023 14:45:31 -0300 Subject: [PATCH] Move Method Refactoring Implemented. --- .../LoggingMinecraftInterface.java | 15 ++++++++++ .../MinecraftInterface.java | 5 ++++ .../legacy/BetaMinecraftInterface.java | 20 ++++++++++--- .../legacy/LegacyMinecraftInterface.java | 30 +++++++++++++++---- .../legacy/_1_13MinecraftInterface.java | 21 +++++++++---- .../legacy/_1_15MinecraftInterface.java | 21 +++++++++---- .../local/LocalMinecraftInterface.java | 21 +++++++++---- .../amidst/mojangapi/world/WorldBuilder.java | 15 ++-------- .../BenchmarkingMinecraftInterface.java | 19 ++++++++++-- .../mocking/FakeMinecraftInterface.java | 19 ++++++++++-- .../RequestStoringMinecraftInterface.java | 19 ++++++++++-- 11 files changed, 159 insertions(+), 46 deletions(-) diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/LoggingMinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/LoggingMinecraftInterface.java index cd4087e46..b72b96d42 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/LoggingMinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/LoggingMinecraftInterface.java @@ -5,7 +5,10 @@ import amidst.documentation.ThreadSafe; import amidst.logging.AmidstLogger; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; @ThreadSafe public class LoggingMinecraftInterface implements MinecraftInterface { @@ -55,4 +58,16 @@ public WorldAccessor createWorldAccessor(WorldOptions worldOptions) throws Minec public RecognisedVersion getRecognisedVersion() { return inner.getRecognisedVersion(); } + + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } } diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/MinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/MinecraftInterface.java index d52036836..d539ba2e0 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/MinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/MinecraftInterface.java @@ -5,7 +5,9 @@ import amidst.documentation.ThreadSafe; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; /** * Acts as an additional layer of abstraction for interfacing with Minecraft. @@ -21,6 +23,9 @@ public interface MinecraftInterface { public RecognisedVersion getRecognisedVersion(); + VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException; + /** * Represents a Minecraft world, allowing for querying of biome data. * diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/BetaMinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/BetaMinecraftInterface.java index c943f5586..5c87100a6 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/BetaMinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/BetaMinecraftInterface.java @@ -2,13 +2,13 @@ import amidst.clazz.symbolic.SymbolicClass; import amidst.clazz.symbolic.SymbolicObject; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; -import amidst.mojangapi.minecraftinterface.UnsupportedDimensionException; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.versionfeatures.DefaultBiomes; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; import amidst.util.ChunkBasedGen; import java.lang.reflect.InvocationTargetException; @@ -89,6 +89,18 @@ public RecognisedVersion getRecognisedVersion() { return recognisedVersion; } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private SymbolicObject constructDimension() throws IllegalAccessException, InstantiationException { return new SymbolicObject(dimensionBaseClass, dimensionOverworldClass.getClazz().newInstance()); } diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/LegacyMinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/LegacyMinecraftInterface.java index 699961a31..24b990d06 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/LegacyMinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/LegacyMinecraftInterface.java @@ -10,14 +10,13 @@ import amidst.clazz.symbolic.SymbolicClass; import amidst.clazz.symbolic.SymbolicObject; import amidst.documentation.ThreadSafe; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; -import amidst.mojangapi.minecraftinterface.ReflectionUtils; -import amidst.mojangapi.minecraftinterface.UnsupportedDimensionException; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.WorldType; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; @ThreadSafe /** @@ -154,6 +153,16 @@ private SymbolicObject getWorldType(WorldType worldType) throws IllegalArgumentE public RecognisedVersion getRecognisedVersion() { return recognisedVersion; } + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } private class WorldAccessor implements MinecraftInterface.WorldAccessor { private final Object quarterResolutionBiomeGenerator; @@ -180,5 +189,16 @@ public T getBiomeData(Dimension dimension, public Set supportedDimensions() { return Collections.singleton(Dimension.OVERWORLD); } + + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } } } diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_13MinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_13MinecraftInterface.java index 9a93beedc..2d1dd1301 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_13MinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_13MinecraftInterface.java @@ -12,14 +12,13 @@ import amidst.clazz.symbolic.SymbolicClass; import amidst.clazz.symbolic.SymbolicObject; import amidst.logging.AmidstLogger; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; -import amidst.mojangapi.minecraftinterface.ReflectionUtils; -import amidst.mojangapi.minecraftinterface.UnsupportedDimensionException; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.WorldType; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; import amidst.util.ArrayCache; public class _1_13MinecraftInterface implements MinecraftInterface { @@ -245,6 +244,18 @@ public RecognisedVersion getRecognisedVersion() { return recognisedVersion; } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private class WorldAccessor implements MinecraftInterface.WorldAccessor { /** * A GenLayer instance, at quarter scale to the final biome layer (i.e. both diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_15MinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_15MinecraftInterface.java index 31fdefa47..9669c8085 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_15MinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/legacy/_1_15MinecraftInterface.java @@ -25,14 +25,13 @@ import amidst.clazz.symbolic.SymbolicClass; import amidst.clazz.symbolic.SymbolicObject; import amidst.logging.AmidstLogger; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; -import amidst.mojangapi.minecraftinterface.ReflectionUtils; -import amidst.mojangapi.minecraftinterface.UnsupportedDimensionException; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.WorldType; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; import amidst.util.ArrayCache; public class _1_15MinecraftInterface implements MinecraftInterface { @@ -266,6 +265,18 @@ public RecognisedVersion getRecognisedVersion() { return recognisedVersion; } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private synchronized void initializeIfNeeded() throws MinecraftInterfaceException { if (isInitialized) { return; diff --git a/src/main/java/amidst/mojangapi/minecraftinterface/local/LocalMinecraftInterface.java b/src/main/java/amidst/mojangapi/minecraftinterface/local/LocalMinecraftInterface.java index 21a5739b1..342410b6c 100644 --- a/src/main/java/amidst/mojangapi/minecraftinterface/local/LocalMinecraftInterface.java +++ b/src/main/java/amidst/mojangapi/minecraftinterface/local/LocalMinecraftInterface.java @@ -20,14 +20,13 @@ import amidst.clazz.symbolic.SymbolicClass; import amidst.clazz.symbolic.SymbolicObject; import amidst.logging.AmidstLogger; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; -import amidst.mojangapi.minecraftinterface.ReflectionUtils; -import amidst.mojangapi.minecraftinterface.UnsupportedDimensionException; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.WorldType; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; import amidst.util.ArrayCache; public class LocalMinecraftInterface implements MinecraftInterface { @@ -187,6 +186,18 @@ public RecognisedVersion getRecognisedVersion() { return recognisedVersion; } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private synchronized void initializeIfNeeded() throws MinecraftInterfaceException { if (isInitialized) { return; diff --git a/src/main/java/amidst/mojangapi/world/WorldBuilder.java b/src/main/java/amidst/mojangapi/world/WorldBuilder.java index 54677eb43..b29d19fb1 100644 --- a/src/main/java/amidst/mojangapi/world/WorldBuilder.java +++ b/src/main/java/amidst/mojangapi/world/WorldBuilder.java @@ -46,7 +46,7 @@ public WorldBuilder(PlayerInformationProvider playerInformationProvider, SeedHis public World from( MinecraftInterface minecraftInterface, WorldOptions worldOptions) throws MinecraftInterfaceException { - VersionFeatures versionFeatures = initInterfaceAndGetFeatures(worldOptions, minecraftInterface); + VersionFeatures versionFeatures = minecraftInterface.initInterfaceAndGetFeatures(worldOptions, minecraftInterface, seedHistoryLogger); return create( minecraftInterface.getRecognisedVersion(), MovablePlayerList.dummy(), @@ -57,7 +57,7 @@ public World from( public World fromSaveGame(MinecraftInterface minecraftInterface, SaveGame saveGame) throws IOException, MinecraftInterfaceException { - VersionFeatures versionFeatures = initInterfaceAndGetFeatures(WorldOptions.fromSaveGame(saveGame), minecraftInterface); + VersionFeatures versionFeatures = minecraftInterface.initInterfaceAndGetFeatures(WorldOptions.fromSaveGame(saveGame), minecraftInterface, seedHistoryLogger); return create( minecraftInterface.getRecognisedVersion(), new MovablePlayerList( @@ -69,17 +69,6 @@ public World fromSaveGame(MinecraftInterface minecraftInterface, SaveGame saveGa new ImmutableWorldSpawnOracle(saveGame.getWorldSpawn())); } - private VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface) - throws MinecraftInterfaceException { - RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); - if(minecraftInterface instanceof LoggingMinecraftInterface) { - ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); - } - MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); - seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); - return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); - } - private World create( RecognisedVersion recognisedVersion, MovablePlayerList movablePlayerList, diff --git a/src/test/java/amidst/mojangapi/mocking/BenchmarkingMinecraftInterface.java b/src/test/java/amidst/mojangapi/mocking/BenchmarkingMinecraftInterface.java index ec2e3020d..b04fd76bf 100644 --- a/src/test/java/amidst/mojangapi/mocking/BenchmarkingMinecraftInterface.java +++ b/src/test/java/amidst/mojangapi/mocking/BenchmarkingMinecraftInterface.java @@ -6,12 +6,13 @@ import java.util.function.Function; import amidst.documentation.ThreadSafe; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.mocking.json.BiomeRequestRecordJson; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; @ThreadSafe public class BenchmarkingMinecraftInterface implements MinecraftInterface { @@ -33,6 +34,18 @@ public RecognisedVersion getRecognisedVersion() { return inner.getRecognisedVersion(); } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private class WorldAccessor implements MinecraftInterface.WorldAccessor { private final MinecraftInterface.WorldAccessor innerWorld; diff --git a/src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java b/src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java index 41e234db6..811b18961 100644 --- a/src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java +++ b/src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java @@ -5,13 +5,14 @@ import java.util.function.Function; import amidst.documentation.ThreadSafe; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; import amidst.mojangapi.world.testworld.storage.json.BiomeDataJson; import amidst.mojangapi.world.testworld.storage.json.WorldMetadataJson; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; @ThreadSafe public class FakeMinecraftInterface implements MinecraftInterface { @@ -43,6 +44,18 @@ public RecognisedVersion getRecognisedVersion() { return worldMetadataJson.getRecognisedVersion(); } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private class WorldAccessor implements MinecraftInterface.WorldAccessor { private WorldAccessor() { } diff --git a/src/test/java/amidst/mojangapi/mocking/RequestStoringMinecraftInterface.java b/src/test/java/amidst/mojangapi/mocking/RequestStoringMinecraftInterface.java index 8f10da5fe..625e29877 100644 --- a/src/test/java/amidst/mojangapi/mocking/RequestStoringMinecraftInterface.java +++ b/src/test/java/amidst/mojangapi/mocking/RequestStoringMinecraftInterface.java @@ -4,11 +4,12 @@ import java.util.function.Function; import amidst.documentation.ThreadSafe; -import amidst.mojangapi.minecraftinterface.MinecraftInterface; -import amidst.mojangapi.minecraftinterface.MinecraftInterfaceException; -import amidst.mojangapi.minecraftinterface.RecognisedVersion; +import amidst.mojangapi.minecraftinterface.*; import amidst.mojangapi.world.Dimension; +import amidst.mojangapi.world.SeedHistoryLogger; import amidst.mojangapi.world.WorldOptions; +import amidst.mojangapi.world.versionfeatures.DefaultVersionFeatures; +import amidst.mojangapi.world.versionfeatures.VersionFeatures; @ThreadSafe public class RequestStoringMinecraftInterface implements MinecraftInterface { @@ -34,6 +35,18 @@ public synchronized RecognisedVersion getRecognisedVersion() { return realMinecraftInterface.getRecognisedVersion(); } + @Override + public VersionFeatures initInterfaceAndGetFeatures(WorldOptions worldOptions, MinecraftInterface minecraftInterface, SeedHistoryLogger seedHistoryLogger) + throws MinecraftInterfaceException { + RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion(); + if(minecraftInterface instanceof LoggingMinecraftInterface) { + ((LoggingMinecraftInterface) minecraftInterface).logNextAccessor(); + } + MinecraftInterface.WorldAccessor worldAccessor = new ThreadedWorldAccessor(v -> minecraftInterface.createWorldAccessor(worldOptions)); + seedHistoryLogger.log(recognisedVersion, worldOptions.getWorldSeed()); + return DefaultVersionFeatures.builder(worldOptions, worldAccessor).create(recognisedVersion); + } + private class WorldAccessor implements MinecraftInterface.WorldAccessor { private final MinecraftInterface.WorldAccessor realMinecraftWorld;