Skip to content

Commit 65cefa7

Browse files
committed
Minor fix with null/transparent handling & skipping (and enabled by default)
1 parent d3f6f2d commit 65cefa7

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

src/main/java/net/evmodder/evmod/keybinds/KeybindMapMove.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
import net.evmodder.evmod.Configs;
1010
import net.evmodder.evmod.Main;
1111
import net.evmodder.evmod.apis.MapColorUtils;
12+
import net.evmodder.evmod.apis.MapGroupUtils;
1213
import net.evmodder.evmod.apis.MapRelationUtils;
1314
import net.evmodder.evmod.apis.ClickUtils;
1415
import net.evmodder.evmod.apis.ClickUtils.ActionType;
1516
import net.evmodder.evmod.apis.ClickUtils.InvAction;
1617
import net.evmodder.evmod.apis.MapRelationUtils.RelatedMapsData;
1718
import net.minecraft.client.MinecraftClient;
1819
import net.minecraft.client.gui.screen.ingame.HandledScreen;
20+
import net.minecraft.component.DataComponentTypes;
21+
import net.minecraft.component.type.MapIdComponent;
1922
import net.minecraft.item.FilledMapItem;
2023
import net.minecraft.item.ItemStack;
2124
import net.minecraft.item.Items;
@@ -25,16 +28,16 @@
2528

