Skip to content

Commit 1a1c67b

Browse files
committed
improve minimap display of water
- update, refactor a bit
1 parent 64a5423 commit 1a1c67b

File tree

20 files changed

+190
-639
lines changed

20 files changed

+190
-639
lines changed

1.20/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ dependencies {
4040
include("io.github.axolotlclient:AxolotlClient-config:${project.property("config")}+${minecraftFriendly}")
4141
modImplementation("io.github.axolotlclient.AxolotlClient-config:AxolotlClientConfig-common:${project.property("config")}")
4242

43-
modImplementation("io.github.axolotlclient:AxolotlClient:3.1.4+$minecraftVersion")
44-
compileOnly("io.github.axolotlclient.AxolotlClient:AxolotlClient-common:3.1.4")
43+
modImplementation("io.github.axolotlclient:AxolotlClient:${project.property("axolotlclient")}+$minecraftVersion")
44+
compileOnly("io.github.axolotlclient.AxolotlClient:AxolotlClient-common:${project.property("axolotlclient")}")
4545

4646
modCompileOnlyApi("com.terraformersmc:modmenu:8.0.0") {
4747
exclude(group = "net.fabricmc")

1.20/src/main/java/io/github/axolotlclient/waypoints/AxolotlClientWaypoints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static Screen createOptionsScreen(Screen parent) {
115115
}
116116

117117
public static ResourceLocation rl(String path) {
118-
return new ResourceLocation(AxolotlClientWaypointsCommon.MODID, path);
118+
return (ResourceLocation) AxolotlClientWaypointsCommon.rl(path);
119119
}
120120

121121
public static Component tr(String key, Object... args) {

1.20/src/main/java/io/github/axolotlclient/waypoints/map/Minimap.java

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,21 @@
2222

2323
package io.github.axolotlclient.waypoints.map;
2424

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-
3125
import com.mojang.blaze3d.platform.NativeImage;
3226
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;
3527
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;
3829
import io.github.axolotlclient.modules.hud.HudManager;
39-
import io.github.axolotlclient.modules.hud.gui.component.HudEntry;
4030
import io.github.axolotlclient.waypoints.AxolotlClientWaypoints;
4131
import io.github.axolotlclient.waypoints.AxolotlClientWaypointsCommon;
42-
import io.github.axolotlclient.waypoints.BooleanOption;
4332
import io.github.axolotlclient.waypoints.util.ARGB;
4433
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;
4735
import net.minecraft.Util;
4836
import net.minecraft.client.Minecraft;
4937
import net.minecraft.client.gui.GuiGraphics;
5038
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
39+
import net.minecraft.client.renderer.BiomeColors;
5140
import net.minecraft.client.renderer.texture.DynamicTexture;
5241
import net.minecraft.core.BlockPos;
5342
import net.minecraft.core.Direction;
@@ -63,57 +52,36 @@
6352
import net.minecraft.world.level.material.MapColor;
6453
import org.joml.Vector3f;
6554

66-
public class Minimap {
55+
public class Minimap extends MinimapCommon {
6756

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;
7957
private static final ResourceLocation texLocation = AxolotlClientWaypoints.rl("minimap");
8058
public static final ResourceLocation arrowLocation = AxolotlClientWaypoints.rl("textures/gui/sprites/arrow.png");
8159
private final NativeImage pixels = new NativeImage(size, size, false);
8260
public long updateDuration = -1;
8361
private DynamicTexture tex;
84-
@Getter
85-
@Setter
86-
private int x, y;
8762
private int mapCenterX, mapCenterZ;
8863
private boolean usingHud;
8964
public boolean allowCaves = true;
9065

9166
private final Minecraft minecraft = Minecraft.getInstance();
9267

9368
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);
9570
AxolotlClientWaypoints.category.add(Minimap.minimap);
9671
if (AxolotlClientWaypointsCommon.AXOLOTLCLIENT_PRESENT) {
9772
usingHud = true;
9873
var hud = new MinimapHudEntry(this);
9974
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());
10176
hudConfigManager.suppressName("x");
10277
hudConfigManager.suppressName("y");
10378
hudConfigManager.suppressName(minimapOutline.getName());
10479
hudConfigManager.suppressName(outlineColor.getName());
10580
AxolotlClientConfig.getInstance().register(hudConfigManager);
10681
hudConfigManager.load();
107-
Runtime.getRuntime().addShutdownHook(new Thread(hudConfigManager::save));
82+
ClientLifecycleEvents.CLIENT_STOPPING.register(mc -> hudConfigManager.save());
10883
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);
11785
}
11886
}
11987

@@ -147,10 +115,11 @@ public void renderMapOverlay(GuiGraphics guiGraphics, float delta) {
147115
renderMap(guiGraphics);
148116
}
149117

150-
public void renderMap(GuiGraphics guiGraphics) {
118+
public void renderMap(AxoRenderContext ctx) {
151119
if (!isEnabled()) {
152120
return;
153121
}
122+
var guiGraphics = (GuiGraphics) ctx;
154123
guiGraphics.pose().pushPose();
155124
{
156125
guiGraphics.enableScissor(x, y, x + size, y + size);
@@ -299,8 +268,7 @@ public void updateMapView() {
299268
}
300269
}
301270

302-
AtomicBoolean updated = new AtomicBoolean(false);
303-
List<CompletableFuture<?>> futs = new ArrayList<>();
271+
boolean updated = false;
304272
for (int x = 0; x < size; x++) {
305273
double d = 0.0;
306274
for (int z = -1; z < size; z++) {
@@ -343,59 +311,46 @@ public void updateMapView() {
343311
e += y;
344312
var mapColor = blockState.getMapColor(level, mutableBlockPos);
345313

346-
MapColor.Brightness brightness;
314+
int color;
347315
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;
356324
} else {
357325
double f = (e - d) * 4.0 / (1 + 4) + ((x + z & 1) - 0.5) * 0.4;
326+
MapColor.Brightness brightness;
358327
if (f > 0.6) {
359328
brightness = MapColor.Brightness.HIGH;
360329
} else if (f < -0.6) {
361330
brightness = MapColor.Brightness.LOW;
362331
} else {
363332
brightness = MapColor.Brightness.NORMAL;
364333
}
334+
color = mapColor.calculateRGBColor(brightness);
365335
}
366336

367337
d = e;
368338

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;
385342
}
386343
} else {
387344
if (z >= 0 && Integer.rotateRight(pixels.getPixelRGBA(x, z), 4) != 0) {
388345
pixels.setPixelRGBA(x, z, ARGB.opaque(0));
389-
updated.set(true);
346+
updated = true;
390347
}
391348
}
392349
}
393350
}
394-
CompletableFuture.allOf(futs.toArray(CompletableFuture[]::new)).thenRun(() -> {
395-
if (updated.get()) {
396-
tex.upload();
397-
}
398-
});
351+
if (updated) {
352+
tex.upload();
353+
}
399354
updateDuration = Util.getNanos() - start;
400355
}
401356
}

