|
22 | 22 |
|
23 | 23 | package io.github.axolotlclient.waypoints.map; |
24 | 24 |
|
25 | | -import java.util.ArrayList; |
26 | | -import java.util.List; |
27 | | -import java.util.Map; |
28 | | -import java.util.concurrent.CompletableFuture; |
29 | | -import java.util.concurrent.atomic.AtomicBoolean; |
30 | | - |
31 | 25 | import com.mojang.blaze3d.platform.NativeImage; |
32 | 26 | import io.github.axolotlclient.AxolotlClientConfig.api.AxolotlClientConfig; |
33 | | -import io.github.axolotlclient.AxolotlClientConfig.api.options.OptionCategory; |
34 | | -import io.github.axolotlclient.AxolotlClientConfig.api.util.Colors; |
35 | 27 | import io.github.axolotlclient.AxolotlClientConfig.impl.managers.JsonConfigManager; |
36 | | -import io.github.axolotlclient.AxolotlClientConfig.impl.options.ColorOption; |
37 | | -import io.github.axolotlclient.AxolotlClientConfig.impl.options.IntegerOption; |
| 28 | +import io.github.axolotlclient.bridge.render.AxoRenderContext; |
38 | 29 | import io.github.axolotlclient.modules.hud.HudManager; |
39 | | -import io.github.axolotlclient.modules.hud.gui.component.HudEntry; |
40 | 30 | import io.github.axolotlclient.waypoints.AxolotlClientWaypoints; |
41 | 31 | import io.github.axolotlclient.waypoints.AxolotlClientWaypointsCommon; |
42 | | -import io.github.axolotlclient.waypoints.BooleanOption; |
43 | 32 | import io.github.axolotlclient.waypoints.util.ARGB; |
44 | 33 | import io.github.axolotlclient.waypoints.waypoints.Waypoint; |
45 | | -import lombok.Getter; |
46 | | -import lombok.Setter; |
| 34 | +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; |
47 | 35 | import net.minecraft.Util; |
48 | 36 | import net.minecraft.client.Minecraft; |
49 | 37 | import net.minecraft.client.gui.GuiGraphics; |
50 | 38 | import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen; |
| 39 | +import net.minecraft.client.renderer.BiomeColors; |
51 | 40 | import net.minecraft.client.renderer.texture.DynamicTexture; |
52 | 41 | import net.minecraft.core.BlockPos; |
53 | 42 | import net.minecraft.core.Direction; |
|
63 | 52 | import net.minecraft.world.level.material.MapColor; |
64 | 53 | import org.joml.Vector3f; |
65 | 54 |
|
66 | | -public class Minimap { |
| 55 | +public class Minimap extends MinimapCommon { |
67 | 56 |
|
68 | | - public final ColorOption outlineColor = new ColorOption("outline_color", Colors.WHITE); |
69 | | - public final BooleanOption minimapOutline = new BooleanOption("minimap_outline", true); |
70 | | - public final IntegerOption arrowScale = new IntegerOption("arrow_scale", 2, 1, 4); |
71 | | - private final BooleanOption lockMapToNorth = new BooleanOption("lock_map_north", true); |
72 | | - public final BooleanOption enabled = new BooleanOption("enabled", true); |
73 | | - private final IntegerOption mapScale = new IntegerOption("map_scale", 1, 1, 5); |
74 | | - private final BooleanOption showWaypoints = new BooleanOption("show_waypoints", true); |
75 | | - //public static final BooleanOption useTextureSampling = new BooleanOption("use_texture_sampling", false); |
76 | | - private final BooleanOption showCardinalDirections = new BooleanOption("show_cardinal_directions", true); |
77 | | - private static final OptionCategory minimap = OptionCategory.create("minimap"); |
78 | | - final int radius = 64, size = radius * 2; |
79 | 57 | private static final ResourceLocation texLocation = AxolotlClientWaypoints.rl("minimap"); |
80 | 58 | public static final ResourceLocation arrowLocation = AxolotlClientWaypoints.rl("textures/gui/sprites/arrow.png"); |
81 | 59 | private final NativeImage pixels = new NativeImage(size, size, false); |
82 | 60 | public long updateDuration = -1; |
83 | 61 | private DynamicTexture tex; |
84 | | - @Getter |
85 | | - @Setter |
86 | | - private int x, y; |
87 | 62 | private int mapCenterX, mapCenterZ; |
88 | 63 | private boolean usingHud; |
89 | 64 | public boolean allowCaves = true; |
90 | 65 |
|
91 | 66 | private final Minecraft minecraft = Minecraft.getInstance(); |
92 | 67 |
|
93 | 68 | public void init() { |
94 | | - minimap.add(enabled, /* useTextureSampling,*/ lockMapToNorth, arrowScale, minimapOutline, outlineColor, mapScale, showWaypoints, showCardinalDirections); |
| 69 | + minimap.add(enabled, lockMapToNorth, arrowScale, minimapOutline, outlineColor, enableBiomeBlending, mapScale, showWaypoints, showCardinalDirections); |
95 | 70 | AxolotlClientWaypoints.category.add(Minimap.minimap); |
96 | 71 | if (AxolotlClientWaypointsCommon.AXOLOTLCLIENT_PRESENT) { |
97 | 72 | usingHud = true; |
98 | 73 | var hud = new MinimapHudEntry(this); |
99 | 74 | hud.setEnabled(true); |
100 | | - var hudConfigManager = new JsonConfigManager(AxolotlClientWaypointsCommon.OPTIONS_PATH.resolveSibling(hud.getId().getPath() + ".json"), hud.getAllOptions()); |
| 75 | + var hudConfigManager = new JsonConfigManager(AxolotlClientWaypointsCommon.OPTIONS_PATH.resolveSibling(hud.getId().br$getPath() + ".json"), hud.getAllOptions()); |
101 | 76 | hudConfigManager.suppressName("x"); |
102 | 77 | hudConfigManager.suppressName("y"); |
103 | 78 | hudConfigManager.suppressName(minimapOutline.getName()); |
104 | 79 | hudConfigManager.suppressName(outlineColor.getName()); |
105 | 80 | AxolotlClientConfig.getInstance().register(hudConfigManager); |
106 | 81 | hudConfigManager.load(); |
107 | | - Runtime.getRuntime().addShutdownHook(new Thread(hudConfigManager::save)); |
| 82 | + ClientLifecycleEvents.CLIENT_STOPPING.register(mc -> hudConfigManager.save()); |
108 | 83 | minimap.add(hud.getAllOptions(), false); |
109 | | - try { |
110 | | - var f = HudManager.class.getDeclaredField("entries"); |
111 | | - f.setAccessible(true); |
112 | | - @SuppressWarnings("unchecked") var entries = (Map<ResourceLocation, HudEntry>) f.get(HudManager.getInstance()); |
113 | | - entries.put(hud.getId(), hud); |
114 | | - } catch (Exception ignored) { |
115 | | - usingHud = false; |
116 | | - } |
| 84 | + HudManager.getInstance().addNonConfigured(hud); |
117 | 85 | } |
118 | 86 | } |
119 | 87 |
|
@@ -147,10 +115,11 @@ public void renderMapOverlay(GuiGraphics guiGraphics, float delta) { |
147 | 115 | renderMap(guiGraphics); |
148 | 116 | } |
149 | 117 |
|
150 | | - public void renderMap(GuiGraphics guiGraphics) { |
| 118 | + public void renderMap(AxoRenderContext ctx) { |
151 | 119 | if (!isEnabled()) { |
152 | 120 | return; |
153 | 121 | } |
| 122 | + var guiGraphics = (GuiGraphics) ctx; |
154 | 123 | guiGraphics.pose().pushPose(); |
155 | 124 | { |
156 | 125 | guiGraphics.enableScissor(x, y, x + size, y + size); |
@@ -299,8 +268,7 @@ public void updateMapView() { |
299 | 268 | } |
300 | 269 | } |
301 | 270 |
|
302 | | - AtomicBoolean updated = new AtomicBoolean(false); |
303 | | - List<CompletableFuture<?>> futs = new ArrayList<>(); |
| 271 | + boolean updated = false; |
304 | 272 | for (int x = 0; x < size; x++) { |
305 | 273 | double d = 0.0; |
306 | 274 | for (int z = -1; z < size; z++) { |
@@ -343,59 +311,46 @@ public void updateMapView() { |
343 | 311 | e += y; |
344 | 312 | var mapColor = blockState.getMapColor(level, mutableBlockPos); |
345 | 313 |
|
346 | | - MapColor.Brightness brightness; |
| 314 | + int color; |
347 | 315 | if (mapColor == MapColor.WATER) { |
348 | | - double f = fluidDepth * 0.1 + (x + z & 1) * 0.2; |
349 | | - if (f < 0.5) { |
350 | | - brightness = MapColor.Brightness.HIGH; |
351 | | - } else if (f > 0.9) { |
352 | | - brightness = MapColor.Brightness.LOW; |
353 | | - } else { |
354 | | - brightness = MapColor.Brightness.NORMAL; |
355 | | - } |
| 316 | + var floorBlock = levelChunk.getBlockState(mutableBlockPos2); |
| 317 | + var floorColor = floorBlock.getMapColor(level, mutableBlockPos2).col; |
| 318 | + int biomeColor = enableBiomeBlending.get() ? BiomeColors.getAverageWaterColor(level, mutableBlockPos) : mapColor.col; |
| 319 | + float shade = level.getShade(Direction.UP, true); |
| 320 | + int waterColor = biomeColor; |
| 321 | + waterColor = ARGB.colorFromFloat(1f, ARGB.redFloat(waterColor) * shade, ARGB.greenFloat(waterColor) * shade, ARGB.blueFloat(waterColor) * shade); |
| 322 | + waterColor = ARGB.average(waterColor, ARGB.scaleRGB(floorColor, 1f - fluidDepth / 15f)); |
| 323 | + color = waterColor; |
356 | 324 | } else { |
357 | 325 | double f = (e - d) * 4.0 / (1 + 4) + ((x + z & 1) - 0.5) * 0.4; |
| 326 | + MapColor.Brightness brightness; |
358 | 327 | if (f > 0.6) { |
359 | 328 | brightness = MapColor.Brightness.HIGH; |
360 | 329 | } else if (f < -0.6) { |
361 | 330 | brightness = MapColor.Brightness.LOW; |
362 | 331 | } else { |
363 | 332 | brightness = MapColor.Brightness.NORMAL; |
364 | 333 | } |
| 334 | + color = mapColor.calculateRGBColor(brightness); |
365 | 335 | } |
366 | 336 |
|
367 | 337 | d = e; |
368 | 338 |
|
369 | | - /*if (useTextureSampling.get()) { |
370 | | - final int fz = z, fx = x; |
371 | | - futs.add(TextureSampler.getSample(blockState, level, mutableBlockPos, brightness).thenAccept(color -> { |
372 | | - color = ARGB.opaque(color); |
373 | | - if (fz >= 0 && Integer.rotateRight(pixels.getPixelRGBA(fx, fz), 4) != color) { |
374 | | - pixels.setPixelRGBA(fx, fz, Integer.rotateLeft(color, 4)); |
375 | | - updated.set(true); |
376 | | - } |
377 | | - })); |
378 | | - } else*/ |
379 | | - { |
380 | | - int color = mapColor.calculateRGBColor(brightness); |
381 | | - if (z >= 0 && Integer.rotateRight(pixels.getPixelRGBA(x, z), 4) != color) { |
382 | | - pixels.setPixelRGBA(x, z, ARGB.opaque(color)); |
383 | | - updated.set(true); |
384 | | - } |
| 339 | + if (z >= 0 && Integer.rotateRight(pixels.getPixelRGBA(x, z), 4) != color) { |
| 340 | + pixels.setPixelRGBA(x, z, ARGB.opaque(color)); |
| 341 | + updated = true; |
385 | 342 | } |
386 | 343 | } else { |
387 | 344 | if (z >= 0 && Integer.rotateRight(pixels.getPixelRGBA(x, z), 4) != 0) { |
388 | 345 | pixels.setPixelRGBA(x, z, ARGB.opaque(0)); |
389 | | - updated.set(true); |
| 346 | + updated = true; |
390 | 347 | } |
391 | 348 | } |
392 | 349 | } |
393 | 350 | } |
394 | | - CompletableFuture.allOf(futs.toArray(CompletableFuture[]::new)).thenRun(() -> { |
395 | | - if (updated.get()) { |
396 | | - tex.upload(); |
397 | | - } |
398 | | - }); |
| 351 | + if (updated) { |
| 352 | + tex.upload(); |
| 353 | + } |
399 | 354 | updateDuration = Util.getNanos() - start; |
400 | 355 | } |
401 | 356 | } |
0 commit comments