Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Method Refactoring Implemented. #1128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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;
Expand All @@ -180,5 +189,16 @@ public<T> T getBiomeData(Dimension dimension,
public Set<Dimension> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/amidst/mojangapi/world/WorldBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down
19 changes: 16 additions & 3 deletions src/test/java/amidst/mojangapi/mocking/FakeMinecraftInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down