Skip to content

Commit

Permalink
Merge pull request #163 from mircokroon/1_17
Browse files Browse the repository at this point in the history
1.17 support
  • Loading branch information
mircokroon authored Jun 11, 2021
2 parents 83deeb7 + 9c9161a commit 052b738
Show file tree
Hide file tree
Showing 48 changed files with 1,386 additions and 682 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
java-version: '8'
java-package: jdk+fx
- run: |
mvn package
mvn package -DskipTests
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '8'
java-version: '16'
java-package: jdk+fx
- run: |
mvn test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Cross-platform jar (GUI & commandline): [world-downloader.jar](https://github.co
<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.">

### Requirements
- Java 8 or higher
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+
- Java 16 or higher (Java 8 works for versions up to 1.16.5)
- Minecraft version 1.12.2+ // 1.13.2+ // 1.14.1+ // 1.15.2+ // 1.16.2+ // 1.17+

### 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
Binary file added chunkdata.bin
Binary file not shown.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<packaging>jar</packaging>
<properties>
<java.version>8</java.version>
<java.version.max>15</java.version.max>
<java.version.max>16</java.version.max>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -93,7 +93,7 @@
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.25</version>
<version>2.1.1</version>
<executions>
<execution>
<id>l4j-gui</id>
Expand Down Expand Up @@ -240,8 +240,8 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import game.data.WorldManager;
import game.data.chunk.ChunkFactory;
import game.data.registries.RegistryLoader;
import game.protocol.Protocol;
import game.protocol.ProtocolVersionHandler;
Expand Down Expand Up @@ -257,6 +256,7 @@ public static Protocol getGameProtocol() {
private static void loadVersionRegistries(Protocol p) {
try {
RegistryLoader loader = RegistryLoader.forVersion(p.getVersion());
if (loader == null) { return; }

WorldManager.getInstance().setEntityMap(loader.generateEntityNames());
WorldManager.getInstance().setMenuRegistry(loader.generateMenuRegistry());
Expand All @@ -267,7 +267,6 @@ private static void loadVersionRegistries(Protocol p) {
loader.clean();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

Expand Down
24 changes: 18 additions & 6 deletions src/main/java/config/Version.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package config;

public enum Version {
V1_12,
V1_13,
V1_14,
V1_15,
V1_16,
ANY;
// version numbers correspond to the earliest full release
V1_12(317, 1132),
V1_13(341, 1444),
V1_14(440, 1901),
V1_15(550, 2200),
V1_16(701, 2578),
V1_17(755, 2724),
ANY(0, 0);

public final int dataVersion;
public final int protocolVersion;

Version(int protocolVersion, int dataVersion) {
this.protocolVersion = protocolVersion;
this.dataVersion = dataVersion;
}

boolean isVersion(VersionReporter versionReporter) {
switch (this) {
Expand All @@ -15,6 +25,7 @@ boolean isVersion(VersionReporter versionReporter) {
case V1_14: return versionReporter.isAtLeast1_14();
case V1_15: return versionReporter.isAtLeast1_15();
case V1_16: return versionReporter.isAtLeast1_16();
case V1_17: return versionReporter.isAtLeast1_17();
case ANY: return true;
default: return false;
}
Expand All @@ -27,6 +38,7 @@ public boolean isDataVersion(int 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 ANY: return true;
default: return false;
}
Expand Down
51 changes: 24 additions & 27 deletions src/main/java/config/VersionReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@
import game.protocol.ProtocolVersionHandler;

public class VersionReporter {
private final static int DATA_VERSION_1_12 = 1022;
private final static int DATA_VERSION_1_13 = 1444;
private final static int DATA_VERSION_1_14 = 1901;
private final static int DATA_VERSION_1_15 = 2200;
private final static int DATA_VERSION_1_16 = 2504;

private final static int VERSION_1_12 = 317;
private final static int VERSION_1_13 = 341;
private final static int VERSION_1_14 = 440;
private final static int VERSION_1_15 = 550;
private final static int VERSION_1_16 = 701;

private final int protocolVersion;
public VersionReporter(int version) {
this.protocolVersion = version;
Expand Down Expand Up @@ -52,50 +40,59 @@ public boolean is(Version v) {
}

public boolean isAtLeast1_12() {
return protocolVersion >= VERSION_1_12;
return protocolVersion >= Version.V1_12.protocolVersion;
}
public boolean isAtLeast1_13() {
return protocolVersion >= VERSION_1_13;
return protocolVersion >= Version.V1_13.protocolVersion;
}
public boolean isAtLeast1_14() {
return protocolVersion >= VERSION_1_14;
return protocolVersion >= Version.V1_14.protocolVersion;
}
public boolean isAtLeast1_15() {
return protocolVersion >= VERSION_1_15;
return protocolVersion >= Version.V1_15.protocolVersion;
}
public boolean isAtLeast1_16() {
return protocolVersion >= VERSION_1_16;
return protocolVersion >= Version.V1_16.protocolVersion;
}
public boolean isAtLeast1_17() {
return protocolVersion >= Version.V1_17.protocolVersion;
}

public static boolean isAtLeast1_12(int dataVersion) {
return dataVersion >= DATA_VERSION_1_12;
return dataVersion >= Version.V1_12.dataVersion;
}
public static boolean isAtLeast1_13(int dataVersion) {
return dataVersion >= DATA_VERSION_1_13;
return dataVersion >= Version.V1_13.dataVersion;
}
public static boolean isAtLeast1_14(int dataVersion) {
return dataVersion >= DATA_VERSION_1_14;
return dataVersion >= Version.V1_14.dataVersion;
}
public static boolean isAtLeast1_15(int dataVersion) {
return dataVersion >= DATA_VERSION_1_15;
return dataVersion >= Version.V1_15.dataVersion;
}
public static boolean isAtLeast1_16(int dataVersion) {
return dataVersion >= DATA_VERSION_1_16;
return dataVersion >= Version.V1_16.dataVersion;
}
public static boolean isAtLeast1_17(int dataVersion) {
return dataVersion >= Version.V1_17.dataVersion;
}

public boolean is1_12() {
return protocolVersion >= VERSION_1_12 && protocolVersion < VERSION_1_13;
return protocolVersion >= Version.V1_12.protocolVersion && protocolVersion < Version.V1_13.protocolVersion;
}
public boolean is1_13() {
return protocolVersion >= VERSION_1_13 && protocolVersion < VERSION_1_14;
return protocolVersion >= Version.V1_13.protocolVersion && protocolVersion < Version.V1_14.protocolVersion;
}
public boolean is1_14() {
return protocolVersion >= VERSION_1_14 && protocolVersion < VERSION_1_15;
return protocolVersion >= Version.V1_14.protocolVersion && protocolVersion < Version.V1_15.protocolVersion;
}
public boolean is1_15() {
return protocolVersion >= VERSION_1_15 && protocolVersion < VERSION_1_16;
return protocolVersion >= Version.V1_15.protocolVersion && protocolVersion < Version.V1_16.protocolVersion;
}
public boolean is1_16() {
return protocolVersion >= VERSION_1_16;
return protocolVersion >= Version.V1_16.protocolVersion && protocolVersion < Version.V1_17.protocolVersion;
}
public boolean is1_17() {
return protocolVersion >= Version.V1_17.protocolVersion;
}
}
18 changes: 13 additions & 5 deletions src/main/java/game/data/LevelData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import java.util.stream.Collectors;

public class LevelData {
WorldManager worldManager;
Path outputDir;
File file;
Tag root;
CompoundTag data;
private final WorldManager worldManager;
private final Path outputDir;
private final File file;
private Tag root;
private CompoundTag data;
private boolean savingBroken;

public LevelData(WorldManager worldManager) {
this.worldManager = worldManager;
Expand Down Expand Up @@ -91,6 +92,13 @@ private void load(boolean forceInternal) throws IOException {
* the resource folder.
*/
public void save() throws IOException {
if (savingBroken) { return; }
if (data == null) {
savingBroken = true;
System.err.println("Unable to read in valid 'level.dat' file. Chunks will be saved, but they cannot be opened in-game without manually providing a 'level.dat' file.");
return;
}

// add the player's position
if (worldManager.getPlayerPosition() != null) {
Tag playerTag = data.get("Player");
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/game/data/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import game.data.entity.EntityRegistry;
import game.data.maps.MapRegistry;
import game.data.region.McaFile;
import game.data.region.McaFilePair;
import game.data.region.Region;
import gui.GuiManager;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -72,8 +73,9 @@ public class WorldManager {
private final EntityRegistry entityRegistry;
private final ChunkFactory chunkFactory;

protected WorldManager() {
public WorldManager() {
this.isStarted = false;
this.entityMap = new EntityNames();
this.entityRegistry = new EntityRegistry(this);
this.chunkFactory = new ChunkFactory();
this.mapRegistry = new MapRegistry();
Expand Down Expand Up @@ -421,16 +423,13 @@ public void save() {
// convert the values to an array first to prevent blocking any threads
Region[] r = regions.values().toArray(new Region[0]);
for (Region region : r) {
McaFile file = region.toFile(getPlayerPosition().globalToChunk());
if (file == null) {
McaFilePair files = region.toFile(getPlayerPosition().globalToChunk());
if (files == null) {
continue;
}

try {
file.write();
} catch (IOException e) {
e.printStackTrace();
}
write(files.getRegion());
write(files.getEntities());
}
}

Expand Down Expand Up @@ -461,6 +460,18 @@ public void save() {
System.gc();
}

private void write(McaFile file) {
if (file == null || file.isEmpty()) {
return;
}

try {
file.write();
} catch (IOException e) {
e.printStackTrace();
}
}

public ContainerManager getContainerManager() {
if (containerManager == null) {
containerManager = new ContainerManager();
Expand Down
Loading

0 comments on commit 052b738

Please sign in to comment.