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

Renaming method variable #1123

Open
wants to merge 5 commits 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
4 changes: 2 additions & 2 deletions src/main/java/amidst/fragment/ClosestWorldIconFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public ClosestWorldIconFinder(
this.positionInWorld = positionInWorld;
this.closestIcon = null;
this.closestDistanceSq = maxDistanceInWorld * maxDistanceInWorld;
find();
findWorldIcon();
}

@CalledOnlyBy(AmidstThread.EDT)
private void find() {
private void findWorldIcon() {
for (FragmentGraphItem fragmentGraphItem : graph) {
Fragment fragment = fragmentGraphItem.getFragment();
for (LayerDeclaration declaration : declarations) {
Expand Down
39 changes: 4 additions & 35 deletions src/main/java/amidst/fragment/drawer/GridDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class GridDrawer extends FragmentDrawer {
private final StringBuffer textBuffer = new StringBuffer(128);
private final char[] textCache = new char[128];
private final Zoom zoom;
TextDrawer textDrawer = new TextDrawer();

public GridDrawer(LayerDeclaration declaration, Zoom zoom) {
super(declaration);
Expand All @@ -36,10 +37,10 @@ public void draw(Fragment fragment, Graphics2D g2d, float time) {
if (isGrid00(gridX, gridY)) {
double invZoom = 1.0 / zoom.getCurrentValue();
g2d.scale(invZoom, invZoom);
updateText(fragment);
drawText(g2d);
textDrawer.updateText(fragment);
textDrawer.drawText(g2d);
// drawThickTextOutline(g2d);
drawTextOutline(g2d);
textDrawer.drawTextOutline(g2d);
}
}

Expand Down Expand Up @@ -84,36 +85,4 @@ private void drawGridLines(Graphics2D g2d, int stride, int gridX, int gridY) {
private boolean isGrid00(int gridX, int gridY) {
return gridX == 0 && gridY == 0;
}

@CalledOnlyBy(AmidstThread.EDT)
private void updateText(Fragment fragment) {
textBuffer.setLength(0);
textBuffer.append(fragment.getCorner().getX());
textBuffer.append(", ");
textBuffer.append(fragment.getCorner().getY());
textBuffer.getChars(0, textBuffer.length(), textCache, 0);
}

@CalledOnlyBy(AmidstThread.EDT)
private void drawText(Graphics2D g2d) {
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 17);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 17);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 19);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 15);
}

// This makes the text outline a bit thicker, but seems unneeded.
@SuppressWarnings("unused")
private void drawThickTextOutline(Graphics2D g2d) {
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 15);
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 19);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 15);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 19);
}

@CalledOnlyBy(AmidstThread.EDT)
private void drawTextOutline(Graphics2D g2d) {
g2d.setColor(Color.white);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 17);
}
}
59 changes: 59 additions & 0 deletions src/main/java/amidst/fragment/drawer/TextDrawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package amidst.fragment.drawer;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import amidst.fragment.Fragment;
import amidst.mojangapi.world.coordinates.Resolution;

@NotThreadSafe
public class TextDrawer {

private static final Font DRAW_FONT = new Font("arial", Font.BOLD, 16);

private final StringBuffer textBuffer = new StringBuffer(128);
private final char[] textCache = new char[128];

@CalledOnlyBy(AmidstThread.EDT)
public void updateText(Fragment fragment) {
textBuffer.setLength(0);
textBuffer.append(fragment.getCorner().getX());
textBuffer.append(", ");
textBuffer.append(fragment.getCorner().getY());
textBuffer.getChars(0, textBuffer.length(), textCache, 0);
}

@CalledOnlyBy(AmidstThread.EDT)
public void drawText(Graphics2D g2d) {
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 17);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 17);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 19);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 15);
}

// This makes the text outline a bit thicker, but seems unneeded.
@SuppressWarnings("unused")
private void drawThickTextOutline(Graphics2D g2d) {
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 15);
g2d.drawChars(textCache, 0, textBuffer.length(), 12, 19);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 15);
g2d.drawChars(textCache, 0, textBuffer.length(), 8, 19);
}

@CalledOnlyBy(AmidstThread.EDT)
public void drawTextOutline(Graphics2D g2d) {
g2d.setColor(Color.white);
g2d.drawChars(textCache, 0, textBuffer.length(), 10, 17);
}

@CalledOnlyBy(AmidstThread.EDT)
public void initGraphics(Graphics2D g2d) {
g2d.setFont(DRAW_FONT);
g2d.setColor(Color.black);
}

}
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
Loading