Skip to content

Commit

Permalink
render world border overlay setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Oct 15, 2024
1 parent 30a6736 commit e7d95eb
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 88 deletions.
151 changes: 105 additions & 46 deletions common/src/main/java/xaeroplus/mixin/client/MixinGuiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,52 +331,111 @@ public void showRenderDistanceWorldMap(final GuiGraphics guiGraphics, final int
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
@Local(name = "matrixStack") PoseStack matrixStack) {
Minecraft mc = Minecraft.getInstance();
if (Settings.REGISTRY.showRenderDistanceWorldMapSetting.get() && !mc.options.hideGui) {
if (mc.level.dimension() == Globals.getCurrentDimensionId()) {
final int viewDistance = mc.options.serverRenderDistance;
int width = viewDistance * 2 + 1;
double playerX = getPlayerX();
double playerZ = getPlayerZ();
int xFloored = OptimizedMath.myFloor(playerX);
int zFloored = OptimizedMath.myFloor(playerZ);
int chunkLeftX = (xFloored >> 4) - (width / 2) << 4;
int chunkRightX = (xFloored >> 4) + 1 + (width / 2) << 4;
int chunkTopZ = (zFloored >> 4) - (width / 2) << 4;
int chunkBottomZ = (zFloored >> 4) + 1 + (width / 2) << 4;
float camX = (float) cameraX;
float camZ = (float) cameraZ;
final float x0 = chunkLeftX - camX;
final float x1 = chunkRightX - camX;
final float z0 = chunkTopZ - camZ;
final float z1 = chunkBottomZ - camZ;
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(xaero.common.graphics.CustomRenderTypes.MAP_LINES);
PoseStack.Pose matrices = matrixStack.last();
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize(mc.getWindow().getWidth(), mc.getWindow().getHeight());
float settingWidth = (float) HudSession.getCurrentSession().getHudMod().getSettings().chunkGridLineWidth;
float lineScale = (float) Math.max(1.0, Math.min(settingWidth * scale, settingWidth));
RenderSystem.lineWidth(lineScale);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
1.0f, 1.0f, 0.0f, 0.8f
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z0, x1, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z1, x0, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x0, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
}
}
if (!Settings.REGISTRY.showRenderDistanceWorldMapSetting.get()
|| mc.options.hideGui
|| mc.level.dimension() != Globals.getCurrentDimensionId()) return;
final int viewDistance = mc.options.serverRenderDistance;
int width = viewDistance * 2 + 1;
double playerX = getPlayerX();
double playerZ = getPlayerZ();
int xFloored = OptimizedMath.myFloor(playerX);
int zFloored = OptimizedMath.myFloor(playerZ);
int chunkLeftX = (xFloored >> 4) - (width / 2) << 4;
int chunkRightX = (xFloored >> 4) + 1 + (width / 2) << 4;
int chunkTopZ = (zFloored >> 4) - (width / 2) << 4;
int chunkBottomZ = (zFloored >> 4) + 1 + (width / 2) << 4;
float camX = (float) cameraX;
float camZ = (float) cameraZ;
final float x0 = chunkLeftX - camX;
final float x1 = chunkRightX - camX;
final float z0 = chunkTopZ - camZ;
final float z1 = chunkBottomZ - camZ;
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(xaero.common.graphics.CustomRenderTypes.MAP_LINES);
PoseStack.Pose matrices = matrixStack.last();
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize(mc.getWindow().getWidth(), mc.getWindow().getHeight());
float settingWidth = (float) HudSession.getCurrentSession().getHudMod().getSettings().chunkGridLineWidth;
float lineScale = (float) Math.max(1.0, Math.min(settingWidth * scale, settingWidth));
RenderSystem.lineWidth(lineScale);
float r = 1.0f;
float g = 1.0f;
float b = 0.0f;
float a = 0.8f;
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z0, x1, z1,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z1, x0, z1,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x0, z1,
r, g, b, a
);
}

