Skip to content

Commit

Permalink
Merge pull request #35 from TechnicJelle/improved-bluenbt-usage
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Mar 4, 2024
2 parents 1e1d96a + d6c6124 commit eec1673
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public static ChunkClass getFromDataVersion(int dataVersion) throws IOException
//https://minecraft.wiki/w/Data_version#List_of_data_versions
if (dataVersion >= 3463) {
return new ChunkClass(MC_1_20_4_Chunk.class, dataVersion);
} else if (intInRange(dataVersion, 2825, 3337)) {
} else if (intInRange(dataVersion, 2844, 3337)) {
//2844 is when they cleaned up the Level section (https://minecraft.wiki/w/Java_Edition_21w43a)
//For versions:
// - 1.18.2
// - 1.19.4
return new ChunkClass(MC_1_18_2_Chunk.class, dataVersion);
} else if (intInRange(dataVersion, 2724, 2730)) {
} else if (intInRange(dataVersion, 2724, 2840)) {
//2840 is right before they cleaned up the Level section (https://minecraft.wiki/w/Java_Edition_21w42a)
return new ChunkClass(MC_1_17_1_Chunk.class, dataVersion);
} else if (intInRange(dataVersion, 1901, 2586)) {
//For versions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.technicjelle.bluemapsignextractor.common;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.NoSuchElementException;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.InflaterInputStream;

public enum Compression {
NONE("none", "", out -> out, in -> in),
GZIP("gzip", ".gz", GZIPOutputStream::new, GZIPInputStream::new),
DEFLATE("deflate", ".deflate", DeflaterOutputStream::new, InflaterInputStream::new);

private final String typeId;
private final String fileSuffix;
private final StreamTransformer<OutputStream> compressor;
private final StreamTransformer<InputStream> decompressor;

Compression(String typeId, String fileSuffix,
StreamTransformer<OutputStream> compressor,
StreamTransformer<InputStream> decompressor) {
this.fileSuffix = fileSuffix;
this.typeId = typeId;
this.compressor = compressor;
this.decompressor = decompressor;
}

public String getTypeId() {
return typeId;
}

public String getFileSuffix() {
return fileSuffix;
}

public OutputStream compress(OutputStream out) throws IOException {
return compressor.apply(out);
}

public InputStream decompress(InputStream in) throws IOException {
return decompressor.apply(in);
}

public static Compression forTypeId(String id) {
for (Compression compression : values()) {
if (compression.typeId.equals(id)) return compression;
}

throw new NoSuchElementException("There is no Compression with type-id: " + id);
}

@FunctionalInterface
private interface StreamTransformer<T> {
T apply(T original) throws IOException;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static MarkerSet loadMarkerSetFromWorld(Logger logger, Path regionFolder)
.build();

try (final Stream<Path> stream = Files.list(regionFolder)) {
stream.filter(path -> path.toString().endsWith(".mca")).forEach(path -> fillMarkerSetFromRegionFile(logger, markerSet, path));
stream.filter(path -> path.toString().endsWith(MCARegion.FILE_SUFFIX)).forEach(path -> fillMarkerSetFromRegionFile(logger, markerSet, path));
} catch (IOException e) {
logger.log(Level.SEVERE, "Error reading region folder", e);
}
Expand All @@ -52,9 +52,9 @@ public static MarkerSet loadMarkerSetFromWorld(Logger logger, Path regionFolder)
private static void fillMarkerSetFromRegionFile(Logger logger, MarkerSet markerSet, Path regionFile) {
logger.fine("Processing region " + regionFile.getFileName().toString());

final MCA mca = new MCA(regionFile);
final MCARegion mcaRegion = new MCARegion(regionFile);
try {
for (BlockEntity blockEntity : mca.getBlockEntities()) {
for (BlockEntity blockEntity : mcaRegion.getBlockEntities()) {
if (blockEntity.isInvalidSign()) continue;

final HtmlMarker htmlMarker = HtmlMarker.builder()
Expand Down
125 changes: 0 additions & 125 deletions src/main/java/com/technicjelle/bluemapsignextractor/common/MCA.java

This file was deleted.

Loading

0 comments on commit eec1673

Please sign in to comment.