Skip to content

Commit 7a771da

Browse files
Add support for mapping custom waypoint styles
1 parent 55c7bf2 commit 7a771da

22 files changed

Lines changed: 247 additions & 11 deletions

client/src/main/java/org/geysermc/rainbow/client/ClientAssetResolver.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import net.minecraft.client.renderer.texture.SpriteContents;
1010
import net.minecraft.client.renderer.texture.TextureAtlas;
1111
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
12+
import net.minecraft.client.resources.WaypointStyle;
13+
import net.minecraft.client.resources.WaypointStyleManager;
1214
import net.minecraft.client.resources.metadata.animation.FrameSize;
1315
import net.minecraft.client.resources.model.EquipmentAssetManager;
1416
import net.minecraft.client.resources.model.EquipmentClientInfo;
@@ -23,13 +25,15 @@
2325
import net.minecraft.server.packs.resources.ResourceManager;
2426
import net.minecraft.world.item.equipment.EquipmentAsset;
2527
import net.minecraft.world.level.block.state.BlockState;
28+
import net.minecraft.world.waypoints.WaypointStyleAsset;
2629
import org.geysermc.rainbow.Rainbow;
2730
import org.geysermc.rainbow.RainbowIO;
2831
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
2932
import org.geysermc.rainbow.client.accessor.SoundManagerAccessor;
3033
import org.geysermc.rainbow.client.mixin.EntityRenderDispatcherAccessor;
3134
import org.geysermc.rainbow.client.mixin.SpriteContentsAnimatedTextureAccessor;
3235
import org.geysermc.rainbow.client.mixin.SpriteContentsClientAccessor;
36+
import org.geysermc.rainbow.client.mixin.WaypointStyleManagerAccessor;
3337
import org.geysermc.rainbow.mapping.AssetResolver;
3438
import org.geysermc.rainbow.mapping.texture.TextureResource;
3539
import org.geysermc.rainbow.mixin.SpriteContentsAccessor;
@@ -44,12 +48,14 @@
4448
public class ClientAssetResolver implements AssetResolver {
4549
private final ModelManager modelManager;
4650
private final EquipmentAssetManager equipmentAssetManager;
51+
private final WaypointStyleManager waypointStyleManager;
4752
private final ResourceManager resourceManager;
4853
private final AtlasManager atlasManager;
4954

5055
public ClientAssetResolver(Minecraft minecraft) {
5156
modelManager = minecraft.getModelManager();
5257
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
58+
waypointStyleManager = minecraft.gui.hud.getWaypointStyles();
5359
resourceManager = minecraft.getResourceManager();
5460
atlasManager = minecraft.getAtlasManager();
5561
}
@@ -74,6 +80,15 @@ public Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset
7480
return Optional.of(equipmentAssetManager.get(key));
7581
}
7682