@Inject(method = "render", at = @At(
value = "FIELD",
target = "Lxaero/map/settings/ModSettings;renderArrow:Z",
opcode = Opcodes.GETFIELD,
ordinal = 0
), remap = true)
public void showWorldBorderWorldMap(final GuiGraphics guiGraphics, final int scaledMouseX, final int scaledMouseY, final float partialTicks, final CallbackInfo ci,
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
@Local(name = "matrixStack") PoseStack matrixStack) {
Minecraft mc = Minecraft.getInstance();
if (!Settings.REGISTRY.showWorldBorderWorldMapSetting.get()
|| mc.options.hideGui
|| mc.level.dimension() != Globals.getCurrentDimensionId()) return;
var worldBorder = mc.level.getWorldBorder();
float wbMinX = (float) worldBorder.getMinX();
float wbMinZ = (float) worldBorder.getMinZ();
float wbMaxX = (float) worldBorder.getMaxX();
float wbMaxZ = (float) worldBorder.getMaxZ();
float camX = (float) cameraX;
float camZ = (float) cameraZ;
float x0 = wbMinX - camX;
float z0 = wbMinZ - camZ;
float x1 = wbMaxX - camX;
float z1 = wbMaxZ - camZ;
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(xaero.common.graphics.CustomRenderTypes.MAP_LINES);
PoseStack.Pose matrices = matrixStack.last();
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize(mc.getWindow().getWidth(), mc.getWindow().getHeight());
float settingWidth = (float) HudSession.getCurrentSession().getHudMod().getSettings().chunkGridLineWidth;
float lineScale = (float) Math.max(1.0, Math.min(settingWidth * scale, settingWidth));
RenderSystem.lineWidth(lineScale);
float r = 0.0f;
float g = 1.0f;
float b = 1.0f;
float a = 0.8f;
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z0, x1, z1,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z1, x0, z1,
r, g, b, a
);
addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x0, z1,
r, g, b, a
);
}

@WrapWithCondition(method = "render", at = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,50 +148,107 @@ public void drawRenderDistanceSquare(final MinimapSession minimapSession, final
@Local(name = "matrixStack") PoseStack matrixStack
) {
final boolean isDimensionSwitched = Globals.getCurrentDimensionId() != Minecraft.getInstance().level.dimension();
if (Settings.REGISTRY.showRenderDistanceSetting.get() && !isDimensionSwitched) {
double actualPlayerX = minimap.getEntityRadar().getEntityX(mc.player, partial);
double actualPlayerZ = minimap.getEntityRadar().getEntityZ(mc.player, partial);
int actualXFloored = OptimizedMath.myFloor(actualPlayerX);
int actualZFloored = OptimizedMath.myFloor(actualPlayerZ);
final int viewDistance = mc.options.serverRenderDistance;
int width = viewDistance * 2 + 1;
// origin of the chunk we are standing in
final int middleChunkX = -(actualXFloored & 15);
final int middleChunkZ = -(actualZFloored & 15);
int distanceFlooredX = actualXFloored - xFloored;
int distanceFlooredZ = actualZFloored - zFloored;
if (!Settings.REGISTRY.showRenderDistanceSetting.get() || isDimensionSwitched) return;
double actualPlayerX = minimap.getEntityRadar().getEntityX(mc.player, partial);
double actualPlayerZ = minimap.getEntityRadar().getEntityZ(mc.player, partial);
int actualXFloored = OptimizedMath.myFloor(actualPlayerX);
int actualZFloored = OptimizedMath.myFloor(actualPlayerZ);
final int viewDistance = mc.options.serverRenderDistance;
int width = viewDistance * 2 + 1;
// origin of the chunk we are standing in
final int middleChunkX = -(actualXFloored & 15);
final int middleChunkZ = -(actualZFloored & 15);
int distanceFlooredX = actualXFloored - xFloored;
int distanceFlooredZ = actualZFloored - zFloored;

final int x0 = distanceFlooredX + middleChunkX - (width / 2) * 16;
final int z0 = distanceFlooredZ + middleChunkZ - (width / 2) * 16;
final int x1 = x0 + width * 16;
final int z1 = z0 + width * 16;
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(CustomRenderTypes.MAP_LINES);
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize((float) scalingFramebuffer.viewWidth, (float) scalingFramebuffer.viewHeight);
float lineWidth = Math.max(1.0f, modMain.getSettings().chunkGridLineWidth * Globals.minimapScaleMultiplier / (float) Globals.minimapSizeMultiplier);
RenderSystem.lineWidth(lineWidth);
PoseStack.Pose matrices = matrixStack.last();
final int x0 = distanceFlooredX + middleChunkX - (width / 2) * 16;
final int z0 = distanceFlooredZ + middleChunkZ - (width / 2) * 16;
final int x1 = x0 + width * 16;
final int z1 = z0 + width * 16;
VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(CustomRenderTypes.MAP_LINES);
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize((float) scalingFramebuffer.viewWidth, (float) scalingFramebuffer.viewHeight);
float lineWidth = Math.max(1.0f, modMain.getSettings().chunkGridLineWidth * Globals.minimapScaleMultiplier / (float) Globals.minimapSizeMultiplier);
RenderSystem.lineWidth(lineWidth);
float r = 1.0f;
float g = 1.0f;
float b = 0.0f;
float a = 0.8f;
PoseStack.Pose matrices = matrixStack.last();

helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
1.0f, 1.0f, 0.0f, 0.8f
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z0, x1, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z1, x0, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x0, z1,
1.0f, 1.0f, 0.0f, 0.8f
);
}
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x1, z0,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z0, x1, z1,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x1, z1, x0, z1,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrices, lineBufferBuilder,
x0, z0, x0, z1,
r, g, b, a
);
}

