Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/xaeroplus/mixin/client/MixinMinimapOption.java
#	common/src/main/java/xaeroplus/mixin/client/MixinWorldMapOption.java
#	forge/src/main/java/xaeroplus/forge/XaeroPlusForge.java
  • Loading branch information
rfresh2 committed Sep 27, 2024
2 parents 8e86776 + d0cc87c commit 98693c6
Show file tree
Hide file tree
Showing 86 changed files with 1,880 additions and 2,008 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import net.fabricmc.loom.api.LoomGradleExtensionAPI
plugins {
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false
id("com.gradleup.shadow") version "8.3.0" apply false
id("com.gradleup.shadow") version "8.3.2" apply false
idea
}

Expand Down
23 changes: 10 additions & 13 deletions common/src/main/java/xaeroplus/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import xaero.map.core.XaeroWorldMapCore;
import xaeroplus.event.ClientPlaySessionFinalizedEvent;
import xaeroplus.feature.render.DrawManager;
import xaeroplus.settings.XaeroPlusSetting;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.Settings;

import java.io.ByteArrayOutputStream;
import java.util.concurrent.ExecutorService;
Expand All @@ -26,7 +24,7 @@ public class Globals {
public static final DrawManager drawManager = new DrawManager();
// cache and only update this on new world loads
public static boolean nullOverworldDimensionFolder = false;
public static XaeroPlusSettingRegistry.DataFolderResolutionMode dataFolderResolutionMode = XaeroPlusSettingRegistry.DataFolderResolutionMode.IP;
public static Settings.DataFolderResolutionMode dataFolderResolutionMode = Settings.DataFolderResolutionMode.IP;
public static int minimapScaleMultiplier = 1;
public static int minimapSizeMultiplier = 1;
public static boolean shouldResetFBO = false;
Expand Down Expand Up @@ -60,15 +58,14 @@ public static ResourceKey<Level> getCurrentDimensionId() {
.setDaemon(true)
.build()));

public static void onAllSettingsLoaded() {
XaeroPlusSettingsReflectionHax.ALL_SETTINGS.get().forEach(XaeroPlusSetting::init);
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
minimapScaleMultiplier = (int) XaeroPlusSettingRegistry.minimapScaleMultiplierSetting.getValue();
minimapSizeMultiplier = (int) XaeroPlusSettingRegistry.minimapSizeMultiplierSetting.getValue();
public static void initStickySettings() {
nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get();
dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get();
minimapScaleMultiplier = Settings.REGISTRY.minimapScaleMultiplierSetting.getAsInt();
minimapSizeMultiplier = Settings.REGISTRY.minimapSizeMultiplierSetting.getAsInt();
XaeroPlus.EVENT_BUS.registerConsumer((e) -> {
nullOverworldDimensionFolder = XaeroPlusSettingRegistry.nullOverworldDimensionFolder.getValue();
dataFolderResolutionMode = XaeroPlusSettingRegistry.dataFolderResolutionMode.getValue();
nullOverworldDimensionFolder = Settings.REGISTRY.nullOverworldDimensionFolder.get();
dataFolderResolutionMode = Settings.REGISTRY.dataFolderResolutionMode.get();
}, ClientPlaySessionFinalizedEvent.class);
}

Expand Down Expand Up @@ -99,7 +96,7 @@ public static void setNullOverworldDimFolderIfAble(final boolean b) {
}
}

