Skip to content

Commit c20b090

Browse files
committed
Skip villager treasure map trade if disabled
When disabling treasure maps, villagers should not be rolling treasure map offers when selecting their merchant offers after a level up as these maps would default to empty maps. Instead, other offers should be picked. The commit uses a simple heuristic to determine if the exploration map function is called from a villager trade selection instead of passing it through all levels of loot context to minimise diff. If vanilla usecases exist that trigger a false positive from the heuristic and require a non empty item to be returned if maps are disabled, this implementation needs to be revisited.
1 parent 57e2655 commit c20b090

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
--- a/net/minecraft/world/level/storage/loot/functions/ExplorationMapFunction.java
22
+++ b/net/minecraft/world/level/storage/loot/functions/ExplorationMapFunction.java
3-
@@ -83,9 +_,17 @@
3+
@@ -83,9 +_,25 @@
44
Vec3 lootPos = context.getOptionalParameter(LootContextParams.ORIGIN);
55
if (lootPos != null) {
66
ServerLevel level = context.getLevel();
77
+ // Paper start - Configurable cartographer treasure maps
8+
+ // Simple heuristic for determining if this function is running in the context of a villager selecting
9+
+ // an item for its offers. Technically other callers could satisfiy this but this minimises the diff and
10+
+ // works for all plain vanilla usecases.
11+
+ final boolean runningForVillagerTrade = context.hasParameter(LootContextParams.ADDITIONAL_COST_COMPONENT_ALLOWED)
12+
+ && context.getOptionalParameter(LootContextParams.THIS_ENTITY) instanceof net.minecraft.world.entity.npc.villager.AbstractVillager;
813
+ if (!level.paperConfig().environment.treasureMaps.enabled) {
914
+ /*
1015
+ * NOTE: I fear users will just get a plain map as their "treasure"
1116
+ * This is preferable to disrespecting the config.
1217
+ */
13-
+ return itemStack;
18+
+ return runningForVillagerTrade ? net.minecraft.world.item.ItemStack.EMPTY : itemStack;
1419
+ }
20+
+ final boolean shouldSkipKnownStructures = runningForVillagerTrade
21+
+ ? !level.paperConfig().environment.treasureMaps.findAlreadyDiscoveredVillager
22+
+ : !level.paperConfig().environment.treasureMaps.findAlreadyDiscoveredLootTable.or(!this.skipKnownStructures);
1523
+ // Paper end - Configurable cartographer treasure maps
1624
BlockPos nearestMapStructure = level.findNearestMapStructure(
1725
- this.destination, BlockPos.containing(lootPos), this.searchRadius, this.skipKnownStructures
1826
- );
19-
+ this.destination, BlockPos.containing(lootPos), this.searchRadius, !level.paperConfig().environment.treasureMaps.findAlreadyDiscoveredLootTable.or(!this.skipKnownStructures)); // Paper - Configurable cartographer treasure maps
27+
+ this.destination, BlockPos.containing(lootPos), this.searchRadius, shouldSkipKnownStructures); // Paper - Configurable cartographer treasure maps
2028
if (nearestMapStructure != null) {
2129
ItemStack map = MapItem.create(level, nearestMapStructure.getX(), nearestMapStructure.getZ(), this.zoom, true, true);
2230
MapItem.renderBiomePreviewMap(level, map);

0 commit comments

Comments
 (0)