1.21.8/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ dependencies {
4646

4747
modImplementation("net.fabricmc.fabric-api:fabric-api:$fapiVersion+$minecraftFriendly")
4848

49-
modImplementation("io.github.axolotlclient:AxolotlClient-config:${project.property("config")}+1.21.7") {
49+
modImplementation("io.github.axolotlclient:AxolotlClient-config:${project.property("config")}+1.21.8") {
5050
exclude(group = "com.terraformersmc")
5151
exclude(group = "org.lwjgl")
5252
}
53-
include("io.github.axolotlclient:AxolotlClient-config:${project.property("config")}+1.21.7")
53+
include("io.github.axolotlclient:AxolotlClient-config:${project.property("config")}+1.21.8")
5454
modImplementation("io.github.axolotlclient.AxolotlClient-config:AxolotlClientConfig-common:${project.property("config")}")
5555

56-
modImplementation("io.github.axolotlclient:AxolotlClient:3.1.4+1.21.7")
57-
compileOnly("io.github.axolotlclient.AxolotlClient:AxolotlClient-common:3.1.4")
56+
modImplementation("io.github.axolotlclient:AxolotlClient:${project.property("axolotlclient")}+1.21.8")
57+
compileOnly("io.github.axolotlclient.AxolotlClient:AxolotlClient-common:${project.property("axolotlclient")}")
5858

5959
modCompileOnly("com.terraformersmc:modmenu:13.0.0-beta.1")
6060

1.21.8/src/main/java/io/github/axolotlclient/waypoints/AxolotlClientWaypoints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static Screen createOptionsScreen(Screen parent) {
105105
}
106106

107107
public static ResourceLocation rl(String path) {
108-
return ResourceLocation.fromNamespaceAndPath(AxolotlClientWaypointsCommon.MODID, path);
108+
return (ResourceLocation) AxolotlClientWaypointsCommon.rl(path);
109109
}
110110

111111
public static Component tr(String key, Object... args) {

0 commit comments

Comments
 (0)