Skip to content

Commit

Permalink
Merge pull request #493 from mircokroon/map-improvements
Browse files Browse the repository at this point in the history
Map & performance improvements
  • Loading branch information
mircokroon authored Mar 9, 2023
2 parents 822aa71 + 6a83a3a commit 7d86fa8
Show file tree
Hide file tree
Showing 60 changed files with 1,157 additions and 1,137 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Cross-platform jar (GUI & command-line): [world-downloader.jar](https://github.c
- Extend the client's render distance by sending chunks downloaded previously back to the client
- Overview map of chunks that have been saved:

<img src="https://i.imgur.com/nSM6mLw.png" width="50%" title="Example of the GUI showing previously downloaded chunks as white squares, chunks sent from the downloader to the client to extend the render distance in normal colours, and chunks sent by server directly to the client in red.">
<img src="https://i.imgur.com/7FIJ6fZ.png" width="80%" title="Example of the GUI showing previously downloaded chunks as white squares, chunks sent from the downloader to the client to extend the render distance in normal colours, and chunks sent by server directly to the client in red.">

### Requirements
- Java 17 or higher
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+ // 1.17+ // 1.18+ // 1.19+
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+ // 1.17+ // 1.18+ // 1.19.3+

### Basic usage
[Download](https://github.com/mircokroon/minecraft-world-downloader/releases/latest/download/world-downloader.exe) the latest release and run it. Enter the server address in the address field and press start. Instead of connecting to the server itself, connect to `localhost` in Minecraft to start downloading the world.
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ private static void loadVersionRegistries(Protocol p) {
if (loader == null) { return; }

WorldManager.getInstance().setEntityMap(loader.generateEntityNames());
WorldManager.getInstance().initialiseRegistries();

RegistryManager.getInstance().setRegistries(loader);

Expand Down Expand Up @@ -418,6 +417,10 @@ public static Consumer<PacketBuilder> getPacketInjector() {
usage = "Disable marking unsaved chunks in red on the map")
public boolean disableMarkUnsavedChunks = false;

@Option(name = "--mark-old-chunks",
usage = "Grey out old chunks on the map")
public boolean markOldChunks = true;

@Option(name = "--ignore-block-changes",
usage = "Ignore changes to chunks after they have been loaded.")
public boolean ignoreBlockChanges = false;
Expand All @@ -438,6 +441,9 @@ public static Consumer<PacketBuilder> getPacketInjector() {
usage = "Disable various info messages (e.g. chest saving).")
public boolean disableInfoMessages = false;

// not really important enough to have an option in the GUI
public boolean smoothZooming = true;

// getters
public static int getExtendedRenderDistance() {
return instance.extendedRenderDistance;
Expand Down Expand Up @@ -500,6 +506,14 @@ public static boolean handleBlockChanges() {

public static boolean sendInfoMessages() { return !instance.disableInfoMessages; }

public static boolean smoothZooming() {
return instance.smoothZooming;
}

public static boolean markOldChunks() {
return instance.markOldChunks;
}

// setters
public static void setZoomLevel(int val) {
instance.zoomLevel = val;
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/config/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,4 @@ public enum Version {
this.protocolVersion = protocolVersion;
this.dataVersion = dataVersion;
}

boolean isVersion(VersionReporter versionReporter) {
return switch (this) {
case V1_12 -> versionReporter.isAtLeast1_12();
case V1_13 -> versionReporter.isAtLeast1_13();
case V1_14 -> versionReporter.isAtLeast1_14();
case V1_15 -> versionReporter.isAtLeast1_15();
case V1_16 -> versionReporter.isAtLeast1_16();
case V1_17 -> versionReporter.isAtLeast1_17();
case V1_18 -> versionReporter.isAtLeast1_18();
case V1_19 -> versionReporter.isAtLeast1_19();
case V1_19_3 -> versionReporter.isAtLeast1_19_3();
case ANY -> true;
default -> false;
};
}

public boolean isDataVersion(int dataVersion) {
switch (this) {
case V1_12: return VersionReporter.isAtLeast1_12(dataVersion);
case V1_13: return VersionReporter.isAtLeast1_13(dataVersion);
case V1_14: return VersionReporter.isAtLeast1_14(dataVersion);
case V1_15: return VersionReporter.isAtLeast1_15(dataVersion);
case V1_16: return VersionReporter.isAtLeast1_16(dataVersion);
case V1_17: return VersionReporter.isAtLeast1_17(dataVersion);
case V1_18: return VersionReporter.isAtLeast1_18(dataVersion);
case V1_19: return VersionReporter.isAtLeast1_19(dataVersion);
case V1_19_3: return VersionReporter.isAtLeast1_19_3(dataVersion);
case ANY: return true;
default: return false;
}
}
}
75 changes: 13 additions & 62 deletions src/main/java/config/VersionReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
import game.protocol.ProtocolVersionHandler;

public class VersionReporter {
private final int protocolVersion;
public VersionReporter(int version) {
this.protocolVersion = version;
private final Protocol protocol;

public VersionReporter(int protocolVersion) {
this.protocol = ProtocolVersionHandler.getInstance().getProtocolByProtocolVersion(protocolVersion);
}

public int getDataVersion() {
return protocol.getDataVersion();
}

public Protocol getProtocol() {
return ProtocolVersionHandler.getInstance().getProtocolByProtocolVersion(protocolVersion);
return protocol;
}

public static <T> T select(int dataVersion, Class<T> type, Option... opts) {
for (Option opt : opts) {
if (is(dataVersion, opt.v)) {
if (dataVersion >= opt.v.dataVersion) {
return type.cast(opt.obj.get());
}
}
Expand All @@ -24,68 +29,14 @@ public static <T> T select(int dataVersion, Class<T> type, Option... opts) {

public <T> T select(Class<T> type, Option... opts) {
for (Option opt : opts) {
if (is(opt.v)) {
if (isAtLeast(opt.v)) {
return type.cast(opt.obj.get());
}
}
return null;
}

public static boolean is(int dataVersion, Version v) {
return v.isDataVersion(dataVersion);
}

public boolean is(Version v) {
return v.isVersion(this);
}

public boolean isAtLeast1_12() {
return protocolVersion >= Version.V1_12.protocolVersion;
}
public boolean isAtLeast1_13() {
return protocolVersion >= Version.V1_13.protocolVersion;
}
public boolean isAtLeast1_14() {
return protocolVersion >= Version.V1_14.protocolVersion;
}
public boolean isAtLeast1_15() {
return protocolVersion >= Version.V1_15.protocolVersion;
}
public boolean isAtLeast1_16() {
return protocolVersion >= Version.V1_16.protocolVersion;
}
public boolean isAtLeast1_17() {
return protocolVersion >= Version.V1_17.protocolVersion;
}
public boolean isAtLeast1_18() { return protocolVersion >= Version.V1_18.protocolVersion; }
public boolean isAtLeast1_19() { return protocolVersion >= Version.V1_19.protocolVersion; }
public boolean isAtLeast1_19_3() { return protocolVersion >= Version.V1_19_3.protocolVersion; }

public static boolean isAtLeast1_12(int dataVersion) {
return dataVersion >= Version.V1_12.dataVersion;
}
public static boolean isAtLeast1_13(int dataVersion) {
return dataVersion >= Version.V1_13.dataVersion;
}
public static boolean isAtLeast1_14(int dataVersion) {
return dataVersion >= Version.V1_14.dataVersion;
}
public static boolean isAtLeast1_15(int dataVersion) {
return dataVersion >= Version.V1_15.dataVersion;
}
public static boolean isAtLeast1_16(int dataVersion) {
return dataVersion >= Version.V1_16.dataVersion;
}
public static boolean isAtLeast1_17(int dataVersion) {
return dataVersion >= Version.V1_17.dataVersion;
}
public static boolean isAtLeast1_18(int dataVersion) {
return dataVersion >= Version.V1_18.dataVersion;
}
public static boolean isAtLeast1_19(int dataVersion) {
return dataVersion >= Version.V1_19.dataVersion;
}
public static boolean isAtLeast1_19_3(int dataVersion) {
return dataVersion >= Version.V1_19_3.dataVersion;
public boolean isAtLeast(Version v) {
return getDataVersion() >= v.dataVersion;
}
}
7 changes: 4 additions & 3 deletions src/main/java/game/data/LevelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import config.Config;
import config.Option;
import config.Version;
import game.data.coordinates.Coordinate3D;
import game.data.coordinates.CoordinateDouble3D;
import game.data.dimension.Dimension;
Expand Down Expand Up @@ -96,7 +97,7 @@ private void loadGeneratorSettings() throws IOException {
}

private static String getGeneratorSettingsName() {
if (Config.versionReporter().isAtLeast1_19()) {
if (Config.versionReporter().isAtLeast(Version.V1_19)) {
return "world-gen-settings-1.19.dat";
} else {
return "world-gen-settings-1.16.dat";
Expand Down Expand Up @@ -166,7 +167,7 @@ public void save() throws IOException {
}

private void enableWorldGeneration(CompoundTag data) {
if (Config.versionReporter().isAtLeast1_16()) {
if (Config.versionReporter().isAtLeast(Version.V1_16)) {
LongTag seed = new LongTag(Config.getLevelSeed());

CompoundTag dimensions = this.worldGenSettings.get("dimensions").asCompound();
Expand All @@ -192,7 +193,7 @@ private void enableWorldGeneration(CompoundTag data) {
* Set world type to a superflat void world.
*/
private void disableWorldGeneration(CompoundTag data) {
if (Config.versionReporter().isAtLeast1_16()) {
if (Config.versionReporter().isAtLeast(Version.V1_16)) {
CompoundTag generator = new CompoundTag();
generator.add("type", new StringTag("minecraft:flat"));
generator.add("settings", new CompoundTag(Arrays.asList(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/game/data/RenderDistanceExtender.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package game.data;

import config.Config;
import config.Version;
import game.data.coordinates.Coordinate2D;
import game.data.coordinates.CoordinateDim2D;
import game.data.region.McaFile;
Expand Down Expand Up @@ -83,7 +84,7 @@ private void setServerDistance(int serverDistance) {
this.active = this.serverDistance < this.extendedDistance;

// temporarily disabled for 1.18
if (Config.versionReporter().isAtLeast1_18()) {
if (Config.versionReporter().isAtLeast(Version.V1_18)) {
this.active = false;
System.out.println("Extending render distance is not yet supported for 1.18.");
}
Expand Down
Loading

0 comments on commit 7d86fa8

Please sign in to comment.