|
| 1 | +package golden.scnamelink.mixin.client; |
| 2 | + |
| 3 | +import com.mojang.datafixers.util.Either; |
| 4 | +import golden.scnamelink.DisplayMapping; |
| 5 | +import golden.scnamelink.SpooncraftNameLinkClient; |
| 6 | +import golden.scnamelink.config.SCNameLinkConfig; |
| 7 | +import me.shedaniel.autoconfig.AutoConfig; |
| 8 | +import net.minecraft.util.math.ColorHelper; |
| 9 | +import net.minecraft.world.waypoint.TrackedWaypoint; |
| 10 | +import net.minecraft.world.waypoint.Waypoint; |
| 11 | +import org.spongepowered.asm.mixin.*; |
| 12 | +import org.spongepowered.asm.mixin.injection.At; |
| 13 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 14 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 15 | + |
| 16 | +import java.util.UUID; |
| 17 | + |
| 18 | +@Mixin (TrackedWaypoint.class) |
| 19 | +public class TrackedWaypointMixin { |
| 20 | + @Unique |
| 21 | + SCNameLinkConfig CONFIG = AutoConfig.getConfigHolder(SCNameLinkConfig.class).getConfig(); |
| 22 | + @Shadow |
| 23 | + @Final |
| 24 | + protected Either<UUID, String> source; |
| 25 | + @Shadow |
| 26 | + @Final |
| 27 | + private Waypoint.Config config; |
| 28 | + |
| 29 | + @Inject (method = "getConfig", at = @At ("RETURN"), cancellable = true) |
| 30 | + private void onGetConfig(CallbackInfoReturnable<Waypoint.Config> cir) { |
| 31 | + Waypoint.Config config = this.config; |
| 32 | + |
| 33 | + if (!CONFIG.enableMod || !CONFIG.locatorbar) { |
| 34 | + return; |
| 35 | + } |
| 36 | + UUID uuid = source.left().orElse(null); |
| 37 | + if (uuid == null) { |
| 38 | + return; |
| 39 | + } |
| 40 | + DisplayMapping mapping = SpooncraftNameLinkClient.getMapping(uuid, null); |
| 41 | + if (mapping == null) { |
| 42 | + return; |
| 43 | + } |
| 44 | + int k = ColorHelper.withAlpha(255, Integer.parseInt(mapping.colour, 16)); |
| 45 | + config.color = java.util.Optional.of(k); |
| 46 | + |
| 47 | + cir.setReturnValue(config); |
| 48 | + } |
| 49 | +} |
0 commit comments