Skip to content

Commit aa090ef

Browse files
committed
Improve biome locating
1 parent 7dc8407 commit aa090ef

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/main/java/dev/xpple/seedmapper/command/CommandExceptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private CommandExceptions() {
3333
public static final DynamicCommandExceptionType NO_CANYON_FOUND_EXCEPTION = new DynamicCommandExceptionType(arg -> Component.translatable("commands.exceptions.noCanyonFound", arg));
3434
public static final SimpleCommandExceptionType INVALID_DIMENSION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.invalidDimension"));
3535
public static final SimpleCommandExceptionType INCOMPATIBLE_PARAMETERS_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.incompatibleParameters"));
36+
public static final SimpleCommandExceptionType BIOME_WRONG_VERSION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.biomeWrongVersion"));
3637
public static final SimpleCommandExceptionType ORE_VEIN_WRONG_VERSION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.oreVeinWrongVersion"));
3738
public static final SimpleCommandExceptionType CANYON_WRONG_VERSION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.canyonWrongVersion"));
3839
public static final SimpleCommandExceptionType CAVE_WRONG_VERSION_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.exceptions.caveWrongVersion"));

src/main/java/dev/xpple/seedmapper/command/commands/LocateCommand.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import dev.xpple.seedmapper.util.WorldIdentifier;
3232
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
3333
import net.minecraft.core.BlockPos;
34+
import net.minecraft.core.QuartPos;
3435
import net.minecraft.core.SectionPos;
3536
import net.minecraft.network.chat.Component;
37+
import net.minecraft.util.Mth;
3638
import net.minecraft.util.RandomSource;
3739
import net.minecraft.world.level.ChunkPos;
3840
import net.minecraft.world.level.Level;
@@ -65,7 +67,9 @@
6567

6668
public class LocateCommand {
6769

68-
private static final int BIOME_SEARCH_RADIUS = 6400;
70+
private static final int BIOME_SEARCH_RADIUS = 25600;
71+
private static final int BIOME_SEARCH_HORIZONTAL_STEP = 32;
72+
private static final int BIOME_SEARCH_VERTICAL_STEP = 64;
6973

7074
public static final Set<Integer> LOOT_SUPPORTED_STRUCTURES = Set.of(Cubiomes.Treasure(), Cubiomes.Desert_Pyramid(), Cubiomes.End_City(), Cubiomes.Igloo(), Cubiomes.Jungle_Pyramid(), Cubiomes.Ruined_Portal(), Cubiomes.Ruined_Portal_N(), Cubiomes.Fortress(), Cubiomes.Bastion(), Cubiomes.Outpost(), Cubiomes.Shipwreck());
7175

@@ -101,18 +105,31 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
101105
private static int locateBiome(CustomClientCommandSource source, int biome) throws CommandSyntaxException {
102106
SeedIdentifier seed = source.getSeed().getSecond();
103107
int dimension = source.getDimension();
108+
int version = source.getVersion();
104109
if (Cubiomes.getDimension(biome) != dimension) {
105110
throw CommandExceptions.INVALID_DIMENSION_EXCEPTION.create();
106111
}
112+
if (Cubiomes.biomeExists(version, biome) == 0) {
113+
throw CommandExceptions.BIOME_WRONG_VERSION_EXCEPTION.create();
114+
}
107115
try (Arena arena = Arena.ofConfined()) {
108116
MemorySegment generator = Generator.allocate(arena);
109-
Cubiomes.setupGenerator(generator, source.getVersion(), source.getGeneratorFlags());
117+
Cubiomes.setupGenerator(generator, version, source.getGeneratorFlags());
110118
Cubiomes.applySeed(generator, dimension, seed.seed());
111119

112120
BlockPos center = BlockPos.containing(source.getPosition());
113121

114-
SpiralLoop.Coordinate pos = SpiralLoop.spiral(center.getX(), center.getZ(), BIOME_SEARCH_RADIUS, 32, (x, z) -> {
115-
return Cubiomes.getBiomeAt(generator, 1, x, 63, z) == biome;
122+
int minY = version <= Cubiomes.MC_1_17_1() ? 0 : -64;
123+
int maxY = version <= Cubiomes.MC_1_17_1() ? 256 : 320;
124+
int[] ys = Mth.outFromOrigin(center.getY(), minY + 1, maxY + 1, BIOME_SEARCH_VERTICAL_STEP).toArray();
125+
126+
SpiralLoop.Coordinate pos = SpiralLoop.spiral(center.getX(), center.getZ(), BIOME_SEARCH_RADIUS, BIOME_SEARCH_HORIZONTAL_STEP, (x, z) -> {
127+
for (int y : ys) {
128+
if (Cubiomes.getBiomeAt(generator, 4, QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)) == biome) {
129+
return true;
130+
}
131+
}
132+
return false;
116133
});
117134
if (pos == null) {
118135
throw CommandExceptions.NO_BIOME_FOUND_EXCEPTION.create(BIOME_SEARCH_RADIUS);

src/main/resources/assets/seedmapper/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"commands.exceptions.unknownDensityFunction": "Unknown density function \"%s\".",
2727
"commands.exceptions.unknownMapFeature": "Unknown map feature \"%s\".",
2828
"commands.exceptions.incompatibleParameters": "Incompatible parameters.",
29+
"commands.exceptions.biomeWrongVersion": "Biome does not exist in this version!",
2930
"commands.exceptions.oreVeinWrongVersion": "Ore veins only exist after version 1.18!",
3031
"commands.exceptions.canyonWrongVersion": "Invalid version for canyon carver!",
3132
"commands.exceptions.caveWrongVersion": "Invalid version for cave carver!",

0 commit comments

Comments
 (0)