diff --git a/src/main/java/dev/xpple/seedmapper/command/SharedExceptions.java b/src/main/java/dev/xpple/seedmapper/command/SharedExceptions.java index af8f355..ce15e40 100644 --- a/src/main/java/dev/xpple/seedmapper/command/SharedExceptions.java +++ b/src/main/java/dev/xpple/seedmapper/command/SharedExceptions.java @@ -1,12 +1,14 @@ package dev.xpple.seedmapper.command; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.text.TranslatableText; public interface SharedExceptions { DynamicCommandExceptionType NULL_POINTER_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.nullPointerException", arg)); DynamicCommandExceptionType DIMENSION_NOT_SUPPORTED_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.dimensionNotSupported", arg)); DynamicCommandExceptionType VERSION_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.versionNotFound", arg)); + SimpleCommandExceptionType INVALID_DIMENSION_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.exceptions.invalidDimension")); DynamicCommandExceptionType BIOME_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.biomeNotFound", arg)); DynamicCommandExceptionType STRUCTURE_NOT_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> new TranslatableText("commands.exceptions.structureNotFound", arg)); } diff --git a/src/main/java/dev/xpple/seedmapper/command/commands/LocateCommand.java b/src/main/java/dev/xpple/seedmapper/command/commands/LocateCommand.java index 057f7ad..098c6e7 100644 --- a/src/main/java/dev/xpple/seedmapper/command/commands/LocateCommand.java +++ b/src/main/java/dev/xpple/seedmapper/command/commands/LocateCommand.java @@ -14,6 +14,7 @@ import kaptainwutax.biomeutils.source.BiomeSource; import kaptainwutax.featureutils.Feature; import kaptainwutax.featureutils.misc.SlimeChunk; +import kaptainwutax.featureutils.structure.Mineshaft; import kaptainwutax.featureutils.structure.RegionStructure; import kaptainwutax.featureutils.structure.Stronghold; import kaptainwutax.featureutils.structure.Structure; @@ -130,7 +131,10 @@ private int locateBiome(FabricClientCommandSource source, String biomeName, Stri return Command.SINGLE_SUCCESS; } - private static BPos locateBiome(Biome biome, int centerX, int centerZ, int radius, int increment, BiomeSource biomeSource) { + private static BPos locateBiome(Biome biome, int centerX, int centerZ, int radius, int increment, BiomeSource biomeSource) throws CommandSyntaxException { + if (biome.getDimension() != biomeSource.getDimension()) { + throw INVALID_DIMENSION_EXCEPTION.create(); + } if (biome.equals(biomeSource.getBiome(centerX, 0, centerZ))) { return new BPos(centerX, 0, centerZ); } @@ -217,7 +221,10 @@ private int locateStructure(FabricClientCommandSource source, String structureNa return Command.SINGLE_SUCCESS; } - private static BPos locateStructure(Structure structure, BPos currentPos, int radius, ChunkRand chunkRand, BiomeSource source, TerrainGenerator terrainGenerator, int dimCoeff) { + private static BPos locateStructure(Structure structure, BPos currentPos, int radius, ChunkRand chunkRand, BiomeSource source, TerrainGenerator terrainGenerator, int dimCoeff) throws CommandSyntaxException { + if (!structure.isValidDimension(source.getDimension())) { + throw INVALID_DIMENSION_EXCEPTION.create(); + } if (structure instanceof RegionStructure regionStructure) { int chunkInRegion = regionStructure.getSpacing(); int regionSize = chunkInRegion * 16; @@ -262,6 +269,27 @@ private static BPos locateStructure(Structure structure, BPos currentPos, } BPos dimPos = closest.toBlockPos().add(9, 0, 9); return new BPos(dimPos.getX() << dimCoeff, 0, dimPos.getZ() << dimCoeff); + } else if (structure instanceof Mineshaft mineshaft) { + int x = currentPos.getX() >> 4; + int z = currentPos.getZ() >> 4; + + float n = 1; + int floorN = 1; + for (int i = 0; floorN / 2 < radius; i++, n += 0.5) { + floorN = (int) Math.floor(n); + for (int j = 0; j < floorN; j++) { + switch (i % 4) { + case 0 -> z++; + case 1 -> x++; + case 2 -> z--; + case 3 -> x--; + } + Feature.Data data = mineshaft.at(x, z); + if (data.testStart(source.getWorldSeed(), chunkRand) && data.testBiome(source) && data.testGenerate(terrainGenerator)) { + return new BPos(x << 4, 0, z << 4); + } + } + } } } return null; @@ -295,7 +323,7 @@ private static int locateSlimeChunk(FabricClientCommandSource source, String ver BlockPos center = CLIENT.player.getBlockPos(); - CPos slimeChunkPos = locateSlimeChunk(new SlimeChunk(mcVersion), center.getX(), center.getZ(), 6400, seed, new ChunkRand(seed)); + CPos slimeChunkPos = locateSlimeChunk(new SlimeChunk(mcVersion), center.getX(), center.getZ(), 6400, seed, new ChunkRand(seed), dimension); if (slimeChunkPos == null) { Chat.print("", new TranslatableText("command.locate.feature.slimeChunk.noneFound")); } else { @@ -324,7 +352,10 @@ private static int locateSlimeChunk(FabricClientCommandSource source, String ver return Command.SINGLE_SUCCESS; } - private static CPos locateSlimeChunk(SlimeChunk slimeChunk, int centerX, int centerZ, int radius, long seed, ChunkRand rand) { + private static CPos locateSlimeChunk(SlimeChunk slimeChunk, int centerX, int centerZ, int radius, long seed, ChunkRand rand, Dimension dimension) throws CommandSyntaxException { + if (!slimeChunk.isValidDimension(dimension)) { + throw INVALID_DIMENSION_EXCEPTION.create(); + } int x = centerX >> 4; int z = centerZ >> 4; diff --git a/src/main/resources/assets/seedmapper/lang/en_us.json b/src/main/resources/assets/seedmapper/lang/en_us.json index fd7dc6e..4365452 100644 --- a/src/main/resources/assets/seedmapper/lang/en_us.json +++ b/src/main/resources/assets/seedmapper/lang/en_us.json @@ -3,6 +3,7 @@ "commands.exceptions.versionNotFound": "Version \"%s\" was not found.", "commands.exceptions.unknownConfig": "Unknown config \"%s\".", "commands.exceptions.nullPointerException": "\"%s\" is null.", + "commands.exceptions.invalidDimension": "Invalid dimension.", "commands.exceptions.biomeNotFound": "Biome \"%s\" was not found.", "commands.exceptions.structureNotFound": "Structure \"%s\" was not found.",