public static void setDataFolderResolutionModeIfAble(XaeroPlusSettingRegistry.DataFolderResolutionMode mode) {
public static void setDataFolderResolutionModeIfAble(Settings.DataFolderResolutionMode mode) {
try {
var currentWMSession = XaeroWorldMapCore.currentSession;
var currentMMSession = HudSession.getCurrentSession();
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/xaeroplus/XaeroPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xaero.map.platform.Services;
import xaeroplus.settings.Settings;
import xaeroplus.settings.XaeroPlusSetting;

import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;

import static xaeroplus.settings.SettingHooks.loadXPSettings;

public class XaeroPlus {
public static final Logger LOGGER = LoggerFactory.getLogger("XaeroPlus");
public static final LambdaManager EVENT_BUS = LambdaManager.basic(new LambdaMetaFactoryGenerator());
public static final AtomicBoolean initialized = new AtomicBoolean(false);
public static final File configFile = Services.PLATFORM.getConfigDir().resolve("xaeroplus.txt").toFile();

public static void initializeSettings() {
loadXPSettings();
Settings.REGISTRY.getAllSettings().forEach(XaeroPlusSetting::init);
Globals.initStickySettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import xaero.map.gui.GuiSettings;
import xaero.map.gui.ISettingEntry;
import xaero.map.gui.ScreenSwitchSettingEntry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.SettingLocation;
import xaeroplus.settings.Settings;

public class GuiXaeroPlusChunkHighlightSettings extends GuiSettings {
public GuiXaeroPlusChunkHighlightSettings(Screen parent, Screen escapeScreen) {
super(Component.translatable("gui.xaeroplus.chunk_highlight_settings"), parent, escapeScreen);
this.entries = XaeroPlusSettingsReflectionHax.getChunkHighlightConfigSettingEntries().toArray(new ISettingEntry[0]);
this.entries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.CHUNK_HIGHLIGHTS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
import xaero.map.gui.GuiSettings;
import xaero.map.gui.ISettingEntry;
import xaero.map.gui.ScreenSwitchSettingEntry;
import xaeroplus.settings.XaeroPlusSettingsReflectionHax;
import xaeroplus.settings.SettingLocation;
import xaeroplus.settings.Settings;

public class GuiXaeroPlusWorldMapSettings extends GuiSettings {

public GuiXaeroPlusWorldMapSettings(Screen parent, Screen escapeScreen) {
super(Component.translatable("gui.xaeroplus.world_map_settings"), parent, escapeScreen);
var mainSettingsEntries = XaeroPlusSettingsReflectionHax.getWorldMapConfigSettingEntries();
var mainSettingsEntries = Settings.REGISTRY.getWorldmapConfigSettingEntries(SettingLocation.WORLD_MAP_MAIN);
var chunkHighlightSettingSwitchEntry = GuiXaeroPlusChunkHighlightSettings.getScreenSwitchSettingEntry(parent);
this.entries = new ISettingEntry[mainSettingsEntries.size() + 1];
this.entries = new ISettingEntry[mainSettingsEntries.length + 1];
this.entries[0] = chunkHighlightSettingSwitchEntry;
for (int i = 0; i < mainSettingsEntries.size(); i++) {
this.entries[i + 1] = mainSettingsEntries.get(i);
for (int i = 0; i < mainSettingsEntries.length; i++) {
this.entries[i + 1] = mainSettingsEntries[i];
}
}

Expand Down
16 changes: 12 additions & 4 deletions common/src/main/java/xaeroplus/feature/render/DrawFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DrawFeature {
private final AsyncLoadingCache<Long, LongList> chunkRenderCache;
private final ChunkHighlightProvider chunkHighlightProvider;
private final HighlightDrawBuffer highlightDrawBuffer = new HighlightDrawBuffer();
private final HighlightDrawBuffer drawBuffer = new HighlightDrawBuffer();

public DrawFeature(ChunkHighlightProvider chunkHighlightProvider) {
this.chunkHighlightProvider = chunkHighlightProvider;
Expand All @@ -25,7 +25,7 @@ private AsyncLoadingCache<Long, LongList> createChunkHighlightRenderCache(final
.expireAfterWrite(10, TimeUnit.SECONDS)
.refreshAfterWrite(500, TimeUnit.MILLISECONDS)
.executor(Globals.cacheRefreshExecutorService.get())
.removalListener((k, v, cause) -> getHighlightDrawBuffer().markStale())
.removalListener((k, v, cause) -> markDrawBuffersStale())
// only one key
.buildAsync(k -> loadFeatureHighlightsInWindow(chunkHighlightProvider));
}
Expand Down Expand Up @@ -58,7 +58,15 @@ public LongList getChunkHighlights() {
return chunkRenderCache.get(0L).getNow(LongList.of());
}

public HighlightDrawBuffer getHighlightDrawBuffer() {
return this.highlightDrawBuffer;
public HighlightDrawBuffer getDrawBuffer() {
return this.drawBuffer;
}

public void markDrawBuffersStale() {
drawBuffer.markStale();
}

public void closeDrawBuffers() {
drawBuffer.close();
}
}
94 changes: 69 additions & 25 deletions common/src/main/java/xaeroplus/feature/render/DrawManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import xaeroplus.XaeroPlus;
import xaeroplus.event.DimensionSwitchEvent;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.settings.XaeroPlusSettingRegistry;
import xaeroplus.settings.Settings;
import xaeroplus.util.ChunkUtils;
import xaeroplus.util.ColorHelper;

Expand Down Expand Up @@ -40,7 +40,7 @@ public synchronized void unregisterChunkHighlightProvider(String id) {
sortedKeySet.remove(id);
DrawFeature feature = chunkHighlightDrawFeatures.remove(id);
if (feature != null) {
Minecraft.getInstance().execute(() -> feature.getHighlightDrawBuffer().close());
Minecraft.getInstance().execute(feature::closeDrawBuffers);
}
}

Expand Down Expand Up @@ -83,12 +83,31 @@ public synchronized void drawMinimapFeatures(
-(chunkZ * 64) - (tileZ * 16) - insideZ,
0);
matrixStack.scale(16f, 16f, 1f);
if (Settings.REGISTRY.highlightShader.get()) {
drawMinimapFeaturesShader(matrixStack);
} else {
drawMinimapFeaturesImmediate(minViewMapTileChunkCoordX, maxViewMapTileChunkCoordX, minViewMapTileChunkCoordZ, maxViewMapTileChunkCoordZ,
matrixStack, overlayBufferBuilder, helper);
}
matrixStack.popPose();
}

public synchronized void drawMinimapFeaturesImmediate(
int minViewMapTileChunkCoordX,
int maxViewMapTileChunkCoordX,
int minViewMapTileChunkCoordZ,
int maxViewMapTileChunkCoordZ,
final PoseStack matrixStack,
final VertexConsumer overlayBufferBuilder,
MinimapRendererHelper helper
) {
var matrix = matrixStack.last().pose();
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
if (k == null) continue;
var feature = chunkHighlightDrawFeatures.get(k);
if (feature == null) continue;
feature.closeDrawBuffers();
int color = feature.colorInt();
var a = ColorHelper.getA(color);
if (a == 0.0f) return;
Expand All @@ -111,7 +130,36 @@ public synchronized void drawMinimapFeatures(
);
}
}
matrixStack.popPose();
}

public synchronized void drawMinimapFeaturesShader(
final PoseStack matrixStack
) {
XaeroPlusShaders.ensureShaders();
var shader = XaeroPlusShaders.HIGHLIGHT_SHADER;
if (shader == null) return;
shader.setMapViewMatrix(matrixStack.last().pose());
RenderSystem.enableBlend();
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
if (k == null) continue;
var feature = chunkHighlightDrawFeatures.get(k);
if (feature == null) continue;
int color = feature.colorInt();
var a = ColorHelper.getA(color);
if (a == 0.0f) return;
var r = ColorHelper.getR(color);
var g = ColorHelper.getG(color);
var b = ColorHelper.getB(color);
shader.setHighlightColor(r, g, b, a);
var highlights = feature.getChunkHighlights();
var drawBuffer = feature.getDrawBuffer();
if (drawBuffer.needsRefresh(false)) {
drawBuffer.refresh(highlights, false);
}
drawBuffer.render();
}
RenderSystem.disableBlend();
}

public synchronized void drawWorldMapFeatures(
Expand All @@ -124,24 +172,24 @@ public synchronized void drawWorldMapFeatures(
final PoseStack matrixStack,
final VertexConsumer overlayBuffer
) {
if (XaeroPlusSettingRegistry.highlightShader.getValue())
drawWorldMapFeaturesShader(flooredCameraX, flooredCameraZ, matrixStack);
matrixStack.pushPose();
matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f);
matrixStack.scale(16f, 16f, 1f);
if (Settings.REGISTRY.highlightShader.get())
drawWorldMapFeaturesShader(matrixStack);
else
drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ, flooredCameraX, flooredCameraZ, matrixStack, overlayBuffer);
drawWorldMapFeaturesImmediate(minBlockX, maxBlockX, minBlockZ, maxBlockZ,
matrixStack, overlayBuffer);
matrixStack.popPose();
}

public synchronized void drawWorldMapFeaturesShader(
final int flooredCameraX,
final int flooredCameraZ,
final PoseStack matrixStack
) {
XaeroPlusShaders.ensureShaders();
var shader = XaeroPlusShaders.HIGHLIGHT_SHADER;
if (shader == null) return;
matrixStack.pushPose();
matrixStack.translate(-flooredCameraX, -flooredCameraZ, 1.0f);
shader.setWorldMapViewMatrix(matrixStack.last().pose());
matrixStack.popPose();
shader.setMapViewMatrix(matrixStack.last().pose());
RenderSystem.enableBlend();
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
Expand All @@ -156,10 +204,11 @@ public synchronized void drawWorldMapFeaturesShader(
var b = ColorHelper.getB(color);
shader.setHighlightColor(r, g, b, a);
var highlights = feature.getChunkHighlights();
if (feature.getHighlightDrawBuffer().needsRefresh()) {
feature.getHighlightDrawBuffer().refresh(highlights);
var drawBuffer = feature.getDrawBuffer();
if (drawBuffer.needsRefresh(true)) {
drawBuffer.refresh(highlights, true);
}
feature.getHighlightDrawBuffer().render();
drawBuffer.render();
}
RenderSystem.disableBlend();
}
Expand All @@ -169,20 +218,16 @@ public synchronized void drawWorldMapFeaturesImmediate(
final double maxBlockX,
final double minBlockZ,
final double maxBlockZ,
final int flooredCameraX,
final int flooredCameraZ,
final PoseStack matrixStack,
final VertexConsumer overlayBuffer
) {
matrixStack.pushPose();
matrixStack.translate(-flooredCameraX, -flooredCameraZ, 0);
var matrix = matrixStack.last().pose();
for (int i = 0; i < sortedKeySet.size(); i++) {
var k = sortedKeySet.get(i);
if (k == null) continue;
var feature = chunkHighlightDrawFeatures.get(k);
if (feature == null) continue;
feature.getHighlightDrawBuffer().close();
feature.closeDrawBuffers();
int color = feature.colorInt();
var a = ColorHelper.getA(color);
if (a == 0.0f) return;
Expand All @@ -198,17 +243,16 @@ public synchronized void drawWorldMapFeaturesImmediate(
var blockZ = ChunkUtils.chunkCoordToCoord(chunkPosZ);
if (blockX < minBlockX - 32 || blockX > maxBlockX) continue;
if (blockZ < minBlockZ - 32 || blockZ > maxBlockZ) continue;
final float left = (float) ChunkUtils.chunkCoordToCoord(chunkPosX);
final float top = (float) ChunkUtils.chunkCoordToCoord(chunkPosZ);
final float right = left + 16;
final float bottom = top + 16;
final float left = chunkPosX;
final float top = chunkPosZ;
final float right = left + 1;
final float bottom = top + 1;
MinimapBackgroundDrawHelper.fillIntoExistingBuffer(
matrix, overlayBuffer,
left, top, right, bottom,
r, g, b, a
);
}
}
matrixStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
public class HighlightDrawBuffer {
private boolean stale = true;
@Nullable private VertexBuffer vertexBuffer = null;
private boolean flipped = false;

public boolean needsRefresh() {
return vertexBuffer == null || vertexBuffer.isInvalid() || stale;
public boolean needsRefresh(boolean needsFlip) {
return vertexBuffer == null || vertexBuffer.isInvalid() || stale || flipped != needsFlip;
}

public void refresh(LongList highlights) {
public void refresh(LongList highlights, boolean needsFlip) {
stale = false;
flipped = needsFlip;
if (highlights.isEmpty()) {
close();
return;
Expand All @@ -30,17 +32,14 @@ public void refresh(LongList highlights) {
long highlight = highlights.getLong(j);
var chunkPosX = ChunkUtils.longToChunkX(highlight);
var chunkPosZ = ChunkUtils.longToChunkZ(highlight);
var blockPosX = ChunkUtils.chunkCoordToCoord(chunkPosX);
var blockPosZ = ChunkUtils.chunkCoordToCoord(chunkPosZ);
var chunkSize = 16;
float x1 = blockPosX;
float x2 = blockPosX + chunkSize;
float y1 = blockPosZ;
float y2 = blockPosZ + chunkSize;
bufferBuilder.vertex(x1, y1, 0.0F).endVertex();
bufferBuilder.vertex(x2, y1, 0.0F).endVertex();
bufferBuilder.vertex(x2, y2, 0.0F).endVertex();
bufferBuilder.vertex(x1, y2, 0.0F).endVertex();
float x1 = chunkPosX;
float x2 = chunkPosX + 1;
float y1 = needsFlip ? chunkPosZ + 1 : chunkPosZ;
float y2 = needsFlip ? chunkPosZ : chunkPosZ + 1;
bufferBuilder.vertex(x1, y2, 0F).endVertex();
bufferBuilder.vertex(x2, y2, 0F).endVertex();
bufferBuilder.vertex(x2, y1, 0F).endVertex();
bufferBuilder.vertex(x1, y1, 0F).endVertex();
}
if (vertexBuffer == null || vertexBuffer.isInvalid()) {
close();
Expand Down
Loading

0 comments on commit 98693c6

Please sign in to comment.