Skip to content

Commit

Permalink
Merge pull request EngineHub#2637 from EngineHub/ot/fix/jnbt-compat
Browse files Browse the repository at this point in the history
Bump lin-bus to support old schematics better
  • Loading branch information
octylFractal authored Oct 13, 2024
2 parents 485bb41 + 6c65f09 commit e595c3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fabric-mixin = "net.fabricmc:sponge-mixin:0.13.3+mixin.0.8.5"

paperweight = "io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.7.2"

linBus-bom = "org.enginehub.lin-bus:lin-bus-bom:0.1.0"
linBus-bom = "org.enginehub.lin-bus:lin-bus-bom:0.2.0"
linBus-common.module = "org.enginehub.lin-bus:lin-bus-common"
linBus-stream.module = "org.enginehub.lin-bus:lin-bus-stream"
linBus-tree.module = "org.enginehub.lin-bus:lin-bus-tree"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Reader;
import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Writer;
import org.enginehub.linbus.stream.LinBinaryIO;
import org.enginehub.linbus.stream.LinReadOptions;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinRootEntry;
Expand Down Expand Up @@ -58,7 +59,8 @@ public String getPrimaryFileExtension() {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return new MCEditSchematicReader(LinBinaryIO.read(
new DataInputStream(new GZIPInputStream(inputStream))
new DataInputStream(new GZIPInputStream(inputStream)),
LEGACY_OPTIONS
));
}

Expand All @@ -72,7 +74,7 @@ public boolean isFormat(InputStream inputStream) {
LinRootEntry rootEntry;
try {
DataInputStream stream = new DataInputStream(new GZIPInputStream(inputStream));
rootEntry = LinBinaryIO.readUsing(stream, LinRootEntry::readFrom);
rootEntry = LinBinaryIO.readUsing(stream, LEGACY_OPTIONS, LinRootEntry::readFrom);
} catch (Exception e) {
return false;
}
Expand All @@ -92,7 +94,7 @@ public String getPrimaryFileExtension() {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return new SpongeSchematicV1Reader(LinBinaryIO.read(
new DataInputStream(new GZIPInputStream(inputStream))
new DataInputStream(new GZIPInputStream(inputStream)), LEGACY_OPTIONS
));
}

Expand All @@ -116,7 +118,7 @@ public String getPrimaryFileExtension() {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return new SpongeSchematicV2Reader(LinBinaryIO.read(
new DataInputStream(new GZIPInputStream(inputStream))
new DataInputStream(new GZIPInputStream(inputStream)), LEGACY_OPTIONS
));
}

Expand Down Expand Up @@ -175,7 +177,7 @@ private static boolean detectOldSpongeSchematic(InputStream inputStream, int ver
LinRootEntry rootEntry;
try {
DataInputStream stream = new DataInputStream(new GZIPInputStream(inputStream));
rootEntry = LinBinaryIO.readUsing(stream, LinRootEntry::readFrom);
rootEntry = LinBinaryIO.readUsing(stream, LEGACY_OPTIONS, LinRootEntry::readFrom);
} catch (Exception e) {
return false;
}
Expand All @@ -200,6 +202,8 @@ private static boolean detectOldSpongeSchematic(InputStream inputStream, int ver
@Deprecated
public static final BuiltInClipboardFormat SPONGE_SCHEMATIC = SPONGE_V2_SCHEMATIC;

private static final LinReadOptions LEGACY_OPTIONS = LinReadOptions.builder().allowNormalUtf8Encoding(true).build();

private final ImmutableSet<String> aliases;

BuiltInClipboardFormat(String... aliases) {
Expand Down

0 comments on commit e595c3f

Please sign in to comment.