Skip to content
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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
group 'net.querz'
version '7.0'

sourceCompatibility = JavaLanguageVersion.of(17)
targetCompatibility = JavaLanguageVersion.of(17)
sourceCompatibility = JavaLanguageVersion.of(8)
targetCompatibility = JavaLanguageVersion.of(8)

repositories {
mavenCentral()
Expand All @@ -19,4 +19,4 @@ dependencies {

test {
useJUnitPlatform()
}
}
6 changes: 1 addition & 5 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
jdk:
- openjdk17

before_install:
- sdk install java 17.0.3-ms
- sdk use java 17.0.3-ms
- openjdk8
12 changes: 8 additions & 4 deletions src/main/java/net/querz/io/seekable/SeekableByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,19 @@ public String readLine() throws IOException {

while (!eol) {
switch (c = read()) {
case '\n' -> eol = true;
case '\r' -> {
case '\n':
eol = true;
break;
case '\r':
eol = true;
long cur = getPointer();
if (read() != '\n') {
seek(cur);
}
}
default -> sb.append((char) c);
break;
default:
sb.append((char) c);
break;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/querz/mca/CompressionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public int getID() {
}

public static CompressionType fromByte(int id) throws IOException {
return switch (id) {
case 0x0 -> NONE;
case 0x1 -> GZIP;
case 0x2 -> ZLIB;
case 0x80 -> NONE_EXT;
case 0x81 -> GZIP_EXT;
case 0x82 -> ZLIB_EXT;
default -> throw new IOException("invalid compression type " + id);
};
switch (id) {
case 0x0: return NONE;
case 0x1: return GZIP;
case 0x2: return ZLIB;
case 0x80: return NONE_EXT;
case 0x81: return GZIP_EXT;
case 0x82: return ZLIB_EXT;
default: throw new IOException("invalid compression type " + id);
}
}

@FunctionalInterface
Expand Down
45 changes: 44 additions & 1 deletion src/main/java/net/querz/mca/MCAFileHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,55 @@

import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Supplier;

public record MCAFileHandle(File directory, SeekableData seekableData, MCCFileHandler mccFileHandler, Supplier<TagTypeVisitor> tagTypeVisitorSupplier) implements AutoCloseable {
public class MCAFileHandle implements AutoCloseable {

private final File directory;
private final SeekableData seekableData;
private final MCCFileHandler mccFileHandler;
private final Supplier<TagTypeVisitor> tagTypeVisitorSupplier;

public MCAFileHandle(File directory, SeekableData seekableData, MCCFileHandler mccFileHandler, Supplier<TagTypeVisitor> tagTypeVisitorSupplier) {
this.directory = directory;
this.seekableData = seekableData;
this.mccFileHandler = mccFileHandler;
this.tagTypeVisitorSupplier = tagTypeVisitorSupplier;
}

@Override
public void close() throws IOException {
seekableData.close();
}

public File directory() {
return directory;
}

public SeekableData seekableData() {
return seekableData;
}

public MCCFileHandler mccFileHandler() {
return mccFileHandler;
}

public Supplier<TagTypeVisitor> tagTypeVisitorSupplier() {
return tagTypeVisitorSupplier;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MCAFileHandle that = (MCAFileHandle) o;
return Objects.equals(directory, that.directory) && Objects.equals(seekableData, that.seekableData) && Objects.equals(mccFileHandler, that.mccFileHandler) && Objects.equals(tagTypeVisitorSupplier, that.tagTypeVisitorSupplier);
}

@Override
public int hashCode() {
return Objects.hash(directory, seekableData, mccFileHandler, tagTypeVisitorSupplier);
}

}
40 changes: 39 additions & 1 deletion src/main/java/net/querz/mca/parsers/BlockLocation.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
package net.querz.mca.parsers;

public record BlockLocation(int x, int y, int z) {
import java.util.Objects;

public class BlockLocation {

private final int x;
private final int y;
private final int z;

public BlockLocation(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}

public BlockLocation() {
this(0, 0, 0);
}

public int x() {
return x;
}

public int y() {
return y;
}

public int z() {
return z;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BlockLocation that = (BlockLocation) o;
return x == that.x && y == that.y && z == that.z;
}

@Override
public int hashCode() {
return Objects.hash(x, y, z);
}

}
40 changes: 39 additions & 1 deletion src/main/java/net/querz/mca/parsers/EntityLocation.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
package net.querz.mca.parsers;

public record EntityLocation(double x, double y, double z) {
import java.util.Objects;

public class EntityLocation {

private final double x;
private final double y;
private final double z;

public EntityLocation(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}

public EntityLocation() {
this(0, 0, 0);
}

public double x() {
return x;
}

public double y() {
return y;
}

public double z() {
return z;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EntityLocation that = (EntityLocation) o;
return Double.compare(x, that.x) == 0 && Double.compare(y, that.y) == 0 && Double.compare(z, that.z) == 0;
}

@Override
public int hashCode() {
return Objects.hash(x, y, z);
}

}
28 changes: 27 additions & 1 deletion src/main/java/net/querz/mca/parsers/HeightmapParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.querz.mca.parsers;

import java.util.Arrays;

public interface HeightmapParser extends DataParser<HeightmapParser.HeightmapData>, CachedParser {

HeightmapData getDataAt(int blockX, int blockZ);
Expand Down Expand Up @@ -43,10 +45,34 @@ public int getID() {
}
}

record HeightmapData(int[] data) {
class HeightmapData {

private final int[] data;

public HeightmapData(int[] data) {
this.data = data;
}

public int[] data() {
return data;
}

public int getHeight(HeightmapType type) {
return data[type.getID()];
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HeightmapData that = (HeightmapData) o;
return Arrays.equals(data, that.data);
}

@Override
public int hashCode() {
return Arrays.hashCode(data);
}

}
}
4 changes: 2 additions & 2 deletions src/main/java/net/querz/nbt/ByteArrayTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Arrays;
import java.util.Objects;

public non-sealed class ByteArrayTag extends CollectionTag<ByteTag> {
public class ByteArrayTag extends CollectionTag<ByteTag> {

private byte[] value;

Expand Down Expand Up @@ -110,7 +110,7 @@ public void setValue(byte[] value) {
this.value = value;
}

public static final TagReader<ByteArrayTag> READER = new TagReader<>() {
public static final TagReader<ByteArrayTag> READER = new TagReader<ByteArrayTag>() {

@Override
public ByteArrayTag read(DataInput in, int depth) throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/querz/nbt/ByteTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.io.DataOutput;
import java.io.IOException;

public non-sealed class ByteTag extends NumberTag {
public class ByteTag extends NumberTag {

private final byte value;

Expand Down Expand Up @@ -98,7 +98,7 @@ public String toString() {
return value + "b";
}

public static final TagReader<ByteTag> READER = new TagReader<>() {
public static final TagReader<ByteTag> READER = new TagReader<ByteTag>() {

@Override
public ByteTag read(DataInput in, int depth) throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/querz/nbt/CollectionTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.AbstractList;

public sealed abstract class CollectionTag<T extends Tag> extends AbstractList<T> implements Tag permits ByteArrayTag, IntArrayTag, ListTag, LongArrayTag {
public abstract class CollectionTag<T extends Tag> extends AbstractList<T> implements Tag {

public CollectionTag() {}

Expand Down
Loading