This library is used by the mod on the map and I need to add an item through which this map will work, I did it.
Now I need the territory to be saved in the map only if there is a certain item in the inventory.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Based on the provided repository code, I can help you modify the territory scanning functionality to only work when a specific item is present in the player's inventory. The main scanning logic appears to happen in the Surveyor class.
Here's how you can implement this:
First, modify the checkStructureExploration method in Surveyor.java. You'll need to add an inventory check before proceeding with the exploration:
[Redacted
public static void checkStructureExploration(ServerWorld world, ServerPlayerEntity player, BlockPos pos) {
// Add inventory check here
if (!hasMapItem(player)) {
return;
}
if (!world.isChunkLoaded(pos.getX() >> 4, pos.getZ() >> 4)) return;
// ... rest of the existing method
}
// Add this helper method
private static boolean hasMapItem(ServerPlayerEntity player) {
// Replace YOUR_MAP_ITEM with your actual map item
return player.getInventory().contains(YOUR_MAP_ITEM.getDefaultStack());
}
Similarly, you'll want to modify the terrain scanning functionality. Looking at the code, terrain updates are handled through the ServerChunkEvents.CHUNK_LOAD event in the Surveyor class's onInitialize method.
You can modify the event handlers to include the item check:
[Redacted
@[Redacted Person]
public void onInitialize() {
SurveyorNetworking.init();
CommandRegistrationCallback.EVENT.register(SurveyorCommands::registerCommands);
ServerPlayConnectionEvents.JOIN.register(ServerSummary::onPlayerJoin);
// Modify the chunk load handlers
ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> {
ServerPlayerEntity nearestPlayer = findNearestPlayer(world, chunk.getPos());
if (nearestPlayer != null && hasMapItem(nearestPlayer)) {
WorldTerrainSummary.onChunkLoad(world, chunk);
}
});
ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> {
ServerPlayerEntity nearestPlayer = findNearestPlayer(world, chunk.getPos());
if (nearestPlayer != null && hasMapItem(nearestPlayer)) {
WorldStructureSummary.onChunkLoad(world, chunk);
}
});
// ... rest of the initialization
}
private static ServerPlayerEntity findNearestPlayer(ServerWorld world, ChunkPos pos) {
// Find the nearest player to the chunk
// This is a simple implementation - you might want to add distance checks
return world.getClosestPlayer(
pos.getStartX() + 8,
64, // middle Y coordinate
pos.getStartZ() + 8,
128, // reasonable search radius
false // include spectators = false
);
}
You'll also want to modify the tick handler that checks for structure exploration:
[Redacted
ServerTickEvents.END_WORLD_TICK.register((world -> {
if ((world.getTime() & 7) != 0) return;
for (ServerPlayerEntity player : world.getPlayers()) {
if (!hasMapItem(player)) continue;
checkStructureExploration(world, player, player.getBlockPos());
checkStructureExploration(world, player, BlockPos.ofFloored(RaycastUtil.playerViewRaycast(player, PlayerSummary.of(player).viewDistance()).getPos()));
}
}));
To implement this, you'll need to:
Create your map item class (if you haven't already)
Register it in your mod's initialization
Replace YOUR_MAP_ITEM in the code above with your actual map item
This implementation will:
Only record terrain when a player with the map item is near
Only record structures when a player with the map item is exploring
Stop recording if the player doesn't have the map item
Resume recording when they obtain the map item again
Remember to test thoroughly, as this modification affects core functionality of the mapping system.