@Inject(method = "renderChunksToFBO", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V",
ordinal = 0
), remap = true)
public void drawWorldBorderSquare(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final Vec3 renderPos, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Local(name = "xFloored") int xFloored,
@Local(name = "zFloored") int zFloored,
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
@Local(name = "matrixStack") PoseStack matrixStack
) {
final boolean isDimensionSwitched = Globals.getCurrentDimensionId() != Minecraft.getInstance().level.dimension();
if (!Settings.REGISTRY.showWorldBorderSetting.get() || isDimensionSwitched) return;
var worldBorder = mc.level.getWorldBorder();
float wbMinX = (float) worldBorder.getMinX();
float wbMinZ = (float) worldBorder.getMinZ();
float wbMaxX = (float) worldBorder.getMaxX();
float wbMaxZ = (float) worldBorder.getMaxZ();
float x0 = wbMinX - xFloored;
float z0 = wbMinZ - zFloored;
float x1 = wbMaxX - xFloored;
float z1 = wbMaxZ - zFloored;

VertexConsumer lineBufferBuilder = renderTypeBuffers.getBuffer(CustomRenderTypes.MAP_LINES);
MinimapShaders.FRAMEBUFFER_LINES.setFrameSize((float) scalingFramebuffer.viewWidth, (float) scalingFramebuffer.viewHeight);
float lineWidth = Math.max(1.0f, modMain.getSettings().chunkGridLineWidth * Globals.minimapScaleMultiplier / (float) Globals.minimapSizeMultiplier);
RenderSystem.lineWidth(lineWidth);
var matrix = matrixStack.last();
float r = 0.0f;
float g = 1.0f;
float b = 1.0f;
float a = 0.8f;
helper.addColoredLineToExistingBuffer(
matrix, lineBufferBuilder,
x0, z0, x1, z0,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrix, lineBufferBuilder,
x0, z1, x1, z1,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrix, lineBufferBuilder,
x1, z0, x1, z1,
r, g, b, a
);
helper.addColoredLineToExistingBuffer(
matrix, lineBufferBuilder,
x0, z0, x0, z1,
r, g, b, a
);
}