2629
public final class KeybindMapMove{
2730
static final boolean isFillerMap(ItemStack[] slots, ItemStack stack, World world){
28-
final MapState state = FilledMapItem.getMapState(stack, world);
29-
if(state == null) return Configs.Generic.SKIP_NULL_MAPS.getBooleanValue();
31+
final MapIdComponent mapId = stack.get(DataComponentTypes.MAP_ID);
32+
final MapState state = world.getMapState(mapId);
33+
if(state == null) return Configs.Generic.SKIP_NULL_MAPS.getBooleanValue() && MapGroupUtils.isConfirmedNull(mapId.id());
3034
if(!Configs.Generic.SKIP_VOID_MAPS.getBooleanValue()) return false;
3135
if(!MapColorUtils.isFullyTransparent(state.colors)) return false;
3236
if(stack.getCustomName() == null) return true;
3337
final RelatedMapsData data = MapRelationUtils.getRelatedMapsByName(Arrays.asList(slots), stack.getName().getString(), stack.getCount(), state.locked, world);
3438
return data.slots().stream()
3539
.map(i -> FilledMapItem.getMapState(slots[i], world))
36-
.anyMatch(s -> s != null && !MapColorUtils.isFullyTransparent(s.colors));
37-
// return data.slots().stream().map(i -> slots[i].getName().getString()).distinct().count() <= 1;
40+
.allMatch(s -> s != null && MapColorUtils.isFullyTransparent(s.colors));
3841
}
3942

4043
public final void moveMapArtToFromShulker(){
@@ -57,10 +60,13 @@ public final void moveMapArtToFromShulker(){
5760
if(stack == null || stack.isEmpty()) ++emptySlotsInv;
5861
else if(stack.getItem() == Items.FILLED_MAP){
5962
if(isFillerMap(slots, stack, client.world)){++fillerInInv; continue;}
60-
if(FilledMapItem.getMapState(stack, client.world) == null){
63+
final MapIdComponent mapId = stack.get(DataComponentTypes.MAP_ID);
64+
if(client.world.getMapState(mapId) == null){
65+
MapGroupUtils.nullMapIds.add(mapId.id());
6166
Main.LOGGER.warn("MapMove: Unloaded map in player inventory!");
6267
// return;
6368
}
69+
else MapGroupUtils.nullMapIds.remove(mapId.id());
6470
++numInInv;
6571
final int count = stack.getCount();
6672
countsInInv.add(count);

src/main/java/net/evmodder/evmod/onTick/TooltipMapLoreMetadata.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.evmodder.evmod.apis.MapColorUtils;
88
import net.evmodder.evmod.apis.Tooltip;
99
import net.evmodder.evmod.apis.MapColorUtils.MapColorData;
10+
import net.evmodder.evmod.apis.MapColorUtils.Palette;
1011
import net.evmodder.evmod.apis.MapGroupUtils;
1112
import net.minecraft.component.DataComponentTypes;
1213
import net.minecraft.component.type.MapIdComponent;
@@ -60,11 +61,11 @@ private final String paletteSymbol(MapColorUtils.Palette palette){
6061
).formatted(Formatting.GREEN);
6162

6263
final boolean showColorsId = Configs.Visuals.MAP_METADATA_TOOLTIP_UUID.getBooleanValue();
63-
final boolean showStaircased = Configs.Visuals.MAP_METADATA_TOOLTIP_STAIRCASE.getBooleanValue();
64+
final boolean showStaircased = Configs.Visuals.MAP_METADATA_TOOLTIP_STAIRCASE.getBooleanValue() && data.palette() != Palette.EMPTY;
6465
final boolean showStaircasedPercent = Configs.Visuals.MAP_METADATA_TOOLTIP_STAIRCASE_PERCENT.getBooleanValue();
65-
final boolean showMaterial = Configs.Visuals.MAP_METADATA_TOOLTIP_MATERIAL.getBooleanValue();
66+
final boolean showMaterial = Configs.Visuals.MAP_METADATA_TOOLTIP_MATERIAL.getBooleanValue() && data.palette() != Palette.EMPTY;
6667
final boolean showCarpetPercent = Configs.Visuals.MAP_METADATA_TOOLTIP_CARPET_PERCENT.getBooleanValue();
67-
final boolean showNumColors = Configs.Visuals.MAP_METADATA_TOOLTIP_NUM_COLORS.getBooleanValue();
68+
final boolean showNumColors = Configs.Visuals.MAP_METADATA_TOOLTIP_NUM_COLORS.getBooleanValue() && data.palette() != Palette.EMPTY;
6869
final boolean showNumColorIds = Configs.Visuals.MAP_METADATA_TOOLTIP_NUM_COLOR_IDS.getBooleanValue();
6970
final boolean showWaterColors = Configs.Visuals.MAP_METADATA_TOOLTIP_WATER_COLORS.getBooleanValue();
7071
final boolean showWaterColorsPercent = Configs.Visuals.MAP_METADATA_TOOLTIP_WATER_COLORS_PERCENT.getBooleanValue();

src/main/java/net/evmodder/evmod/onTick/TooltipMapNameColor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static final boolean mixedOnDisplayAndNotOnDisplay(List<UUID> nonFillerI
5353
if(cachedLines != null){lines.clear(); lines.addAll(cachedLines); return;}
5454

5555
if(item.getItem() != Items.FILLED_MAP){
56-
final List<ItemStack> mapItems = InvUtils.getAllNestedItems(item).filter(i -> i.get(DataComponentTypes.MAP_ID) != null).toList();
56+
final List<ItemStack> mapItems = InvUtils.getAllNestedItems(item).filter(s -> s.get(DataComponentTypes.MAP_ID) != null).toList();
5757
if(mapItems.isEmpty()) return;
5858
final List<MapState> states = mapItems.stream().map(i -> context.getMapState(i.get(DataComponentTypes.MAP_ID))).filter(Objects::nonNull).toList();
5959
// final List<UUID> nonFillerIds = states.stream().filter(Predicate.not(MapRelationUtils::isFillerMap)).map(MapGroupUtils::getIdForMapState).toList();

src/main/java/net/evmodder/evmod/onTick/UpdateContainerHighlights.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import net.minecraft.client.gui.screen.ingame.CraftingScreen;
1818
import net.minecraft.client.gui.screen.ingame.HandledScreen;
1919
import net.minecraft.component.DataComponentTypes;
20-
import net.minecraft.component.type.MapIdComponent;
2120
import net.minecraft.item.FilledMapItem;
2221
import net.minecraft.item.ItemStack;
23-
import net.minecraft.item.Items;
2422
import net.minecraft.item.map.MapState;
2523
import net.minecraft.screen.slot.Slot;
2624
import net.minecraft.text.MutableText;
@@ -48,7 +46,8 @@ public static boolean isInInvAndContainer(UUID colorsId){
4846
private static final List<ItemStack> getAllMapItemsInContainer(List<Slot> slots){
4947
final List<Slot> containerSlots = slots.subList(0, slots.size()-36);
5048
return InvUtils.getAllNestedItems(containerSlots.stream().map(Slot::getStack))
51-
.filter(s -> s.getItem() == Items.FILLED_MAP)
49+
// .filter(s -> s.getItem() == Items.FILLED_MAP)
50+
.filter(s -> s.get(DataComponentTypes.MAP_ID) != null)
5251
.toList();
5352
}
5453
private static final boolean mixedOnDisplayAndNotOnDisplay(List<UUID> nonFillerIds){
@@ -75,16 +74,16 @@ public static final void onTickStart(MinecraftClient client){
7574
}
7675
final boolean renderAsterisks = Configs.Visuals.MAP_HIGHLIGHT_CONTAINER_NAME.getBooleanValue();
7776

78-
final List<ItemStack> items = getAllMapItemsInContainer(hs.getScreenHandler().slots);
77+
final List<ItemStack> mapItems = getAllMapItemsInContainer(hs.getScreenHandler().slots);
7978

80-
mapsInContainerHash = hs.getScreenHandler().syncId + items.hashCode();
79+
mapsInContainerHash = hs.getScreenHandler().syncId + mapItems.hashCode();
8180
final int currHash = UpdateInventoryHighlights.getMapInInvHash() + mapsInContainerHash;
8281
if(lastHash == currHash) return;
8382
lastHash = currHash;
8483
// Main.LOGGER.info("ContainerHighlighter: Recomputing cache");
8584

86-
if(items.isEmpty()) return;
87-
final List<MapState> states = items.stream().map(i -> FilledMapItem.getMapState(i, client.world)).filter(Objects::nonNull).toList();
85+
if(mapItems.isEmpty()) return;
86+
final List<MapState> states = mapItems.stream().map(i -> FilledMapItem.getMapState(i, client.world)).filter(Objects::nonNull).toList();
8887
final List<UUID> nonTransparentIds = (!Configs.Generic.SKIP_VOID_MAPS.getBooleanValue() ? states.stream() :
8988
states.stream().filter(s -> !MapColorUtils.isFullyTransparent(s.colors))).map(MapGroupUtils::getIdForMapState).toList();
9089

@@ -94,11 +93,8 @@ public static final void onTickStart(MinecraftClient client){
9493
if(!inContainerAndInInv.isEmpty()) asterisks.add(Configs.Visuals.MAP_COLOR_IN_INV.getIntegerValue());
9594
if(states.stream().anyMatch(MapGroupUtils::shouldHighlightNotInCurrentGroup)) asterisks.add(Configs.Visuals.MAP_COLOR_NOT_IN_GROUP.getIntegerValue());
9695
if(states.stream().anyMatch(s -> !s.locked)) asterisks.add(Configs.Visuals.MAP_COLOR_UNLOCKED.getIntegerValue());
97-
if(items.size() > states.size() + (!Configs.Generic.SKIP_NULL_MAPS.getBooleanValue() ? 0 : items.stream().filter(stack -> {
98-
// assert mapId != null;
99-
MapIdComponent mapId = stack.get(DataComponentTypes.MAP_ID);
100-
return mapId != null && MapGroupUtils.nullMapIds.contains(mapId.id());
101-
}).count()
96+
if(mapItems.size() > states.size() + (!Configs.Generic.SKIP_NULL_MAPS.getBooleanValue() ? 0
97+
: mapItems.stream().filter(stack -> MapGroupUtils.nullMapIds.contains(stack.get(DataComponentTypes.MAP_ID).id())).count()
10298
)){
10399
asterisks.add(Configs.Visuals.MAP_COLOR_UNLOADED.getIntegerValue());
104100
}
@@ -114,7 +110,7 @@ public static final void onTickStart(MinecraftClient client){
114110
uniqueIdsStream.filter(Predicate.not(uniqueMapIds::add)).forEach(duplicatesInContainer::add);
115111
if(renderAsterisks){
116112
if(!duplicatesInContainer.isEmpty()) asterisks.add(Configs.Visuals.MAP_COLOR_MULTI_CONTAINER.getIntegerValue());
117-
if(items.stream().anyMatch(i -> i.getCustomName() == null)) asterisks.add(Configs.Visuals.MAP_COLOR_UNNAMED.getIntegerValue());
113+
if(mapItems.stream().anyMatch(i -> i.getCustomName() == null)) asterisks.add(Configs.Visuals.MAP_COLOR_UNNAMED.getIntegerValue());
118114
}
119115

120116
if(renderAsterisks && !asterisks.isEmpty()){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"evmod.config.generic.comment.whisperPearlPull": "/w msg to trigger a pearl",
182182

183183
"evmod.config.generic.name.ignoreNullMapsInHighlightsAndKeybinds": "ignoreNullMapsInHighlightsAndKeybinds",
184-
"evmod.config.generic.comment.ignoreNullMapsInHighlightsAndKeybinds": "Treat maps with missing MapState (either not-yet-loaded, or deleted by Hausemaster) as filler items (skipped)",
184+
"evmod.config.generic.comment.ignoreNullMapsInHighlightsAndKeybinds": "Treat maps with confirmed missing MapState (not just unloaded, but actually deleted (thx Hause)) as filler items.",
185185
"evmod.config.generic.name.ignoreTransparentMapsInHighlightsAndKeybinds": "ignoreTransparentMapsInHighlightsAndKeybinds",
186186
"evmod.config.generic.comment.ignoreTransparentMapsInHighlightsAndKeybinds": "Treat fully transparent maps as filler items (this is actually very useful IMO)",
187187
"evmod.config.generic.name.ignoreMonoColorMapsInHightlights": "ignoreMonoColorMapsInHightlights",

0 commit comments

Comments
 (0)