83+
@Override
84+
public Optional<WaypointStyle> getWaypointStyle(ResourceKey<WaypointStyleAsset> key) {
85+
WaypointStyle style = waypointStyleManager.get(key);
86+
if (style == WaypointStyleManagerAccessor.getMissing()) {
87+
return Optional.empty();
88+
}
89+
return Optional.of(style);
90+
}
91+
7792
@Override
7893
public Optional<TextureResource> getTexture(@Nullable Identifier atlasId, Identifier identifier) {
7994
if (atlasId == null) {

client/src/main/java/org/geysermc/rainbow/client/PackManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private static String createPackSummary(BedrockPack pack, ClientPackSerializer p
131131
report.append("\nGenerated pack: ").append(pack.name());
132132
report.append("\nBlock mappings written: ").append(stats.blockMappings());
133133
report.append("\nItem mappings written: ").append(stats.itemMappings());
134+
report.append("\nWaypoint style mappings written: ").append(stats.waypointStyleMappings());
134135
report.append("\n");
135136
report.append("\nItem texture atlas size: ").append(stats.itemAtlas());
136137
report.append("\nTerrain texture atlas size: ").append(stats.terrainAtlas());

client/src/main/java/org/geysermc/rainbow/client/command/PackGeneratorCommand.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.fabricmc.fabric.api.client.command.v2.ClientCommands;
77
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
88
import net.minecraft.ChatFormatting;
9+
import net.minecraft.commands.arguments.ResourceKeyArgument;
910
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
1011
import net.minecraft.commands.arguments.coordinates.Coordinates;
1112
import net.minecraft.commands.arguments.coordinates.LocalCoordinates;
@@ -14,14 +15,19 @@
1415
import net.minecraft.core.BlockPos;
1516
import net.minecraft.network.chat.ClickEvent;
1617
import net.minecraft.network.chat.Component;
18+
import net.minecraft.resources.ResourceKey;
1719
import net.minecraft.world.item.ItemStack;
1820
import net.minecraft.world.item.ItemStackTemplate;
1921
import net.minecraft.world.level.block.state.BlockState;
2022
import net.minecraft.world.phys.Vec3;
23+
import net.minecraft.world.waypoints.WaypointStyleAsset;
24+
import net.minecraft.world.waypoints.WaypointStyleAssets;
25+
import org.geysermc.rainbow.Rainbow;
2126
import org.geysermc.rainbow.client.PackManager;
2227
import org.geysermc.rainbow.client.mapper.InventoryMapper;
2328
import org.geysermc.rainbow.client.mapper.PackMapper;
2429
import org.geysermc.rainbow.client.mapper.RecipeMapper;
30+
import org.geysermc.rainbow.client.mixin.WaypointStyleManagerAccessor;
2531
import org.geysermc.rainbow.pack.BedrockPack;
2632

2733
import java.nio.file.Path;
@@ -98,6 +104,21 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
98104
})
99105
)
100106
)
107+
.then(ClientCommands.literal("waypoint")
108+
.then(ClientCommands.argument("style", ResourceKeyArgument.key(WaypointStyleAssets.ROOT_ID))
109+
.suggests(WaypointStyleSuggestionProvider.INSTANCE)
110+
.executes(context -> {
111+
//noinspection unchecked
112+
ResourceKey<WaypointStyleAsset> key = (ResourceKey<WaypointStyleAsset>) context.getArgument("style", ResourceKey.class);
113+
return runWithPack(packManager, (source, pack) -> {
114+
switch (pack.mapWaypointStyle(key)) {
115+
case PROBLEMS_OCCURRED -> source.sendError(Component.translatable("commands.rainbow.mapped_waypoint_style_problems", key.identifier()));
116+
case MAPPED_SUCCESSFULLY -> source.sendFeedback(Component.translatable("commands.rainbow.mapped_waypoint_style", key.identifier()));
117+
}
118+
}).run(context);
119+
})
120+
)
121+
)
101122
)
102123
.then(ClientCommands.literal("mapinventory")
103124
.executes(runWithPack(packManager, (source, pack) -> {
@@ -178,6 +199,16 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
178199
}
179200
}))
180201
)
202+
.then(ClientCommands.literal("waypoints")
203+
.executes(runWithPack(packManager, (source, pack) -> {
204+
long mapped = ((WaypointStyleManagerAccessor) source.getClient().gui.hud.getWaypointStyles()).getWaypointStyles().keySet().stream()
205+
.filter(key -> !Rainbow.isVanilla(key))
206+
.map(pack::mapWaypointStyle)
207+
.filter(result -> result == BedrockPack.MappingResult.MAPPED_SUCCESSFULLY)
208+
.count();
209+
source.sendFeedback(Component.translatable("commands.rainbow.mapped_waypoint_styles", mapped));
210+
}))
211+
)
181212
.then(ClientCommands.literal("stop")
182213
.executes(runWithPack(packManager, (source, _) -> {
183214
packMapper.setItemProvider(null);

client/src/main/java/org/geysermc/rainbow/client/command/SoundNamespaceSuggestionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
77
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
88
import net.minecraft.commands.SharedSuggestionProvider;
9-
import net.minecraft.resources.Identifier;
9+
import org.geysermc.rainbow.Rainbow;
1010
import org.geysermc.rainbow.client.accessor.SoundManagerAccessor;
1111

1212
import java.util.concurrent.CompletableFuture;
@@ -20,6 +20,6 @@ protected SoundNamespaceSuggestionProvider() {}
2020
public CompletableFuture<Suggestions> getSuggestions(CommandContext<FabricClientCommandSource> context, SuggestionsBuilder builder) {
2121

2222
return SharedSuggestionProvider.suggest(((SoundManagerAccessor) context.getSource().getClient().getSoundManager()).rainbow$getRawRegistrations().keySet().stream()
23-
.filter(namespace -> !namespace.equals(Identifier.DEFAULT_NAMESPACE)), builder);
23+
.filter(namespace -> !Rainbow.isVanilla(namespace)), builder);
2424
}
2525
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.geysermc.rainbow.client.command;
2+
3+
import com.mojang.brigadier.context.CommandContext;
4+
import com.mojang.brigadier.suggestion.SuggestionProvider;
5+
import com.mojang.brigadier.suggestion.Suggestions;
6+
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
7+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
8+
import net.minecraft.commands.SharedSuggestionProvider;
9+
import net.minecraft.resources.ResourceKey;
10+
import org.geysermc.rainbow.client.mixin.WaypointStyleManagerAccessor;
11+
12+
import java.util.concurrent.CompletableFuture;
13+
14+
public class WaypointStyleSuggestionProvider implements SuggestionProvider<FabricClientCommandSource> {
15+
public static final WaypointStyleSuggestionProvider INSTANCE = new WaypointStyleSuggestionProvider();
16+
17+
protected WaypointStyleSuggestionProvider() {}
18+
19+
@Override
20+
public CompletableFuture<Suggestions> getSuggestions(CommandContext<FabricClientCommandSource> context, SuggestionsBuilder builder) {
21+
return SharedSuggestionProvider.suggestResource(
22+
((WaypointStyleManagerAccessor) context.getSource().getClient().gui.hud.getWaypointStyles()).getWaypointStyles()
23+
.keySet()
24+
.stream()
25+
.map(ResourceKey::identifier),
26+
builder);
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.geysermc.rainbow.client.mixin;
2+
3+
import net.minecraft.client.resources.WaypointStyle;
4+
import net.minecraft.client.resources.WaypointStyleManager;
5+
import net.minecraft.resources.ResourceKey;
6+
import net.minecraft.world.waypoints.WaypointStyleAsset;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.gen.Accessor;
9+
10+
import java.util.Map;
11+
12+
@Mixin(WaypointStyleManager.class)
13+
public interface WaypointStyleManagerAccessor {
14+
15+
@Accessor("MISSING")
16+
static WaypointStyle getMissing() {
17+
throw new AssertionError();
18+
}
19+
20+
@Accessor
21+
Map<ResourceKey<WaypointStyleAsset>, WaypointStyle> getWaypointStyles();
22+
}

client/src/main/resources/rainbow-client.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"SoundManagerMixin",
1313
"SplashRendererAccessor",
1414
"SpriteContentsAnimatedTextureAccessor",
15-
"SpriteContentsClientAccessor"
15+
"SpriteContentsClientAccessor",
16+
"WaypointStyleManagerAccessor"
1617
],
1718
"injectors": {
1819
"defaultRequire": 1

rainbow/src/main/java/org/geysermc/rainbow/Rainbow.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.logging.LogUtils;
44
import net.minecraft.client.resources.model.ResolvedModel;
55
import net.minecraft.resources.Identifier;
6+
import net.minecraft.resources.ResourceKey;
67
import org.slf4j.Logger;
78

89
public class Rainbow {
@@ -31,4 +32,16 @@ public static Identifier getModelIdentifier(ResolvedModel model) {
3132
// debugName() returns the resource location of the model as a string
3233
return Identifier.parse(model.debugName());
3334
}
35+
36+
public static boolean isVanilla(String namespace) {
37+
return namespace.equals(Identifier.DEFAULT_NAMESPACE);
38+
}
39+
40+
public static boolean isVanilla(Identifier identifier) {
41+
return isVanilla(identifier.getNamespace());
42+
}
43+
44+
public static boolean isVanilla(ResourceKey<?> key) {
45+
return isVanilla(key.identifier());
46+
}
3447
}

rainbow/src/main/java/org/geysermc/rainbow/definition/GeyserMappings.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import org.geysermc.rainbow.definition.block.GeyserBlockMappings;
44
import org.geysermc.rainbow.definition.item.GeyserItemMappings;
55
import org.geysermc.rainbow.definition.skull.GeyserSkullMappings;
6+
import org.geysermc.rainbow.definition.waypoint.GeyserWaypointStyleMappings;
67

78
public record GeyserMappings(GeyserBlockMappings blocks, GeyserItemMappings items,
8-
GeyserSkullMappings skulls) {
9+
GeyserSkullMappings skulls, GeyserWaypointStyleMappings waypointStyles) {
910

1011
public GeyserMappings() {
11-
this(new GeyserBlockMappings(), new GeyserItemMappings(), new GeyserSkullMappings());
12+
this(new GeyserBlockMappings(), new GeyserItemMappings(),
13+
new GeyserSkullMappings(), new GeyserWaypointStyleMappings());
1214
}
1315
}

0 commit comments

Comments
 (0)