@Redirect(method = "renderChunksToFBO", at = @At(
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/xaeroplus/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,18 @@ static void markChunksDirtyInWriteDistance() {
"xaeroplus.setting.show_render_distance_world_map",
false),
SettingLocation.MINIMAP_OVERLAYS);
public final BooleanSetting showWorldBorderSetting = register(
BooleanSetting.create(
"Show World Border",
"xaeroplus.setting.show_world_border",
false),
SettingLocation.MINIMAP_OVERLAYS);
public final BooleanSetting showWorldBorderWorldMapSetting = register(
BooleanSetting.create(
"Show World Border WorldMap",
"xaeroplus.setting.show_world_border_world_map",
false),
SettingLocation.MINIMAP_OVERLAYS);
public final BooleanSetting nullOverworldDimensionFolder = register(
BooleanSetting.create(
"null OW Dim Dir",
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
"xaeroplus.setting.show_render_distance.tooltip": "Show server side render distance (actually just another setting).",
"xaeroplus.setting.show_render_distance_world_map": "Show Render Distance on WorldMap",
"xaeroplus.setting.show_render_distance_world_map.tooltip": "Show server side render distance on the WorldMap.",
"xaeroplus.setting.show_world_border": "Show World Border",
"xaeroplus.setting.show_world_border.tooltip": "Renders a rectangle on the current world border",
"xaeroplus.setting.show_world_border_world_map": "Show World Border on WorldMap",
"xaeroplus.setting.show_world_border_world_map.tooltip": "Renders a rectangle on the current world border on the WorldMap",
"xaeroplus.setting.assumed_server_render_distance": "Server Render Distance",
"xaeroplus.setting.assumed_server_render_distance.tooltip": "View-distance of the server.",
"xaeroplus.setting.null_overworld_dimension_folder": "null OW Dim Dir",
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/es_ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
"xaeroplus.setting.show_render_distance.tooltip": "Muestra la distancia de renderizado del servidor (en realidad, solo otro ajuste).",
"xaeroplus.setting.show_render_distance_world_map": "Mostrar Distancia Renderizado MapaMundi",
"xaeroplus.setting.show_render_distance_world_map.tooltip": "Muestra la distancia de renderizado del servidor en el MapaMundi.",
"xaeroplus.setting.show_world_border": "Mostrar Frontera del Mundo",
"xaeroplus.setting.show_world_border.tooltip": "Dibuja un rectángulo en la frontera actual del mundo",
"xaeroplus.setting.show_world_border_world_map": "Mostrar Frontera del Mundo en el Mapa del Mundo",
"xaeroplus.setting.show_world_border_world_map.tooltip": "Dibuja un rectángulo en la frontera actual del mundo en el Mapa del Mundo",
"xaeroplus.setting.assumed_server_render_distance": "Distancia Renderizado Servidor",
"xaeroplus.setting.assumed_server_render_distance.tooltip": "Distancia visual del servidor.",
"xaeroplus.setting.null_overworld_dimension_folder": "Carpeta Dimension OW",
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/resources/assets/xaeroplus/lang/fr_ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
"xaeroplus.setting.show_render_distance.tooltip": "Afficher la distance de rendu côté serveur.",
"xaeroplus.setting.show_render_distance_world_map": "Afficher la distance de rendu sur la WorldMap",
"xaeroplus.setting.show_render_distance_world_map.tooltip": "Afficher la distance de rendu côté serveur sur la carte du monde.",
"xaeroplus.setting.show_world_border": "Afficher la Frontière du Monde",
"xaeroplus.setting.show_world_border.tooltip": "Affiche un rectangle sur la frontière actuelle du monde",
"xaeroplus.setting.show_world_border_world_map": "Afficher la Frontière du Monde sur la Carte du Monde",
"xaeroplus.setting.show_world_border_world_map.tooltip": "Affiche un rectangle sur la frontière actuelle du monde sur la Carte du Monde",
"xaeroplus.setting.assumed_server_render_distance": "Distance de rendu du serveur",
"xaeroplus.setting.assumed_server_render_distance.tooltip": "Distance de vue du serveur.",
"xaeroplus.setting.null_overworld_dimension_folder": "null OW Dim Dir",
Expand Down
Loading

0 comments on commit e7d95eb

Please sign in to comment.