diff --git a/build.gradle b/build.gradle index cfd369f..a2496c5 100644 --- a/build.gradle +++ b/build.gradle @@ -22,13 +22,15 @@ apply plugin: "java" ext { //general things javaVersion = "1.8" - savesearcherVersion = "1.6.2" + minecraftVersion = "1.16.4" + savesearcherVersion = "2.0.0." + ('git rev-list --count HEAD'.execute().text.trim()) + "-$minecraftVersion-SNAPSHOT" //dependency things gsonVersion = "2.8.5" junitVersion = "4.12" lombokVersion = "1.16.20" - porklibVersion = "0.5.4-SNAPSHOT" + mcworldlibVersion = "0.0.1-$minecraftVersion-SNAPSHOT" + porklibVersion = "0.5.5-SNAPSHOT" } group "net.daporkchop" @@ -56,19 +58,16 @@ configurations { } dependencies { - shade "com.google.code.gson:gson:$gsonVersion" - shade "net.daporkchop.lib:http:$porklibVersion" shade "net.daporkchop.lib:logging:$porklibVersion" - shade "net.daporkchop.lib:minecraft-worldscanner:$porklibVersion" shade "net.daporkchop.lib:reflection:$porklibVersion" + shade "net.daporkchop:mcworldlib:$mcworldlibVersion" + testCompile "junit:junit:$junitVersion" compileOnly "org.projectlombok:lombok:$lombokVersion" - testCompileOnly "org.projectlombok:lombok:$lombokVersion" annotationProcessor "org.projectlombok:lombok:$lombokVersion" - testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" } jar { diff --git a/src/main/java/net/daporkchop/savesearcher/Main.java b/src/main/java/net/daporkchop/savesearcher/Main.java index b66f4ac..ec79068 100644 --- a/src/main/java/net/daporkchop/savesearcher/Main.java +++ b/src/main/java/net/daporkchop/savesearcher/Main.java @@ -21,35 +21,27 @@ import net.daporkchop.lib.common.function.io.IOConsumer; import net.daporkchop.lib.common.misc.file.PFiles; +import net.daporkchop.lib.common.misc.string.PStrings; +import net.daporkchop.lib.common.pool.array.ArrayAllocator; +import net.daporkchop.lib.common.ref.ReferenceType; import net.daporkchop.lib.common.system.OperatingSystem; import net.daporkchop.lib.common.system.PlatformInfo; +import net.daporkchop.lib.common.util.PorkUtil; import net.daporkchop.lib.compression.zlib.Zlib; import net.daporkchop.lib.logging.LogAmount; import net.daporkchop.lib.math.vector.i.Vec2i; -import net.daporkchop.lib.minecraft.region.WorldScanner; -import net.daporkchop.lib.minecraft.region.util.ChunkProcessor; -import net.daporkchop.lib.minecraft.region.util.NeighboringChunkProcessor; -import net.daporkchop.lib.minecraft.tileentity.TileEntityRegistry; -import net.daporkchop.lib.minecraft.world.MinecraftSave; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.lib.minecraft.world.format.anvil.AnvilSaveFormat; -import net.daporkchop.lib.minecraft.world.format.anvil.region.RegionFile; -import net.daporkchop.lib.minecraft.world.format.anvil.region.RegionOpenOptions; -import net.daporkchop.lib.minecraft.world.impl.MinecraftSaveConfig; -import net.daporkchop.lib.minecraft.world.impl.SaveBuilder; +import net.daporkchop.mcworldlib.format.anvil.AnvilSaveFormat; +import net.daporkchop.mcworldlib.format.anvil.AnvilSaveOptions; +import net.daporkchop.mcworldlib.save.Save; +import net.daporkchop.mcworldlib.save.SaveOptions; +import net.daporkchop.mcworldlib.util.Identifier; +import net.daporkchop.mcworldlib.util.WriteAccess; +import net.daporkchop.mcworldlib.world.World; import net.daporkchop.savesearcher.module.SearchModule; -import net.daporkchop.savesearcher.module.impl.DoubleChestModule; -import net.daporkchop.savesearcher.module.impl.EmptyChunksModule; -import net.daporkchop.savesearcher.module.impl.EntityModule; -import net.daporkchop.savesearcher.module.impl.NetherChunksModule; import net.daporkchop.savesearcher.module.impl.SignModule; -import net.daporkchop.savesearcher.module.impl.SpawnerModule; -import net.daporkchop.savesearcher.module.impl.block.BlockModule; -import net.daporkchop.savesearcher.module.impl.count.CountBlocksModule; import net.daporkchop.savesearcher.output.OutputHandle; import net.daporkchop.savesearcher.output.csv.CSVOutputHandle; import net.daporkchop.savesearcher.output.csv.CompressedCSVOutputHandle; -import net.daporkchop.savesearcher.tileentity.TileEntitySpawner; import net.daporkchop.savesearcher.util.Version; import java.io.File; @@ -63,6 +55,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; +import java.util.stream.StreamSupport; import static net.daporkchop.lib.logging.Logging.*; @@ -72,13 +65,6 @@ public class Main { private static final Map> REGISTERED_MODULES = new HashMap>() { { - this.put("--block", BlockModule::find); - this.put("--count", CountBlocksModule::find); - this.put("--doublechest", DoubleChestModule::new); - this.put("--emptychunks", EmptyChunksModule::new); - this.put("--entity", EntityModule::new); - this.put("--netherchunks", NetherChunksModule::new); - this.put("--spawner", SpawnerModule::new); this.put("--sign", SignModule::new); } }; @@ -103,34 +89,35 @@ public static void main(String... args) throws IOException { } if (args.length == 0 - || contains(args, "-h") - || contains(args, "--help") - || contains(args, "--h") - || contains(args, "-help")) { + || contains(args, "-h") + || contains(args, "--help") + || contains(args, "--h") + || contains(args, "-help")) { logger.info("SaveSearcher v%s", Version.VERSION) .info("Copyright (c) DaPorkchop_") .info("https://github.com/DaMatrix/SaveSearcher") .info("") .info("--input= Sets the input world path (required)") - .info("--dim= Sets the dimension (world) id to scan. default=0") + .info("--dim= Sets the dimension (world) id to scan. default=minecraft:overworld") .info("--verbose Print status updates to console") .info("--format= Sets the format that the output data will be written in. valid formats=csv,csv_gz default=csv") .info("--output= Set the root directory that output data will be written to. default=./scanresult/") .info("") .info("MODULES") - .info("--block,id=(,meta=) Scan for a certain block id+meta, saving coordinates. Block ids should be in format 'minecraft:stone'. Meta must be 0-15, by default") - .info(" (,min=)(,max=) it's ignored. Both min and max values are inclusive, and default to min=0 and max=255 if not given. Adding the invert flag will cause") - .info(" (,invert)(,chunkinvert) a search for block coordinates where the given block id+meta does not occur. Adding the chunkinvert flag will cause a search for chunk") - .info(" coordinates where the given block id+meta does not occur. invert and chunkinvert may not be used together.") - .info("--count,type=(,id=) Counts the number of occurrences of the given type in each chunk, saving chunk coordinates and count. Valid types: block, tileentity. id") - .info(" (,meta=) is required for block, optional for tileentity. meta is optional for block, not allowed for tileentity.") - .info("--doublechest Scan for double chests, saving coordinates and whether or not they're trapped.") - .warn(" WARNING! Can cause significant slowdown!") - .info("--netherchunks Scan for nether chunks that have somehow ended up in the overworld.") - .info("--emptychunks Scan for empty (air-only) chunks.") + //.info("--block,id=(,meta=) Scan for a certain block id+meta, saving coordinates. Block ids should be in format 'minecraft:stone'. Meta must be 0-15, by default") + //.info(" (,min=)(,max=) it's ignored. Both min and max values are inclusive, and default to min=0 and max=255 if not given. Adding the invert flag will cause") + //.info(" (,invert)(,chunkinvert) a search for block coordinates where the given block id+meta does not occur. Adding the chunkinvert flag will cause a search for chunk") + //.info(" coordinates where the given block id+meta does not occur. invert and chunkinvert may not be used together.") + //.info("--count,type=(,id=) Counts the number of occurrences of the given type in each chunk, saving chunk coordinates and count. Valid types: block, tileentity. id") + //.info(" (,meta=) is required for block, optional for tileentity. meta is optional for block, not allowed for tileentity.") + //.info("--doublechest Scan for double chests, saving coordinates and whether or not they're trapped.") + //.warn(" WARNING! Can cause significant slowdown!") + //.info("--netherchunks Scan for nether chunks that have somehow ended up in the overworld.") + //.info("--emptychunks Scan for empty (air-only) chunks.") .info("--sign Scan for sign blocks, saving coordinates and text.") - .info("--spawner(,) Scan for spawner blocks, optionally filtering based on mob type and saving coordinates and entity type.") - .info("--entity(,) Scan for entities, optionally filtering based on entity ID and saving coordinates and NBT data."); + //.info("--spawner(,) Scan for spawner blocks, optionally filtering based on mob type and saving coordinates and entity type.") + //.info("--entity(,) Scan for entities, optionally filtering based on entity ID and saving coordinates and NBT data.") + ; return; } else { logger.addFile(new File("savesearcher.log").getAbsoluteFile(), true, LogAmount.DEBUG) @@ -147,7 +134,7 @@ public static void main(String... args) throws IOException { File worldFile = null; File outDir = new File("scanresult"); - int dim = 0; + Identifier dim = Identifier.fromString("minecraft:overworld"); boolean verbose = false; boolean overwrite = false; String formatName = "csv"; @@ -174,7 +161,7 @@ public static void main(String... args) throws IOException { overwrite = true; continue; case "--dim": - dim = Integer.parseInt(split[1]); + dim = Identifier.fromString(split[1]); continue; case "--verbose": case "-v": @@ -228,42 +215,32 @@ public static void main(String... args) throws IOException { long time = System.currentTimeMillis(); AtomicLong count = new AtomicLong(0L); Set regionPositions = Collections.newSetFromMap(new ConcurrentHashMap<>()); - try (MinecraftSave save = new SaveBuilder() - .setInitFunctions(new MinecraftSaveConfig() - .openOptions(new RegionOpenOptions().access(RegionFile.Access.READ_ONLY).mode(RegionFile.Mode.MMAP_FULL)) - .tileEntityFactory(TileEntityRegistry.builder(TileEntityRegistry.defaultRegistry()) - .add(TileEntitySpawner.ID, TileEntitySpawner::new) - .build())) - .setFormat(new AnvilSaveFormat(worldFile)).build()) { - World world = save.world(dim); - if (world == null) { - throw new IllegalArgumentException(String.format("Invalid dimension: %d", dim)); - } - + try (Save save = new AnvilSaveFormat().open(worldFile, SaveOptions.builder() + .set(SaveOptions.ACCESS, WriteAccess.READ_ONLY) + .set(AnvilSaveOptions.MMAP_REGIONS, true) + .set(SaveOptions.BYTE_ALLOC, ArrayAllocator.pow2(byte.class, ReferenceType.SOFT, 64 * PorkUtil.CPU_COUNT)) + .set(SaveOptions.INT_ALLOC, ArrayAllocator.pow2(int.class, ReferenceType.SOFT, 64 * PorkUtil.CPU_COUNT)) + .set(SaveOptions.LONG_ALLOC, ArrayAllocator.pow2(long.class, ReferenceType.SOFT, 64 * PorkUtil.CPU_COUNT)) + .build())) { for (SearchModule module : modules) { - module.init(world, REGISTERED_OUTPUTS.get(formatName).apply(outDir)); + module.init(save, REGISTERED_OUTPUTS.get(formatName).apply(outDir)); } - WorldScanner scanner = new WorldScanner(world) { - @Override - public WorldScanner addProcessor(ChunkProcessor processor) { - if (processor instanceof NeighboringChunkProcessor) { - return super.addProcessor((NeighboringChunkProcessor) processor); - } else { - return super.addProcessor(processor); - } + try (World world = save.world(dim)) { + if (world == null) { + throw new IllegalArgumentException(PStrings.fastFormat("Invalid dimension: %s", dim)); } - }; - if (verbose) { - scanner.addProcessor((current, estimatedTotal, column) -> { - if (regionPositions.add(new Vec2i(column.getX() >> 5, column.getZ() >> 5))) { - logger.debug("Processing region #%d (%d,%d), chunk %d/~%d (%.2f%%)", regionPositions.size(), column.getX() >> 5, column.getZ() >> 5, current, estimatedTotal, ((double) current / (double) estimatedTotal) * 100.0d); - } - }); + + /*if (verbose) { + scanner.addProcessor((current, estimatedTotal, column) -> { + if (regionPositions.add(new Vec2i(column.getX() >> 5, column.getZ() >> 5))) { + logger.debug("Processing region #%d (%d,%d), chunk %d/~%d (%.2f%%)", regionPositions.size(), column.getX() >> 5, column.getZ() >> 5, current, estimatedTotal, ((double) current / (double) estimatedTotal) * 100.0d); + } + }); + }*/ + StreamSupport.stream(world.storage().allSections(), true) + .forEach(section -> modules.forEach(module -> ((SearchModule.ForSection) module).acceptChunk(world, section))); } - scanner.addProcessor((current, estimatedTotal, column) -> count.set(current)); - modules.forEach(scanner::addProcessor); - scanner.run(true); logger.info("Finishing..."); modules.forEach((IOConsumer) SearchModule::close); diff --git a/src/main/java/net/daporkchop/savesearcher/module/AbstractSearchModule.java b/src/main/java/net/daporkchop/savesearcher/module/AbstractSearchModule.java index 99121aa..8d242f9 100644 --- a/src/main/java/net/daporkchop/savesearcher/module/AbstractSearchModule.java +++ b/src/main/java/net/daporkchop/savesearcher/module/AbstractSearchModule.java @@ -22,9 +22,7 @@ import lombok.Getter; import lombok.NonNull; import lombok.experimental.Accessors; -import net.daporkchop.lib.common.util.GenericMatcher; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; +import net.daporkchop.mcworldlib.save.Save; import net.daporkchop.savesearcher.output.OutputHandle; import java.io.IOException; @@ -34,12 +32,11 @@ */ @Getter @Accessors(fluent = true) -public abstract class AbstractSearchModule implements SearchModule { - protected final Class dataType = GenericMatcher.find(this.getClass(), AbstractSearchModule.class, "S"); - protected OutputHandle handle; +public abstract class AbstractSearchModule implements SearchModule { + protected OutputHandle handle; @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { + public void init(@NonNull Save save, @NonNull OutputHandle handle) { handle.init(this); this.handle = handle; } @@ -48,11 +45,4 @@ public void init(@NonNull World world, @NonNull OutputHandle handle) { public void close() throws IOException { this.handle.close(); } - - @Override - public void handle(long current, long estimatedTotal, @NonNull Chunk chunk) { - this.processChunk(chunk, this.handle); - } - - protected abstract void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle); } diff --git a/src/main/java/net/daporkchop/savesearcher/module/PositionData.java b/src/main/java/net/daporkchop/savesearcher/module/PositionData.java index facdc57..c45bb58 100644 --- a/src/main/java/net/daporkchop/savesearcher/module/PositionData.java +++ b/src/main/java/net/daporkchop/savesearcher/module/PositionData.java @@ -19,13 +19,10 @@ package net.daporkchop.savesearcher.module; -import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.experimental.Accessors; import net.daporkchop.lib.math.vector.i.Vec3i; -import net.daporkchop.lib.minecraft.tileentity.TileEntity; +import net.daporkchop.lib.nbt.tag.CompoundTag; /** * Base class for module output data that has a position. @@ -38,8 +35,8 @@ public class PositionData { public final int y; public final int z; - public PositionData(@NonNull TileEntity te) { - this(te.getX(), te.getY(), te.getZ()); + public PositionData(@NonNull CompoundTag te) { + this(te.getInt("x"), te.getInt("y"), te.getInt("z")); } public PositionData(@NonNull Vec3i vec) { diff --git a/src/main/java/net/daporkchop/savesearcher/module/PositionDataXZ.java b/src/main/java/net/daporkchop/savesearcher/module/PositionDataXZ.java index 4e00609..0b9e9f2 100644 --- a/src/main/java/net/daporkchop/savesearcher/module/PositionDataXZ.java +++ b/src/main/java/net/daporkchop/savesearcher/module/PositionDataXZ.java @@ -22,8 +22,6 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import net.daporkchop.lib.math.vector.i.Vec2i; -import net.daporkchop.lib.math.vector.i.Vec3i; -import net.daporkchop.lib.minecraft.tileentity.TileEntity; /** * Base class for module output data that has a position. diff --git a/src/main/java/net/daporkchop/savesearcher/module/SearchModule.java b/src/main/java/net/daporkchop/savesearcher/module/SearchModule.java index 6fa710a..9a5e035 100644 --- a/src/main/java/net/daporkchop/savesearcher/module/SearchModule.java +++ b/src/main/java/net/daporkchop/savesearcher/module/SearchModule.java @@ -20,8 +20,10 @@ package net.daporkchop.savesearcher.module; import lombok.NonNull; -import net.daporkchop.lib.minecraft.region.util.ChunkProcessor; -import net.daporkchop.lib.minecraft.world.World; +import net.daporkchop.mcworldlib.save.Save; +import net.daporkchop.mcworldlib.world.Chunk; +import net.daporkchop.mcworldlib.world.World; +import net.daporkchop.mcworldlib.world.section.Section; import net.daporkchop.savesearcher.output.OutputHandle; import java.io.IOException; @@ -29,20 +31,22 @@ /** * The core of all SaveSearcher modules. *

- * Implementations of this do the actual searching of the world. + * Modules will only be initialized once, and will be closed after all search operations are completed. Once initialized, implementations + * must be safely usable from multiple threads. * + * @param the result data type * @author DaPorkchop_ */ -public interface SearchModule extends ChunkProcessor, AutoCloseable { +public interface SearchModule extends AutoCloseable { /** - * Initializes this module for searching the given world. + * Initializes this module for searching the given save. *

- * This may be used to e.g. obtain any numeric block IDs needed. + * This may be used to e.g. prefetch numeric block IDs from the registry. * - * @param world the world to search in + * @param save the save that is going to be searched * @param handle the {@link OutputHandle} that any output data should be given to */ - void init(@NonNull World world, @NonNull OutputHandle handle); + void init(@NonNull Save save, @NonNull OutputHandle handle); /** * Closes this module. @@ -54,8 +58,11 @@ public interface SearchModule extends ChunkProcessor, AutoCloseable { @Override void close() throws IOException; - /** - * @return the class of values that will be returned by this module - */ - Class dataType(); + interface ForChunk { + void acceptChunk(@NonNull World world, @NonNull Chunk chunk); + } + + interface ForSection { + void acceptChunk(@NonNull World world, @NonNull Section section); + } } diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/DoubleChestModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/DoubleChestModule.java deleted file mode 100644 index 647b61c..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/DoubleChestModule.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl; - -import com.google.gson.JsonObject; -import lombok.NonNull; -import net.daporkchop.lib.minecraft.region.util.NeighboringChunkProcessor; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.util.BlockAccess; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionData; -import net.daporkchop.savesearcher.module.SearchModule; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -public final class DoubleChestModule extends AbstractSearchModule implements NeighboringChunkProcessor { - private int chestId; - private int trappedChestId; - - public DoubleChestModule(String[] args) { - } - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - this.chestId = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(new ResourceLocation("minecraft:chest")); - this.trappedChestId = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(new ResourceLocation("minecraft:trapped_chest")); - } - - @Override - public void handle(long l, long l1, Chunk chunk) { - throw new UnsupportedOperationException(); - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - throw new UnsupportedOperationException(); - } - - @Override - public void handle(long current, long estimatedTotal, Chunk chunk, BlockAccess access) { - final int chestId = this.chestId; - final int trappedChestId = this.trappedChestId; - final int x = chunk.getX() << 4; - final int z = chunk.getZ() << 4; - - for (int xx = 15; xx >= 0; xx--) { - for (int zz = (xx & 1) == 0 ? 15 : 14; zz >= 0; zz -= 2) { - for (int y = 255; y >= 0; y--) { - int id = access.getBlockId(x + xx, y, z + zz); - if (id == chestId) { - if (access.getBlockId(x + xx + 1, y, z + zz) == chestId - || access.getBlockId(x + xx, y, z + zz + 1) == chestId) { - this.handle.accept(new DoubleChestData(x + xx, y, z + zz, false)); - } - } else if (id == trappedChestId) { - if (access.getBlockId(x + xx + 1, y, z + zz) == trappedChestId - || access.getBlockId(x + xx, y, z + zz + 1) == trappedChestId) { - this.handle.accept(new DoubleChestData(x + xx, y, z + zz, true)); - } - } - } - } - } - } - - @Override - public String toString() { - return "Double Chests"; - } - - @Override - public int hashCode() { - return DoubleChestModule.class.hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof DoubleChestModule; - } - - protected static final class DoubleChestData extends PositionData { - public final boolean trapped; - - public DoubleChestData(int x, int y, int z, boolean trapped) { - super(x, y, z); - - this.trapped = trapped; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/EmptyChunksModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/EmptyChunksModule.java deleted file mode 100644 index 3f0c2c6..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/EmptyChunksModule.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl; - -import lombok.NonNull; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -public final class EmptyChunksModule extends AbstractSearchModule { - public EmptyChunksModule(String[] args) { - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - for (int chunkY = 0; chunkY < 15; chunkY++) { //go from bottom section to top as it's more likely to find blocks on the bottom - final Section section = chunk.section(chunkY); - if (section == null) { - continue; - } - for (int x = 15; x >= 0; x--) { - for (int y = 15; y >= 0; y--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, y, z) != 0) { - return; - } - } - } - } - } - handle.accept(new PositionDataXZ(chunk.pos())); - } - - @Override - public String toString() { - return "Empty Chunks"; - } - - @Override - public int hashCode() { - return EmptyChunksModule.class.hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof EmptyChunksModule; - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/EntityModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/EntityModule.java deleted file mode 100644 index c86f49e..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/EntityModule.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.minecraft.entity.Entity; -import net.daporkchop.lib.minecraft.entity.impl.UnknownEntity; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.output.OutputHandle; -import net.daporkchop.savesearcher.util.NBTHelper; - -import java.util.Objects; - -/** - * @author DaPorkchop_ - */ -public final class EntityModule extends AbstractSearchModule { - protected final ResourceLocation filterId; - - public EntityModule(String[] args) { - switch (args.length) { - case 1: - this.filterId = null; - break; - case 2: - this.filterId = new ResourceLocation(args[1]); - break; - default: - throw new IllegalArgumentException("--entity must be called with either no arguments or the entity ID to search for!"); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - if (this.filterId == null) { - chunk.entities().stream() - .map(EntityData::new) - .forEach(handle::accept); - } else { - chunk.entities().stream() - .filter(e -> this.filterId.equals(e.id())) - .map(EntityData::new) - .forEach(handle::accept); - } - } - - @Override - public String toString() { - return this.filterId == null ? "Entities" : String.format("Entities (id=%s)", this.filterId); - } - - @Override - public int hashCode() { - return this.filterId == null ? EntityModule.class.hashCode() : this.filterId.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj instanceof EntityModule) { - return Objects.equals(this.filterId, ((EntityModule) obj).filterId); - } else { - return false; - } - } - - @RequiredArgsConstructor - protected static final class EntityData { - @NonNull - public final ResourceLocation id; - public final double x; - public final double y; - public final double z; - @NonNull - public final String nbt; - - public EntityData(@NonNull Entity entity) { - this(entity.id(), entity.getX(), entity.getY(), entity.getZ(), - entity instanceof UnknownEntity ? NBTHelper.toJson(((UnknownEntity) entity).data()) : "{}"); - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/NetherChunksModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/NetherChunksModule.java deleted file mode 100644 index f842e89..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/NetherChunksModule.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl; - -import lombok.NonNull; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -public final class NetherChunksModule extends AbstractSearchModule { - protected int bedrock_id; - - public NetherChunksModule(String[] args) { - } - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - this.bedrock_id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(new ResourceLocation("minecraft:bedrock")); - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.bedrock_id; - - final Section section = chunk.section(7); - if (section == null) { - return; - } - for (int x = 15; x >= 0; x--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, 15, z) == id) { - handle.accept(new PositionDataXZ(chunk.pos())); - return; - } - } - } - } - - @Override - public String toString() { - return "Nether Chunks"; - } - - @Override - public int hashCode() { - return NetherChunksModule.class.hashCode(); - } - - @Override - public boolean equals(Object obj) { - return obj instanceof NetherChunksModule; - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/SignModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/SignModule.java index 36bf1c1..c5e76a7 100644 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/SignModule.java +++ b/src/main/java/net/daporkchop/savesearcher/module/impl/SignModule.java @@ -19,24 +19,28 @@ package net.daporkchop.savesearcher.module.impl; -import com.google.gson.JsonObject; import lombok.NonNull; -import net.daporkchop.lib.logging.format.FormatParser; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.text.parser.MinecraftFormatParser; -import net.daporkchop.lib.minecraft.tileentity.impl.TileEntitySign; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; +import net.daporkchop.lib.minecraft.text.MCTextEncoder; +import net.daporkchop.lib.minecraft.text.MCTextType; +import net.daporkchop.lib.minecraft.text.parser.AutoMCFormatParser; +import net.daporkchop.lib.nbt.tag.CompoundTag; +import net.daporkchop.mcworldlib.block.BlockState; +import net.daporkchop.mcworldlib.registry.Registry; +import net.daporkchop.mcworldlib.save.Save; +import net.daporkchop.mcworldlib.util.Identifier; +import net.daporkchop.mcworldlib.world.World; +import net.daporkchop.mcworldlib.world.section.FlattenedSection; +import net.daporkchop.mcworldlib.world.section.LegacySection; +import net.daporkchop.mcworldlib.world.section.Section; import net.daporkchop.savesearcher.module.AbstractSearchModule; import net.daporkchop.savesearcher.module.PositionData; +import net.daporkchop.savesearcher.module.SearchModule; import net.daporkchop.savesearcher.output.OutputHandle; /** * @author DaPorkchop_ */ -public final class SignModule extends AbstractSearchModule { - private static final FormatParser PARSER = new MinecraftFormatParser(); - +public final class SignModule extends AbstractSearchModule implements SearchModule.ForSection { private int standing_sign; private int wall_sign; @@ -44,19 +48,21 @@ public SignModule(String[] args) { } @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); + public void init(@NonNull Save save, @NonNull OutputHandle handle) { + super.init(save, handle); - this.standing_sign = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(new ResourceLocation("minecraft:standing_sign")); - this.wall_sign = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(new ResourceLocation("minecraft:wall_sign")); + Registry blockRegistry = save.version().registries().block(); + this.standing_sign = blockRegistry.get(Identifier.fromString("minecraft:standing_sign")); + this.wall_sign = blockRegistry.get(Identifier.fromString("minecraft:wall_sign")); } @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - chunk.tileEntities().stream() - .filter(TileEntitySign.class::isInstance) - .map(te -> new SignData((TileEntitySign) te, chunk)) - .forEach(handle::accept); + public void acceptChunk(@NonNull World world, @NonNull Section section) { + section.tileEntities().forEach(te -> { + if ("minecraft:sign".equals(te.getString("id"))) { + this.handle.accept(new SignData(te, section)); + } + }); } @Override @@ -83,92 +89,110 @@ protected final class SignData extends PositionData { public final String type; public final String direction; - public SignData(@NonNull TileEntitySign te, @NonNull Chunk chunk) { + public SignData(@NonNull CompoundTag te, @NonNull Section section) { super(te); - this.line1 = PARSER.parse(te.line1()).toRawString(); - this.line2 = PARSER.parse(te.line2()).toRawString(); - this.line3 = PARSER.parse(te.line3()).toRawString(); - this.line4 = PARSER.parse(te.line4()).toRawString(); - - int id = chunk.getBlockId(te.getX() & 0xF, te.getY(), te.getZ() & 0xF); - int meta = chunk.getBlockMeta(te.getX() & 0xF, te.getY(), te.getZ() & 0xF); - if (id == SignModule.this.standing_sign) { - String dir = "unknown"; - switch (meta) { - case 0: - dir = "south"; - break; - case 1: - dir = "south-southwest"; - break; - case 2: - dir = "southwest"; - break; - case 3: - dir = "west-southwest"; - break; - case 4: - dir = "west"; - break; - case 5: - dir = "west-northwest"; - break; - case 6: - dir = "northwest"; - break; - case 7: - dir = "north-northwest"; - break; - case 8: - dir = "north"; - break; - case 9: - dir = "north-northeast"; - break; - case 10: - dir = "northeast"; - break; - case 11: - dir = "east-northeast"; - break; - case 12: - dir = "east"; - break; - case 13: - dir = "east-southeast"; - break; - case 14: - dir = "southeast"; - break; - case 15: - dir = "south-southeast"; - break; + this.line1 = MCTextEncoder.encode(MCTextType.LEGACY, AutoMCFormatParser.DEFAULT.parse(te.getString("Text1"))); + this.line2 = MCTextEncoder.encode(MCTextType.LEGACY, AutoMCFormatParser.DEFAULT.parse(te.getString("Text2"))); + this.line3 = MCTextEncoder.encode(MCTextType.LEGACY, AutoMCFormatParser.DEFAULT.parse(te.getString("Text3"))); + this.line4 = MCTextEncoder.encode(MCTextType.LEGACY, AutoMCFormatParser.DEFAULT.parse(te.getString("Text4"))); + + int direction = 0; + String dir = null; + String type = "invalid"; + + if (section instanceof LegacySection) { + int id = ((LegacySection) section).getCombinedIdMeta(this.x & 0xF, this.y & 0xF, this.z & 0xF); + if ((id >> 4) == SignModule.this.standing_sign) { + type = "standing_sign"; + direction = id & 0xF; + } else if ((id >> 4) == SignModule.this.wall_sign) { + type = "wall_sign"; + direction = ~(id & 0xF); + } + } else if (section instanceof FlattenedSection) { + BlockState state = ((FlattenedSection) section).getBlockState(this.x & 0xF, this.y & 0xF, this.z & 0xF); + if (state.id().name().endsWith("_wall_sign")) { + type = "wall_sign"; + dir = state.properties().get("facing"); + } else if (state.id().name().endsWith("_sign")) { + type = "standing_sign"; + direction = Integer.parseInt(state.properties().getOrDefault("rotation", "0")); } - this.type = "standing_sign"; - this.direction = dir; - } else if (id == SignModule.this.wall_sign) { - String dir = "unknown"; - switch (meta) { - case 2: - dir = "north"; - break; - case 3: - dir = "south"; - break; - case 4: - dir = "west"; - break; - case 5: - dir = "east"; - break; + } + + if (dir == null) { + dir = "unknown"; + if (direction >= 0) { + switch (direction) { + case 0: + dir = "south"; + break; + case 1: + dir = "south-southwest"; + break; + case 2: + dir = "southwest"; + break; + case 3: + dir = "west-southwest"; + break; + case 4: + dir = "west"; + break; + case 5: + dir = "west-northwest"; + break; + case 6: + dir = "northwest"; + break; + case 7: + dir = "north-northwest"; + break; + case 8: + dir = "north"; + break; + case 9: + dir = "north-northeast"; + break; + case 10: + dir = "northeast"; + break; + case 11: + dir = "east-northeast"; + break; + case 12: + dir = "east"; + break; + case 13: + dir = "east-southeast"; + break; + case 14: + dir = "southeast"; + break; + case 15: + dir = "south-southeast"; + break; + } + } else { + switch (~direction) { + case 2: + dir = "north"; + break; + case 3: + dir = "south"; + break; + case 4: + dir = "west"; + break; + case 5: + dir = "east"; + break; + } } - this.type = "wall_sign"; - this.direction = dir; - } else { - this.type = String.format("invalid_id_%d", id); - this.direction = "unknown"; } + this.direction = dir; + this.type = type; } } } diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/SpawnerModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/SpawnerModule.java deleted file mode 100644 index 79e28bb..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/SpawnerModule.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl; - -import lombok.NonNull; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionData; -import net.daporkchop.savesearcher.output.OutputHandle; -import net.daporkchop.savesearcher.tileentity.TileEntitySpawner; - -import java.util.Objects; - -/** - * @author DaPorkchop_ - */ -public final class SpawnerModule extends AbstractSearchModule { - protected final ResourceLocation filterId; - - public SpawnerModule(String[] args) { - switch (args.length) { - case 1: - this.filterId = null; - break; - case 2: - this.filterId = new ResourceLocation(args[1]); - break; - default: - throw new IllegalArgumentException("--spawner must be called with either no arguments or the entity ID of the spawner type to search for!"); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - if (this.filterId == null) { - chunk.tileEntities().stream() - .filter(TileEntitySpawner.class::isInstance) - .map(te -> new SpawnerData((TileEntitySpawner) te)) - .forEach(handle::accept); - } else { - chunk.tileEntities().stream() - .filter(TileEntitySpawner.class::isInstance) - .map(TileEntitySpawner.class::cast) - .filter(te -> te.canSpawn(this.filterId)) - .map(SpawnerData::new) - .forEach(handle::accept); - } - } - - @Override - public String toString() { - return this.filterId == null ? "Spawners" : String.format("Spawners (id=%s)", this.filterId); - } - - @Override - public int hashCode() { - return this.filterId == null ? SpawnerModule.class.hashCode() : this.filterId.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj instanceof SpawnerModule) { - return Objects.equals(this.filterId, ((SpawnerModule) obj).filterId); - } else { - return false; - } - } - - protected static final class SpawnerData extends PositionData { - public final ResourceLocation id; - - public SpawnerData(@NonNull TileEntitySpawner te) { - super(te); - - if (te.entries().size() != 1) { - throw new IllegalArgumentException(String.format("Spawner (%d,%d,%d) has %d entries!", te.getX(), te.getY(), te.getZ(), te.entries().size())); - } - - this.id = te.entries().get(0).id(); - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockModule.java deleted file mode 100644 index 4966aee..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockModule.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.AccessLevel; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.math.vector.i.Vec3i; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.SearchModule; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public final class BlockModule extends AbstractSearchModule { - public static SearchModule find(@NonNull String[] args) { - ResourceLocation id = null; - int meta = -1; - int min = 0; - int max = 255; - boolean invert = false; - boolean chunkinvert = false; - - for (String s : args) { - if (s.isEmpty()) { - continue; - } - String[] split = s.split("="); - if (split.length != 2) { - throw new IllegalArgumentException(String.format("Invalid argument: %s", s)); - } - switch (split[0]) { - case "id": - id = new ResourceLocation(split[1]); - break; - case "meta": - meta = Integer.parseInt(split[1]); - if (meta > 15 || meta < 0) { - throw new IllegalArgumentException(String.format("Invalid meta: %d (must be in range 0-15)", meta)); - } - break; - case "min": - case "minY": - min = Integer.parseInt(split[1]); - break; - case "max": - case "maxY": - max = Integer.parseInt(split[1]); - break; - case "invert": - if (chunkinvert) { - throw new IllegalArgumentException("invert and chunkinvert cannot be used together!"); - } - invert = true; - break; - case "chunkinvert": - if (invert) { - throw new IllegalArgumentException("invert and chunkinvert cannot be used together!"); - } - chunkinvert = true; - break; - default: - throw new IllegalArgumentException(String.format("Invalid argument: %s", s)); - } - } - - if (id == null) { - throw new IllegalArgumentException("No id given!"); - } else if (min > max) { - throw new IllegalArgumentException(String.format("Min Y must be less than or equal to max Y! (min=%d, max=%d)", min, max)); - } else if (min == 0 && max == 255) { - return chunkinvert - ? new ChunkInverseBlockModule(id, meta) - : invert ? new InverseBlockModule(id, meta) : new BlockModule(id, meta); - } else { - return chunkinvert - ? new ChunkInverseBlockRangeModule(id, meta, min, max) - : invert ? new InverseBlockRangeModule(id, meta, min, max) : new BlockRangeModule(id, meta, min, max); - } - } - - protected final ResourceLocation searchName; - protected final int meta; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - - for (int sectionY = 15; sectionY >= 0; sectionY--) { - Section section = chunk.section(sectionY); - if (section == null) { - continue; - } - for (int x = 15; x >= 0; x--) { - for (int y = 15; y >= 0; y--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, y, z) == id && (meta == -1 || section.getBlockMeta(x, y, z) == meta)) { - handle.accept(new Vec3i(chunk.minX() + x, (section.getY() << 4) + y, chunk.minZ() + z)); - } - } - } - } - } - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block (id=%s)", this.searchName); - } else { - return String.format("Block (id=%s, meta=%d)", this.searchName, this.meta); - } - } - - @Override - public int hashCode() { - //id is only computed later and can change dynamically, so we don't want to include it in the hash code - return this.searchName.hashCode() * 31 + this.meta; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == BlockModule.class) { - //don't do instanceof check, since we only want to check if the modules are exactly identical - BlockModule other = (BlockModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockRangeModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockRangeModule.java deleted file mode 100644 index 018e72d..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/BlockRangeModule.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.math.vector.i.Vec3i; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor -final class BlockRangeModule extends AbstractSearchModule { - protected final ResourceLocation searchName; - protected final int meta; - protected final int minY; - protected final int maxY; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - final int maxY = this.maxY; - final int minY = this.minY; - - for (int y = maxY; y >= minY; y--) { - for (int x = 15; x >= 0; x--) { - for (int z = 15; z >= 0; z--) { - if (chunk.getBlockId(x, y, z) == id && (meta == -1 || chunk.getBlockMeta(x, y, z) == meta)) { - handle.accept(new Vec3i(chunk.minX() + x, y, chunk.minZ() + z)); - } - } - } - } - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block - Ranged (id=%s, min=%d, max=%d)", this.searchName, this.minY, this.maxY); - } else { - return String.format("Block - Ranged (id=%s, meta=%d, min=%d, max=%d)", this.searchName, this.meta, this.minY, this.maxY); - } - } - - @Override - public int hashCode() { - return ((this.searchName.hashCode() * 31 + this.meta) * 31 + this.maxY) * 31 + this.minY; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == BlockRangeModule.class) { - BlockRangeModule other = (BlockRangeModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta && this.maxY == other.maxY && this.minY == other.minY; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockModule.java deleted file mode 100644 index ba1890e..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockModule.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor -final class ChunkInverseBlockModule extends AbstractSearchModule { - protected final ResourceLocation searchName; - protected final int meta; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - - for (int sectionY = 15; sectionY >= 0; sectionY--) { - Section section = chunk.section(sectionY); - if (section == null) { - if (id == 0) { - return; - } else { - continue; - } - } - for (int x = 15; x >= 0; x--) { - for (int y = 15; y >= 0; y--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, y, z) == id && (meta == -1 || section.getBlockMeta(x, y, z) == meta)) { - return; - } - } - } - } - } - handle.accept(new PositionDataXZ(chunk.pos())); - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block - Inverted (chunk, id=%s)", this.searchName); - } else { - return String.format("Block - Inverted (chunk, id=%s, meta=%d)", this.searchName, this.meta); - } - } - - @Override - public int hashCode() { - //id is only computed later and can change dynamically, so we don't want to include it in the hash code - return this.searchName.hashCode() * 31 + this.meta; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == ChunkInverseBlockModule.class) { - ChunkInverseBlockModule other = (ChunkInverseBlockModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockRangeModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockRangeModule.java deleted file mode 100644 index d725a4a..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/ChunkInverseBlockRangeModule.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor -final class ChunkInverseBlockRangeModule extends AbstractSearchModule { - protected final ResourceLocation searchName; - protected final int meta; - protected final int minY; - protected final int maxY; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - final int maxY = this.maxY; - final int minY = this.minY; - - for (int y = maxY; y >= minY; y--) { - for (int x = 15; x >= 0; x--) { - for (int z = 15; z >= 0; z--) { - if (chunk.getBlockId(x, y, z) == id && (meta == -1 || chunk.getBlockMeta(x, y, z) == meta)) { - return; - } - } - } - } - - handle.accept(new PositionDataXZ(chunk.pos())); - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block - Inverted,Ranged (chunk, id=%s, min=%d, max=%d)", this.searchName, this.minY, this.maxY); - } else { - return String.format("Block - Inverted,Ranged (chunk, id=%s, meta=%d, min=%d, max=%d)", this.searchName, this.meta, this.minY, this.maxY); - } - } - - @Override - public int hashCode() { - return ((this.searchName.hashCode() * 31 + this.meta) * 31 + this.maxY) * 31 + this.minY; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == ChunkInverseBlockRangeModule.class) { - ChunkInverseBlockRangeModule other = (ChunkInverseBlockRangeModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta && this.maxY == other.maxY && this.minY == other.minY; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockModule.java deleted file mode 100644 index 95d7856..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockModule.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionData; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor -final class InverseBlockModule extends AbstractSearchModule { - protected final ResourceLocation searchName; - protected final int meta; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - - for (int sectionY = 15; sectionY >= 0; sectionY--) { - Section section = chunk.section(sectionY); - if (section == null) { - section = Section.EMPTY_SECTION; - } - for (int x = 15; x >= 0; x--) { - for (int y = 15; y >= 0; y--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, y, z) != id && (meta == -1 || section.getBlockMeta(x, y, z) != meta)) { - handle.accept(new PositionData(chunk.minX() + x, (sectionY << 4) + y, chunk.minZ() + z)); - } - } - } - } - } - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block - Inverted (id=%s)", this.searchName); - } else { - return String.format("Block - Inverted (id=%s, meta=%d)", this.searchName, this.meta); - } - } - - @Override - public int hashCode() { - //id is only computed later and can change dynamically, so we don't want to include it in the hash code - return this.searchName.hashCode() * 31 + this.meta; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == InverseBlockModule.class) { - InverseBlockModule other = (InverseBlockModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockRangeModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockRangeModule.java deleted file mode 100644 index 2e772e9..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/block/InverseBlockRangeModule.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.block; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionData; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor -final class InverseBlockRangeModule extends AbstractSearchModule { - protected final ResourceLocation searchName; - protected final int meta; - protected final int minY; - protected final int maxY; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - final int maxY = this.maxY; - final int minY = this.minY; - - for (int y = maxY; y >= minY; y--) { - for (int x = 15; x >= 0; x--) { - for (int z = 15; z >= 0; z--) { - if (chunk.getBlockId(x, y, z) != id && (meta == -1 || chunk.getBlockMeta(x, y, z) != meta)) { - handle.accept(new PositionData(chunk.minX() + x, y, chunk.minZ() + z)); - } - } - } - } - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Block - Inverted,Ranged (id=%s, min=%d, max=%d)", this.searchName, this.minY, this.maxY); - } else { - return String.format("Block - Inverted,Ranged (id=%s, meta=%d, min=%d, max=%d)", this.searchName, this.meta, this.minY, this.maxY); - } - } - - @Override - public int hashCode() { - return ((this.searchName.hashCode() * 31 + this.meta) * 31 + this.maxY) * 31 + this.minY; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == InverseBlockRangeModule.class) { - InverseBlockRangeModule other = (InverseBlockRangeModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta && this.maxY == other.maxY && this.minY == other.minY; - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountBlocksModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountBlocksModule.java deleted file mode 100644 index f44bbdd..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountBlocksModule.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.count; - -import lombok.AccessLevel; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.math.vector.i.Vec2i; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.module.SearchModule; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public final class CountBlocksModule extends AbstractSearchModule { - public static SearchModule find(@NonNull String[] args) { - ResourceLocation id = null; - int meta = -1; - String type = null; - - for (String s : args) { - if (s.isEmpty()) { - continue; - } - String[] split = s.split("="); - if (split.length != 2) { - throw new IllegalArgumentException(String.format("Invalid argument: %s", s)); - } - switch (split[0]) { - case "id": - id = new ResourceLocation(split[1]); - break; - case "meta": - meta = Integer.parseInt(split[1]); - if (meta > 15 || meta < 0) { - throw new IllegalArgumentException(String.format("Invalid meta: %d (must be in range 0-15)", meta)); - } - break; - case "type": - type = split[1]; - break; - default: - throw new IllegalArgumentException(String.format("Invalid argument: %s", s)); - } - } - - if (type == null) { - throw new IllegalArgumentException("No type given!"); - } else { - switch (type) { - case "block": - if (id == null) { - throw new IllegalArgumentException("No id given!"); - } - return new CountBlocksModule(id, meta); - case "tileentity": - if (meta != -1) { - throw new IllegalStateException("type=tileentity does not use a meta value!"); - } - return new CountTileEntitiesModule(id); - default: - throw new IllegalStateException(String.format("Unknown type: \"%s\"", type)); - } - } - } - - protected final ResourceLocation searchName; - protected final int meta; - protected int id; - - @Override - public void init(@NonNull World world, @NonNull OutputHandle handle) { - super.init(world, handle); - - if ((this.id = world.getSave().registry(new ResourceLocation("minecraft:blocks")).lookup(this.searchName)) == -1) { - throw new IllegalArgumentException(String.format("Invalid block id: %s", this.searchName.toString())); - } - } - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - final int id = this.id; - final int meta = this.meta; - - long count = 0L; - for (int sectionY = 15; sectionY >= 0; sectionY--) { - Section section = chunk.section(sectionY); - if (section == null) { - if (id == 0 && meta == 0) { - count += 4096L; - } - continue; - } - for (int x = 15; x >= 0; x--) { - for (int y = 15; y >= 0; y--) { - for (int z = 15; z >= 0; z--) { - if (section.getBlockId(x, y, z) == id && (meta == -1 || section.getBlockMeta(x, y, z) == meta)) { - count++; - } - } - } - } - } - handle.accept(new CountData(chunk.pos(), count)); - } - - @Override - public String toString() { - if (this.meta == -1) { - return String.format("Count - Block (id=%s)", this.searchName); - } else { - return String.format("Count - Block (id=%s, meta=%d)", this.searchName, this.meta); - } - } - - @Override - public int hashCode() { - //id is only computed later and can change dynamically, so we don't want to include it in the hash code - return this.searchName.hashCode() * 31 + this.meta; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj.getClass() == CountBlocksModule.class) { - //don't do instanceof check, since we only want to check if the modules are exactly identical - CountBlocksModule other = (CountBlocksModule) obj; - return this.searchName.equals(other.searchName) && this.meta == other.meta; - } else { - return false; - } - } - - protected static final class CountData extends PositionDataXZ { - public final long count; - - public CountData(Vec2i vec, long count) { - super(vec); - - this.count = count; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountTileEntitiesModule.java b/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountTileEntitiesModule.java deleted file mode 100644 index 0020692..0000000 --- a/src/main/java/net/daporkchop/savesearcher/module/impl/count/CountTileEntitiesModule.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.module.impl.count; - -import lombok.AccessLevel; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import net.daporkchop.lib.math.vector.i.Vec2i; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.world.Chunk; -import net.daporkchop.lib.minecraft.world.Section; -import net.daporkchop.lib.minecraft.world.World; -import net.daporkchop.savesearcher.module.AbstractSearchModule; -import net.daporkchop.savesearcher.module.PositionDataXZ; -import net.daporkchop.savesearcher.output.OutputHandle; - -/** - * @author DaPorkchop_ - */ -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public final class CountTileEntitiesModule extends AbstractSearchModule { - protected final ResourceLocation filterId; - - @Override - protected void processChunk(@NonNull Chunk chunk, @NonNull OutputHandle handle) { - long count; - if (this.filterId == null) { - count = chunk.tileEntities().size(); - } else { - count = chunk.tileEntities().stream().filter(tileEntity -> this.filterId.equals(tileEntity.id())).count(); - } - handle.accept(new CountBlocksModule.CountData(chunk.pos(), count)); - } - - @Override - public String toString() { - if (this.filterId == null) { - return "Count - Tile Entities"; - } else { - return String.format("Count - Tile Entities (id=%s)", this.filterId); - } - } - - @Override - public int hashCode() { - return this.filterId == null ? CountTileEntitiesModule.class.hashCode() : this.filterId.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } else if (obj instanceof CountTileEntitiesModule) { - CountTileEntitiesModule other = (CountTileEntitiesModule) obj; - if (this.filterId == null) { - return other.filterId == null; - } else { - return this.filterId.equals(other.filterId); - } - } else { - return false; - } - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/output/OutputHandle.java b/src/main/java/net/daporkchop/savesearcher/output/OutputHandle.java index 5b32370..8771c7f 100644 --- a/src/main/java/net/daporkchop/savesearcher/output/OutputHandle.java +++ b/src/main/java/net/daporkchop/savesearcher/output/OutputHandle.java @@ -29,8 +29,8 @@ * * @author DaPorkchop_ */ -public interface OutputHandle extends AutoCloseable { - void init(@NonNull SearchModule module); +public interface OutputHandle extends AutoCloseable { + void init(@NonNull SearchModule module); @Override void close() throws IOException; diff --git a/src/main/java/net/daporkchop/savesearcher/output/csv/CSVOutputHandle.java b/src/main/java/net/daporkchop/savesearcher/output/csv/CSVOutputHandle.java index c0c0293..f20fdd7 100644 --- a/src/main/java/net/daporkchop/savesearcher/output/csv/CSVOutputHandle.java +++ b/src/main/java/net/daporkchop/savesearcher/output/csv/CSVOutputHandle.java @@ -23,11 +23,11 @@ import net.daporkchop.lib.binary.oio.appendable.PAppendable; import net.daporkchop.lib.binary.oio.writer.UTF8FileWriter; import net.daporkchop.lib.common.misc.file.PFiles; -import net.daporkchop.lib.common.pool.handle.DefaultThreadHandledPool; import net.daporkchop.lib.common.pool.handle.Handle; -import net.daporkchop.lib.common.pool.handle.HandledPool; import net.daporkchop.lib.common.system.OperatingSystem; import net.daporkchop.lib.common.system.PlatformInfo; +import net.daporkchop.lib.common.util.GenericMatcher; +import net.daporkchop.lib.common.util.PorkUtil; import net.daporkchop.lib.reflection.PField; import net.daporkchop.savesearcher.module.SearchModule; import net.daporkchop.savesearcher.output.OutputHandle; @@ -44,15 +44,13 @@ /** * @author DaPorkchop_ */ -public class CSVOutputHandle implements OutputHandle { - protected static final HandledPool BUILDER_CACHE = new DefaultThreadHandledPool<>(StringBuilder::new, 2); - +public class CSVOutputHandle implements OutputHandle { protected final File parent; - protected Class clazz; - protected List> fields; + protected Class clazz; + protected List> fields; protected Function[] mappers; - protected PAppendable output; + protected PAppendable output; public CSVOutputHandle(@NonNull File parent) { this.parent = PFiles.ensureDirectoryExists(parent); @@ -60,10 +58,10 @@ public CSVOutputHandle(@NonNull File parent) { @Override @SuppressWarnings("unchecked") - public void init(@NonNull SearchModule module) { + public void init(@NonNull SearchModule module) { this.fields = new ArrayList<>(); - Class clazz = this.clazz = module.dataType(); + Class clazz = this.clazz = GenericMatcher.find(module.getClass(), SearchModule.class, "R"); while (clazz != Object.class) { int i = 0; for (PField field : Arrays.stream(clazz.getDeclaredFields()) @@ -136,8 +134,8 @@ public void accept(@NonNull Object data) { throw new IllegalArgumentException(String.format("Expected %s but got %s!", this.clazz, data.getClass())); } - try (Handle handle = BUILDER_CACHE.get()) { - StringBuilder builder = handle.value(); + try (Handle handle = PorkUtil.STRINGBUILDER_POOL.get()) { + StringBuilder builder = handle.get(); builder.setLength(0); for (int i = 0, length = this.mappers.length; i < length; i++) { builder.append(this.mappers[i].apply(data)).append(','); diff --git a/src/main/java/net/daporkchop/savesearcher/output/csv/CompressedCSVOutputHandle.java b/src/main/java/net/daporkchop/savesearcher/output/csv/CompressedCSVOutputHandle.java index b41bddc..ce706b9 100644 --- a/src/main/java/net/daporkchop/savesearcher/output/csv/CompressedCSVOutputHandle.java +++ b/src/main/java/net/daporkchop/savesearcher/output/csv/CompressedCSVOutputHandle.java @@ -22,23 +22,17 @@ import lombok.NonNull; import net.daporkchop.lib.binary.oio.appendable.PAppendable; import net.daporkchop.lib.binary.oio.writer.UTF8FileWriter; -import net.daporkchop.lib.common.misc.file.PFiles; -import net.daporkchop.lib.common.system.OperatingSystem; import net.daporkchop.lib.common.system.PlatformInfo; -import net.daporkchop.lib.unsafe.PUnsafe; -import net.daporkchop.savesearcher.module.SearchModule; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; import java.util.zip.GZIPOutputStream; /** * @author DaPorkchop_ */ -public final class CompressedCSVOutputHandle extends CSVOutputHandle { +public final class CompressedCSVOutputHandle extends CSVOutputHandle { public CompressedCSVOutputHandle(@NonNull File parent) { super(parent); } diff --git a/src/main/java/net/daporkchop/savesearcher/tileentity/TileEntitySpawner.java b/src/main/java/net/daporkchop/savesearcher/tileentity/TileEntitySpawner.java deleted file mode 100644 index 0664ca8..0000000 --- a/src/main/java/net/daporkchop/savesearcher/tileentity/TileEntitySpawner.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Adapted from The MIT License (MIT) - * - * Copyright (c) 2018-2020 DaPorkchop_ - * - * 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: - * - * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, - * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. - * - * 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 net.daporkchop.savesearcher.tileentity; - -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.daporkchop.lib.minecraft.registry.ResourceLocation; -import net.daporkchop.lib.minecraft.tileentity.TileEntityBase; -import net.daporkchop.lib.nbt.tag.notch.CompoundTag; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author DaPorkchop_ - */ -@Getter -@Accessors(fluent = true) -public final class TileEntitySpawner extends TileEntityBase { - public static final ResourceLocation ID = new ResourceLocation("minecraft:mob_spawner"); - - protected List entries = Collections.emptyList(); - - @Override - protected void doInit(@NonNull CompoundTag nbt) { - if (nbt.contains("SpawnPotentials")) { - this.entries = Collections.unmodifiableList(nbt.getList("SpawnPotentials").stream() - .map(tag -> new SpawnerEntry(new ResourceLocation(tag.getCompound("Entity").getString("id")), tag.getInt("Weight"))) - .collect(Collectors.toList())); - } else { - this.entries = Collections.singletonList(new SpawnerEntry( - new ResourceLocation(nbt.getCompound("SpawnData").getString("id")), - 1 - )); - } - } - - @Override - protected void doDeinit() { - this.entries = Collections.emptyList(); - } - - @Override - public ResourceLocation id() { - return ID; - } - - /** - * Checks if this spawner is capable of spawning the given entity type. - * - * @param id the id of the entity - * @return whether or not this spawner can spawn entities with the given id - */ - public boolean canSpawn(@NonNull ResourceLocation id) { - for (int i = 0, size = this.entries.size(); i < size; i++) { - if (this.entries.get(i).id.equals(id)) { - return true; - } - } - return false; - } - - /** - * An entry representing the chance a mob has of being spawned by a spawner block. - * - * @author DaPorkchop_ - */ - @RequiredArgsConstructor - @Getter - @Accessors(fluent = true) - public static final class SpawnerEntry { - protected final ResourceLocation id; - protected final int weight; - } -} diff --git a/src/main/java/net/daporkchop/savesearcher/util/NBTHelper.java b/src/main/java/net/daporkchop/savesearcher/util/NBTHelper.java index 84f3266..a563512 100644 --- a/src/main/java/net/daporkchop/savesearcher/util/NBTHelper.java +++ b/src/main/java/net/daporkchop/savesearcher/util/NBTHelper.java @@ -30,18 +30,18 @@ import net.daporkchop.lib.common.pool.handle.Handle; import net.daporkchop.lib.common.util.PorkUtil; import net.daporkchop.lib.nbt.tag.Tag; -import net.daporkchop.lib.nbt.tag.notch.ByteArrayTag; -import net.daporkchop.lib.nbt.tag.notch.ByteTag; -import net.daporkchop.lib.nbt.tag.notch.CompoundTag; -import net.daporkchop.lib.nbt.tag.notch.DoubleTag; -import net.daporkchop.lib.nbt.tag.notch.FloatTag; -import net.daporkchop.lib.nbt.tag.notch.IntArrayTag; -import net.daporkchop.lib.nbt.tag.notch.IntTag; -import net.daporkchop.lib.nbt.tag.notch.ListTag; -import net.daporkchop.lib.nbt.tag.notch.LongArrayTag; -import net.daporkchop.lib.nbt.tag.notch.LongTag; -import net.daporkchop.lib.nbt.tag.notch.ShortTag; -import net.daporkchop.lib.nbt.tag.notch.StringTag; +import net.daporkchop.lib.nbt.tag.ByteArrayTag; +import net.daporkchop.lib.nbt.tag.ByteTag; +import net.daporkchop.lib.nbt.tag.CompoundTag; +import net.daporkchop.lib.nbt.tag.DoubleTag; +import net.daporkchop.lib.nbt.tag.FloatTag; +import net.daporkchop.lib.nbt.tag.IntArrayTag; +import net.daporkchop.lib.nbt.tag.IntTag; +import net.daporkchop.lib.nbt.tag.ListTag; +import net.daporkchop.lib.nbt.tag.LongArrayTag; +import net.daporkchop.lib.nbt.tag.LongTag; +import net.daporkchop.lib.nbt.tag.ShortTag; +import net.daporkchop.lib.nbt.tag.StringTag; import java.io.IOException; @@ -75,19 +75,19 @@ private JsonElement toJson0(Tag nbt) { ((ListTag) nbt).forEach(tag -> array.add(toJson0(tag))); return array; } else if (nbt instanceof ByteTag) { - return new JsonPrimitive(((ByteTag) nbt).getValue()); + return new JsonPrimitive(((ByteTag) nbt).value()); } else if (nbt instanceof DoubleTag) { - return new JsonPrimitive(((DoubleTag) nbt).getValue()); + return new JsonPrimitive(((DoubleTag) nbt).value()); } else if (nbt instanceof FloatTag) { - return new JsonPrimitive(((FloatTag) nbt).getValue()); + return new JsonPrimitive(((FloatTag) nbt).value()); } else if (nbt instanceof IntTag) { - return new JsonPrimitive(((IntTag) nbt).getValue()); + return new JsonPrimitive(((IntTag) nbt).value()); } else if (nbt instanceof LongTag) { - return new JsonPrimitive(((LongTag) nbt).getValue()); + return new JsonPrimitive(((LongTag) nbt).value()); } else if (nbt instanceof ShortTag) { - return new JsonPrimitive(((ShortTag) nbt).getValue()); + return new JsonPrimitive(((ShortTag) nbt).value()); } else if (nbt instanceof StringTag) { - return new JsonPrimitive(((StringTag) nbt).getValue()); + return new JsonPrimitive(((StringTag) nbt).value()); } else if (nbt instanceof ByteArrayTag) { JsonArray array = new JsonArray(); for (byte b : ((ByteArrayTag) nbt).value()) { @@ -102,7 +102,7 @@ private JsonElement toJson0(Tag nbt) { return array; } else if (nbt instanceof LongArrayTag) { JsonArray array = new JsonArray(); - for (long l : ((LongArrayTag) nbt).getValue()) { + for (long l : ((LongArrayTag) nbt).value()) { array.add(l); } return array; diff --git a/src/main/java/net/daporkchop/savesearcher/util/Version.java b/src/main/java/net/daporkchop/savesearcher/util/Version.java index 513f642..fc0eb8b 100644 --- a/src/main/java/net/daporkchop/savesearcher/util/Version.java +++ b/src/main/java/net/daporkchop/savesearcher/util/Version.java @@ -19,22 +19,12 @@ package net.daporkchop.savesearcher.util; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import lombok.NonNull; import lombok.experimental.UtilityClass; -import net.daporkchop.lib.http.Http; -import net.daporkchop.lib.logging.Logging; -import net.daporkchop.savesearcher.Main; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static net.daporkchop.lib.logging.Logging.*; - /** * @author DaPorkchop_ */ @@ -43,7 +33,8 @@ public class Version { public final String VERSION; static { - try { + VERSION = "unknown"; + /*try { JsonParser parser = new JsonParser(); JsonObject local; try (Reader reader = new InputStreamReader(Main.class.getResourceAsStream("/version.json"))) { @@ -73,12 +64,12 @@ public class Version { VERSION = local.get("nameNew").getAsString().replaceAll(" ", ""); } catch (IOException e) { throw new RuntimeException(e); - } + }*/ } - private int toVersionNumber(@NonNull String version) { + private int toVersionNumber(@NonNull String version) { Matcher matcher = Pattern.compile("^ *?([0-9]+)\\. *?([0-9]+)\\. *?([0-9]+)$").matcher(version); - if (!matcher.find()) { + if (!matcher.find()) { throw new IllegalArgumentException(version); } return Integer.parseInt(matcher.group(1)) * 1000000 + Integer.parseInt(matcher.group(2)) * 1000 + Integer.parseInt(matcher.group(3));