Skip to content

Commit

Permalink
Add stronghold locating
Browse files Browse the repository at this point in the history
  • Loading branch information
xpple committed Nov 5, 2024
1 parent d90729d commit fb917cc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.cubiomes.Cubiomes;
import com.github.cubiomes.Generator;
import com.github.cubiomes.Pos;
import com.github.cubiomes.StrongholdIter;
import com.github.cubiomes.StructureConfig;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
Expand All @@ -20,6 +21,9 @@

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

import static dev.xpple.seedmapper.command.arguments.BiomeArgument.*;
import static dev.xpple.seedmapper.command.arguments.StructureArgument.*;
Expand All @@ -37,6 +41,8 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(literal("structure")
.then(argument("structure", structure())
.executes(ctx -> locateStructure(CustomClientCommandSource.of(ctx.getSource()), getStructure(ctx, "structure")))))
.then(literal("stronghold")
.executes(ctx -> locateStronghold(CustomClientCommandSource.of(ctx.getSource()))))
.then(literal("slimechunk")
.executes(ctx -> locateSlimeChunk(CustomClientCommandSource.of(ctx.getSource())))))
.then(literal("spawn")
Expand Down Expand Up @@ -123,6 +129,48 @@ private static int locateStructure(CustomClientCommandSource source, int structu
}
}

private static int locateStronghold(CustomClientCommandSource source) throws CommandSyntaxException {
int dimension = source.getDimension();
if (dimension != Cubiomes.DIM_OVERWORLD()) {
throw CommandExceptions.INVALID_DIMENSION_EXCEPTION.create();
}
int version = source.getVersion();
long seed = source.getSeed().getSecond();

BlockPos position = BlockPos.containing(source.getPosition());

try (Arena arena = Arena.ofConfined()) {
SortedSet<MemorySegment> strongholdLocations = new TreeSet<>(Comparator.comparingDouble(o -> position.distToLowCornerSqr(Pos.x(o), position.getY(), Pos.z(o))));

MemorySegment strongholdIter = StrongholdIter.allocate(arena);
Cubiomes.initFirstStronghold(arena, strongholdIter, version, seed);
MemorySegment generator = Generator.allocate(arena);
Cubiomes.setupGenerator(generator, version, 0);
Cubiomes.applySeed(generator, dimension, seed);

for (int i = 0; i < 12; i++) {
if (Cubiomes.nextStronghold(strongholdIter, generator) == 0) {
break;
}
MemorySegment pos = Pos.allocate(arena);
strongholdLocations.add(pos.copyFrom(StrongholdIter.pos(strongholdIter)));
}

MemorySegment pos = strongholdLocations.getFirst();

source.sendFeedback(chain(
highlight(Component.translatable("command.locate.feature.stronghold.success", copy(
hover(
accent("x: %d, z: %d".formatted(Pos.x(pos), Pos.z(pos))),
base(Component.translatable("chat.copy.click"))
),
"%d ~ %d".formatted(Pos.x(pos), Pos.z(pos))
)))
));
return Command.SINGLE_SUCCESS;
}
}

private static int locateSlimeChunk(CustomClientCommandSource source) throws CommandSyntaxException {
if (source.getDimension() != Cubiomes.DIM_OVERWORLD()) {
throw CommandExceptions.INVALID_DIMENSION_EXCEPTION.create();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/seedmapper/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

"command.locate.biome.foundAt": "Biome found at",
"command.locate.feature.structure.foundAt": "Structure found at",
"command.locate.feature.stronghold.success": "Stronghold found at %s.",
"command.locate.feature.slimeChunk.noneFound": "Couldn't locate a slime chunk within 6400 blocks.",
"command.locate.feature.slimeChunk.foundAt": "Slime chunk found at",
"command.locate.feature.slimeChunk.copy": "Click to copy coordinates of this slime chunk",
Expand Down

0 comments on commit fb917cc

Please sign in to comment.