Skip to content

Commit 2c04fff

Browse files
committed
Added Locate Loot, Locate From Coordinates, Updated Option Menu UI
1 parent 8a5dfc7 commit 2c04fff

2 files changed

Lines changed: 501 additions & 97 deletions

File tree

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

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class LocateCommand {
7373

7474
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());
7575

76+
public record LootStructureResult(String structureName, int count, List<BlockPos> positions) {}
77+
public record LootLocateResult(int totalFound, String itemName, BlockPos pos, List<LootStructureResult> structureResults) {}
78+
7679
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
7780
dispatcher.register(literal("sm:locate")
7881
.then(literal("biome")
@@ -301,23 +304,33 @@ private static int locateSlimeChunk(CustomClientCommandSource source) throws Com
301304
}
302305

303306
private static int locateLoot(CustomClientCommandSource source, int amount, EnchantedItem itemPredicate) throws CommandSyntaxException {
304-
SeedIdentifier seed = source.getSeed().getSecond();
305-
int version = source.getVersion();
307+
LootLocateResult result = calculateLoot(BlockPos.containing(source.getPosition()), source.getSeed().getSecond().seed(), source.getVersion(), source.getDimension(), source.getGeneratorFlags(), amount, itemPredicate);
308+
result.structureResults().forEach(structureResult -> source.getClient().schedule(() -> source.sendFeedback(Component.translatable(
309+
"command.locate.loot.foundAtStructure",
310+
accent(String.valueOf(structureResult.count())),
311+
structureResult.structureName(),
312+
ComponentUtils.formatXZCollection(structureResult.positions())
313+
))));
314+
source.getClient().schedule(() -> source.sendFeedback(Component.translatable(
315+
"command.locate.loot.totalFound",
316+
accent(String.valueOf(result.totalFound())),
317+
result.itemName()
318+
)));
319+
return result.totalFound();
320+
}
321+
322+
public static LootLocateResult calculateLoot(BlockPos center, long seed, int version, int dimension, int generatorFlags, int amount, EnchantedItem itemPredicate) throws CommandSyntaxException {
306323
if (version <= Cubiomes.MC_1_12()) {
307324
throw CommandExceptions.LOOT_NOT_SUPPORTED_EXCEPTION.create();
308325
}
309-
int dimension = source.getDimension();
310-
int generatorFlags = source.getGeneratorFlags();
311326

312327
try (Arena arena = Arena.ofConfined()) {
313328
MemorySegment generator = Generator.allocate(arena);
314329
Cubiomes.setupGenerator(generator, version, generatorFlags);
315-
Cubiomes.applySeed(generator, dimension, seed.seed());
330+
Cubiomes.applySeed(generator, dimension, seed);
316331

317332
MemorySegment surfaceNoise = SurfaceNoise.allocate(arena);
318-
Cubiomes.initSurfaceNoise(surfaceNoise, dimension, seed.seed());
319-
320-
BlockPos center = BlockPos.containing(source.getPosition());
333+
Cubiomes.initSurfaceNoise(surfaceNoise, dimension, seed);
321334

322335
record StructureIterationState(MemorySegment structureConfig, StructureChecks.GenerationCheck generationCheck, SpiralSpliterator iterator) {
323336
}
@@ -348,6 +361,8 @@ record StructureIterationState(MemorySegment structureConfig, StructureChecks.Ge
348361
MemorySegment structureVariant = StructureVariant.allocate(arena);
349362
MemorySegment structureSaltConfig = StructureSaltConfig.allocate(arena);
350363
int[] found = {0};
364+
BlockPos[] primaryPos = {null};
365+
List<LootStructureResult> structureResults = new ArrayList<>();
351366

352367
/*
353368
* To locate loot closest to the player, all structures
@@ -389,12 +404,12 @@ record StructureIterationState(MemorySegment structureConfig, StructureChecks.Ge
389404
int posX = Pos.x(structurePos);
390405
int posZ = Pos.z(structurePos);
391406
int biome = Cubiomes.getBiomeAt(generator, 4, posX >> 2, 320 >> 2, posZ >> 2);
392-
Cubiomes.getVariant(structureVariant, structure, version, seed.seed(), posX, posZ, biome);
407+
Cubiomes.getVariant(structureVariant, structure, version, seed, posX, posZ, biome);
393408
biome = StructureVariant.biome(structureVariant) != -1 ? StructureVariant.biome(structureVariant) : biome;
394409
if (Cubiomes.getStructureSaltConfig(structure, version, biome, structureSaltConfig) == 0) {
395410
return;
396411
}
397-
int numPieces = Cubiomes.getStructurePieces(pieces, StructureChecks.MAX_END_CITY_AND_FORTRESS_PIECES, structure, structureSaltConfig, structureVariant, version, seed.seed(), posX, posZ);
412+
int numPieces = Cubiomes.getStructurePieces(pieces, StructureChecks.MAX_END_CITY_AND_FORTRESS_PIECES, structure, structureSaltConfig, structureVariant, version, seed, posX, posZ);
398413
if (numPieces <= 0) {
399414
return;
400415
}
@@ -438,6 +453,9 @@ record StructureIterationState(MemorySegment structureConfig, StructureChecks.Ge
438453
if (foundInStructure > 0) {
439454
found[0] += foundInStructure;
440455
aggregatedLootPositions.add(new BlockPos(posX, 0, posZ));
456+
if (primaryPos[0] == null) {
457+
primaryPos[0] = new BlockPos(posX, 0, posZ);
458+
}
441459
}
442460
});
443461
if (exhausted) {
@@ -455,15 +473,14 @@ record StructureIterationState(MemorySegment structureConfig, StructureChecks.Ge
455473
int newlyFound = found[0] - previouslyFound;
456474
if (newlyFound > 0) {
457475
String structureName = Cubiomes.struct2str(StructureConfig.structType(structureConfig)).getString(0);
458-
source.getClient().schedule(() -> source.sendFeedback(Component.translatable("command.locate.loot.foundAtStructure", accent(String.valueOf(newlyFound)), structureName, ComponentUtils.formatXZCollection(aggregatedLootPositions))));
476+
structureResults.add(new LootStructureResult(structureName, newlyFound, List.copyOf(aggregatedLootPositions)));
459477
}
460478
if (found[0] >= amount) {
461479
break;
462480
}
463481
}
464482
String itemName = Cubiomes.global_id2item_name(itemPredicate.item(), version).getString(0);
465-
source.getClient().schedule(() -> source.sendFeedback(Component.translatable("command.locate.loot.totalFound", accent(String.valueOf(found[0])), itemName)));
466-
return found[0];
483+
return new LootLocateResult(found[0], itemName, primaryPos[0] == null ? center : primaryPos[0], List.copyOf(structureResults));
467484
}
468485
}
469486

0 commit comments

Comments
 (0)