Initial sanctuary sources

This commit is contained in:
cnstiout
2026-07-04 20:27:08 +02:00
commit c796a20321
1582 changed files with 253264 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
# Gradle
.gradle/
build/
out/
classes/
# Eclipse
*.launch
# IntelliJ IDEA
.idea/
*.iml
*.ipr
*.iws
# VS Code
.settings/
.vscode/
bin/
.classpath
.project
# macOS
*.DS_Store
# Fabric
run/
# Java
.jdk/
hs_err_*.log
replay_*.log
*.hprof
*.jfr
+72
View File
@@ -0,0 +1,72 @@
plugins {
id "net.fabricmc.fabric-loom" version "${loom_version}"
id "maven-publish"
}
version = project.mod_version
group = project.maven_group
base {
archivesName = project.archives_base_name
}
repositories {
mavenCentral()
}
loom {
splitEnvironmentSourceSets()
mods {
"atlas" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
}
processResources {
def version = project.version
inputs.property "version", version
filesMatching("fabric.mod.json") {
expand "version": version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 25
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
jar {
inputs.property "archivesName", project.base.archivesName
from("../../license.txt") {
rename { "${it}_${inputs.properties.archivesName}" }
}
}
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
repositories {
}
}
+21
View File
@@ -0,0 +1,21 @@
# Done to increase the memory available to Gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# IntelliJ IDEA is not yet fully compatible with configuration cache:
# https://github.com/FabricMC/fabric-loom/issues/1349
org.gradle.configuration-cache=false
# Fabric properties
# Check current versions on https://fabricmc.net/develop
minecraft_version=26.1.2
loader_version=0.19.2
loom_version=1.16-SNAPSHOT
# Mod properties
mod_version=1.0.0
maven_group=fr.koka99cab
archives_base_name=atlas
# Dependencies
fabric_api_version=0.148.0+26.1.2
Binary file not shown.
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+253
View File
@@ -0,0 +1,253 @@
#!/bin/sh
#
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
if [ -z "$JAVA_HOME" ] && [ -x "$APP_HOME/.jdk/current/bin/java" ] ; then
JAVA_HOME=$APP_HOME/.jdk/current
export JAVA_HOME
fi
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
+93
View File
@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+19
View File
@@ -0,0 +1,19 @@
# Atlas
Atlas est un module Fabric autonome qui ajoute un acces simple a une carte Atlas 3D des chunks visites.
## Compatibilite
- Aucune dependance dure a Sanctuary ou aux autres mods de la collection.
- La touche par defaut est `N` pour eviter les conflits avec les raccourcis deja presents dans la collection.
- L'item `atlas:atlas` ouvre le meme ecran au clic droit.
- Un bouton `Atlas` est ajoute dans le menu pause.
- Les chunks visites sont memorises cote client dans `atlas/visited_chunks.tsv`.
- La carte affiche les chunks de la dimension courante en isometrique, avec une hauteur estimee depuis la surface connue au moment de la visite.
## Premiere boucle de jeu
1. Mettre le jeu en pause et cliquer sur `Atlas`.
2. Ou appuyer sur `N` en jeu.
3. Ou crafter un atlas avec papier, compas et livre, puis clic droit.
4. Explorer: chaque chunk traverse apparait progressivement sur la carte.
+12
View File
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "atlas"
@@ -0,0 +1,52 @@
package fr.koka99cab.atlas.client;
import com.mojang.blaze3d.platform.InputConstants;
import fr.koka99cab.atlas.AtlasMod;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFW;
public final class AtlasClient implements ClientModInitializer {
private static final KeyMapping.Category ATLAS_CATEGORY =
KeyMapping.Category.register(AtlasMod.id("atlas"));
private static KeyMapping openMapKey;
@Override
public void onInitializeClient() {
openMapKey = KeyMappingHelper.registerKeyMapping(new KeyMapping(
"key.atlas.open_map",
InputConstants.Type.KEYSYM,
GLFW.GLFW_KEY_N,
ATLAS_CATEGORY
));
AtlasClientBridge.setMapOpener(AtlasClient::openMap);
ClientTickEvents.END_CLIENT_TICK.register(AtlasClient::tick);
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> AtlasVisitedChunks.saveIfDirty(client));
}
private static void tick(Minecraft client) {
AtlasVisitedChunks.tick(client);
while (openMapKey.consumeClick()) {
openMap();
}
}
private static void openMap() {
Minecraft client = Minecraft.getInstance();
if (client.player == null || client.level == null) {
return;
}
if (client.screen instanceof AtlasMapScreen) {
client.setScreen(null);
return;
}
client.setScreen(new AtlasMapScreen());
}
}
@@ -0,0 +1,338 @@
package fr.koka99cab.atlas.client;
import fr.koka99cab.atlas.client.AtlasVisitedChunks.VisitedChunk;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
public final class AtlasMapScreen extends Screen {
private static final int BACKDROP = 0xAA05080A;
private static final int PANEL = 0xEE151A1C;
private static final int PANEL_BORDER = 0xFF6F7F83;
private static final int MAP_BG = 0xFF101617;
private static final int MAP_LINE_MAJOR = 0x444E777B;
private static final int MAP_LINE_MINOR = 0x223E5659;
private static final int PLAYER_DOT = 0xFFE9F06B;
private static final int TEXT = 0xFFE8E8DD;
private static final int MUTED = 0xFF9EA9A8;
private static final int PANEL_MARGIN = 24;
private static final int BUTTON_WIDTH = 92;
private static final int BUTTON_HEIGHT = 20;
private static final int MIN_ZOOM = 0;
private static final int MAX_ZOOM = 4;
private static int rememberedZoom = 2;
private int zoom = rememberedZoom;
public AtlasMapScreen() {
super(Component.translatable("screen.atlas.map"));
}
@Override
protected void init() {
addRenderableWidget(Button.builder(Component.translatable("gui.done"), button -> this.minecraft.setScreen(null))
.bounds(this.width - PANEL_MARGIN - BUTTON_WIDTH, this.height - PANEL_MARGIN - BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT)
.build());
}
@Override
public boolean isPauseScreen() {
return false;
}
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
int direction = scrollY > 0.0D ? 1 : -1;
this.zoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, this.zoom + direction));
rememberedZoom = this.zoom;
return true;
}
@Override
public boolean mouseDragged(MouseButtonEvent event, double dragX, double dragY) {
return super.mouseDragged(event, dragX, dragY);
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mouseY, float tickDelta) {
graphics.fill(0, 0, this.width, this.height, BACKDROP);
Layout layout = layout();
Minecraft client = Minecraft.getInstance();
List<VisitedChunk> chunks = AtlasVisitedChunks.currentDimensionChunks(client);
List<RenderChunk> visibleChunks = collectVisibleChunks(client, chunks, layout);
graphics.fill(layout.panelX(), layout.panelY(), layout.panelRight(), layout.panelBottom(), PANEL);
graphics.outline(layout.panelX(), layout.panelY(), layout.panelWidth(), layout.panelHeight(), PANEL_BORDER);
graphics.fill(layout.mapX(), layout.mapY(), layout.mapRight(), layout.mapBottom(), MAP_BG);
graphics.outline(layout.mapX(), layout.mapY(), layout.mapSize(), layout.mapSize(), PANEL_BORDER);
drawGrid(graphics, layout);
drawChunks(graphics, layout, visibleChunks);
drawPlayerDot(graphics, layout);
drawHeader(graphics, layout, chunks.size(), visibleChunks.size());
super.extractRenderState(graphics, mouseX, mouseY, tickDelta);
}
private void drawGrid(GuiGraphicsExtractor graphics, Layout layout) {
int minorStep = Math.max(12, layout.tileHalfWidth() * 2);
for (int x = layout.mapX() + minorStep; x < layout.mapRight(); x += minorStep) {
graphics.verticalLine(x, layout.mapY(), layout.mapBottom(), MAP_LINE_MINOR);
}
for (int y = layout.mapY() + minorStep; y < layout.mapBottom(); y += minorStep) {
graphics.horizontalLine(layout.mapX(), layout.mapRight(), y, MAP_LINE_MINOR);
}
int centerX = layout.mapX() + layout.mapSize() / 2;
int centerY = layout.mapY() + layout.mapSize() / 2;
graphics.verticalLine(centerX, layout.mapY(), layout.mapBottom(), MAP_LINE_MAJOR);
graphics.horizontalLine(layout.mapX(), layout.mapRight(), centerY, MAP_LINE_MAJOR);
}
private List<RenderChunk> collectVisibleChunks(Minecraft client, List<VisitedChunk> chunks, Layout layout) {
if (client.player == null) {
return List.of();
}
int playerChunkX = client.player.getBlockX() >> 4;
int playerChunkZ = client.player.getBlockZ() >> 4;
int radius = visibleRadius();
List<VisitedChunk> nearby = chunks.stream()
.filter(chunk -> Math.abs(chunk.chunkX() - playerChunkX) <= radius && Math.abs(chunk.chunkZ() - playerChunkZ) <= radius)
.toList();
if (nearby.isEmpty()) {
return List.of();
}
int minHeight = nearby.stream().mapToInt(VisitedChunk::surfaceY).min().orElse(client.player.getBlockY());
int maxHeight = nearby.stream().mapToInt(VisitedChunk::surfaceY).max().orElse(minHeight + 1);
int heightRange = Math.max(1, maxHeight - minHeight);
List<RenderChunk> renderChunks = new ArrayList<>();
for (VisitedChunk chunk : nearby) {
int dx = chunk.chunkX() - playerChunkX;
int dz = chunk.chunkZ() - playerChunkZ;
int screenX = layout.mapCenterX() + (dx - dz) * layout.tileHalfWidth();
int screenY = layout.mapCenterY() + (dx + dz) * layout.tileHalfHeight();
int elevation = Math.max(2, Math.min(42, Math.round(((chunk.surfaceY() - minHeight) / (float) heightRange) * 42.0F)));
int topY = screenY - elevation;
if (screenX < layout.mapX() - layout.tileHalfWidth() || screenX > layout.mapRight() + layout.tileHalfWidth()) {
continue;
}
if (topY < layout.mapY() - 48 || screenY > layout.mapBottom() + 48) {
continue;
}
boolean playerChunk = chunk.chunkX() == playerChunkX && chunk.chunkZ() == playerChunkZ;
renderChunks.add(new RenderChunk(chunk, screenX, screenY, elevation, colorFor(chunk, minHeight, maxHeight, playerChunk), playerChunk));
}
renderChunks.sort(Comparator
.comparingInt(RenderChunk::sortY)
.thenComparingInt(renderChunk -> renderChunk.chunk().chunkX())
.thenComparingInt(renderChunk -> renderChunk.chunk().chunkZ()));
return renderChunks;
}
private void drawChunks(GuiGraphicsExtractor graphics, Layout layout, List<RenderChunk> chunks) {
graphics.enableScissor(layout.mapX() + 1, layout.mapY() + 1, layout.mapRight() - 1, layout.mapBottom() - 1);
for (RenderChunk chunk : chunks) {
drawChunkColumn(graphics, layout, chunk);
}
graphics.disableScissor();
}
private void drawChunkColumn(GuiGraphicsExtractor graphics, Layout layout, RenderChunk chunk) {
int cx = chunk.screenX();
int topY = chunk.baseY() - chunk.elevation();
int hw = layout.tileHalfWidth();
int hh = layout.tileHalfHeight();
int baseY = chunk.baseY();
int color = chunk.color();
int leftColor = shade(color, 0.70F);
int rightColor = shade(color, 0.52F);
int topColor = chunk.playerChunk() ? 0xFFE9F06B : color;
fillQuad(graphics,
new int[] {cx - hw, cx, cx, cx - hw},
new int[] {topY, topY + hh, baseY + hh, baseY},
leftColor
);
fillQuad(graphics,
new int[] {cx + hw, cx, cx, cx + hw},
new int[] {topY, topY + hh, baseY + hh, baseY},
rightColor
);
fillDiamond(graphics, cx, topY, hw, hh, topColor);
if (chunk.playerChunk()) {
graphics.outline(cx - hw - 1, topY - hh - 1, hw * 2 + 2, hh * 2 + 2, PLAYER_DOT);
}
}
private static void fillDiamond(GuiGraphicsExtractor graphics, int cx, int cy, int halfWidth, int halfHeight, int color) {
for (int dy = -halfHeight; dy <= halfHeight; dy++) {
float t = 1.0F - Math.abs(dy) / (float) Math.max(1, halfHeight);
int width = Math.max(1, Math.round(halfWidth * t));
graphics.horizontalLine(cx - width, cx + width, cy + dy, color);
}
}
private static void fillQuad(GuiGraphicsExtractor graphics, int[] x, int[] y, int color) {
int minY = Math.min(Math.min(y[0], y[1]), Math.min(y[2], y[3]));
int maxY = Math.max(Math.max(y[0], y[1]), Math.max(y[2], y[3]));
for (int scanY = minY; scanY <= maxY; scanY++) {
List<Integer> intersections = new ArrayList<>(4);
for (int index = 0; index < 4; index++) {
int next = (index + 1) % 4;
int y1 = y[index];
int y2 = y[next];
if (y1 == y2) {
continue;
}
if ((scanY >= Math.min(y1, y2)) && (scanY < Math.max(y1, y2))) {
float t = (scanY - y1) / (float) (y2 - y1);
intersections.add(Math.round(x[index] + (x[next] - x[index]) * t));
}
}
if (intersections.size() >= 2) {
intersections.sort(Integer::compareTo);
graphics.horizontalLine(intersections.get(0), intersections.get(intersections.size() - 1), scanY, color);
}
}
}
private void drawPlayerDot(GuiGraphicsExtractor graphics, Layout layout) {
int centerX = layout.mapX() + layout.mapSize() / 2;
int centerY = layout.mapY() + layout.mapSize() / 2;
graphics.fill(centerX - 2, centerY - 7, centerX + 3, centerY - 2, PLAYER_DOT);
graphics.outline(centerX - 4, centerY - 9, 9, 9, 0xFF101010);
}
private void drawHeader(GuiGraphicsExtractor graphics, Layout layout, int totalChunks, int visibleChunks) {
Minecraft client = Minecraft.getInstance();
String dimension = client.level == null ? "" : readableDimension(client.level.dimension());
String position = client.player == null
? ""
: "X " + client.player.getBlockX() + " Y " + client.player.getBlockY() + " Z " + client.player.getBlockZ();
graphics.text(this.font, this.title, layout.panelX() + 14, layout.panelY() + 12, TEXT);
graphics.text(this.font, dimension, layout.panelX() + 14, layout.panelY() + 28, MUTED);
graphics.text(this.font, Component.translatable("screen.atlas.chunk_count", totalChunks, visibleChunks), layout.panelX() + 14, layout.panelBottom() - 48, MUTED);
graphics.text(this.font, position, layout.panelX() + 14, layout.panelBottom() - 34, MUTED);
graphics.text(this.font, Component.translatable("screen.atlas.zoom", this.zoom + 1), layout.panelRight() - 90, layout.panelY() + 12, MUTED);
}
private static String readableDimension(ResourceKey<Level> key) {
return key.identifier().toString();
}
private Layout layout() {
int panelWidth = Math.min(this.width - PANEL_MARGIN * 2, 560);
int panelHeight = Math.min(this.height - PANEL_MARGIN * 2, 360);
int panelX = (this.width - panelWidth) / 2;
int panelY = (this.height - panelHeight) / 2;
int mapSize = Math.max(96, Math.min(panelWidth - 40, panelHeight - 86));
int mapX = panelX + (panelWidth - mapSize) / 2;
int mapY = panelY + 54;
int tileHalfWidth = 6 + this.zoom * 3;
int tileHalfHeight = Math.max(3, tileHalfWidth / 2);
return new Layout(panelX, panelY, panelWidth, panelHeight, mapX, mapY, mapSize, tileHalfWidth, tileHalfHeight);
}
private int visibleRadius() {
return Math.max(10, 58 - this.zoom * 10);
}
private static int colorFor(VisitedChunk chunk, int minHeight, int maxHeight, boolean playerChunk) {
if (playerChunk) {
return PLAYER_DOT;
}
float t = (chunk.surfaceY() - minHeight) / (float) Math.max(1, maxHeight - minHeight);
if (t < 0.42F) {
return lerpColor(0xFF355865, 0xFF5E8A68, t / 0.42F);
}
if (t < 0.78F) {
return lerpColor(0xFF5E8A68, 0xFF9B976D, (t - 0.42F) / 0.36F);
}
return lerpColor(0xFF9B976D, 0xFFE1DDC8, (t - 0.78F) / 0.22F);
}
private static int shade(int color, float factor) {
int r = Math.round(((color >> 16) & 0xFF) * factor);
int g = Math.round(((color >> 8) & 0xFF) * factor);
int b = Math.round((color & 0xFF) * factor);
return 0xFF000000 | (clampColor(r) << 16) | (clampColor(g) << 8) | clampColor(b);
}
private static int lerpColor(int from, int to, float t) {
float clamped = Math.max(0.0F, Math.min(1.0F, t));
int r = Math.round(((from >> 16) & 0xFF) + (((to >> 16) & 0xFF) - ((from >> 16) & 0xFF)) * clamped);
int g = Math.round(((from >> 8) & 0xFF) + (((to >> 8) & 0xFF) - ((from >> 8) & 0xFF)) * clamped);
int b = Math.round((from & 0xFF) + ((to & 0xFF) - (from & 0xFF)) * clamped);
return 0xFF000000 | (clampColor(r) << 16) | (clampColor(g) << 8) | clampColor(b);
}
private static int clampColor(int value) {
return Math.max(0, Math.min(255, value));
}
private record Layout(
int panelX,
int panelY,
int panelWidth,
int panelHeight,
int mapX,
int mapY,
int mapSize,
int tileHalfWidth,
int tileHalfHeight
) {
int panelRight() {
return this.panelX + this.panelWidth;
}
int panelBottom() {
return this.panelY + this.panelHeight;
}
int mapRight() {
return this.mapX + this.mapSize;
}
int mapBottom() {
return this.mapY + this.mapSize;
}
int mapCenterX() {
return this.mapX + this.mapSize / 2;
}
int mapCenterY() {
return this.mapY + this.mapSize / 2;
}
}
private record RenderChunk(
VisitedChunk chunk,
int screenX,
int baseY,
int elevation,
int color,
boolean playerChunk
) {
int sortY() {
return this.baseY;
}
}
}
@@ -0,0 +1,231 @@
package fr.koka99cab.atlas.client;
import fr.koka99cab.atlas.AtlasMod;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.world.level.levelgen.Heightmap;
public final class AtlasVisitedChunks {
private static final String FILE_NAME = "visited_chunks.tsv";
private static final int SAVE_COOLDOWN_TICKS = 80;
private static final long SAME_CHUNK_REFRESH_INTERVAL_MS = 60_000L;
private static final Map<ChunkKey, VisitedChunk> CHUNKS = new HashMap<>();
private static boolean loaded;
private static boolean dirty;
private static int saveCooldownTicks;
private AtlasVisitedChunks() {
}
public static void tick(Minecraft client) {
if (client.level == null || client.player == null) {
saveIfDirty(client);
return;
}
ensureLoaded(client);
recordCurrentChunk(client);
if (dirty && saveCooldownTicks > 0) {
saveCooldownTicks--;
}
if (dirty && saveCooldownTicks <= 0) {
save(client);
}
}
public static List<VisitedChunk> currentDimensionChunks(Minecraft client) {
if (client.level == null) {
return List.of();
}
ensureLoaded(client);
String world = worldKey(client);
String dimension = dimensionKey(client);
return CHUNKS.values().stream()
.filter(chunk -> chunk.worldKey().equals(world) && chunk.dimension().equals(dimension))
.sorted(Comparator.comparingInt(VisitedChunk::chunkX).thenComparingInt(VisitedChunk::chunkZ))
.toList();
}
public static void saveIfDirty(Minecraft client) {
if (dirty) {
save(client);
}
}
private static void recordCurrentChunk(Minecraft client) {
String world = worldKey(client);
String dimension = dimensionKey(client);
int chunkX = client.player.getBlockX() >> 4;
int chunkZ = client.player.getBlockZ() >> 4;
int surfaceY = estimateSurfaceY(client, chunkX, chunkZ);
long visitedAt = System.currentTimeMillis();
ChunkKey key = new ChunkKey(world, dimension, chunkX, chunkZ);
VisitedChunk previous = CHUNKS.get(key);
if (previous != null && Math.abs(previous.surfaceY() - surfaceY) <= 1) {
if (visitedAt - previous.lastVisited() < SAME_CHUNK_REFRESH_INTERVAL_MS) {
return;
}
CHUNKS.put(key, previous.withLastVisited(visitedAt));
} else {
CHUNKS.put(key, new VisitedChunk(world, dimension, chunkX, chunkZ, surfaceY, visitedAt));
}
dirty = true;
if (saveCooldownTicks <= 0) {
saveCooldownTicks = SAVE_COOLDOWN_TICKS;
}
}
private static int estimateSurfaceY(Minecraft client, int chunkX, int chunkZ) {
int fallbackY = client.player.getBlockY();
if (client.level == null || !client.level.hasChunk(chunkX, chunkZ)) {
return fallbackY;
}
int blockX = (chunkX << 4) + 8;
int blockZ = (chunkZ << 4) + 8;
int surfaceY = client.level.getHeight(Heightmap.Types.WORLD_SURFACE, blockX, blockZ);
if (surfaceY <= client.level.getMinY()) {
return fallbackY;
}
return surfaceY;
}
private static void ensureLoaded(Minecraft client) {
if (loaded) {
return;
}
loaded = true;
Path file = storageFile(client);
if (!Files.isRegularFile(file)) {
return;
}
try {
for (String line : Files.readAllLines(file, StandardCharsets.UTF_8)) {
if (line.isBlank() || line.startsWith("#")) {
continue;
}
VisitedChunk.fromLine(line).ifPresent(chunk ->
CHUNKS.put(new ChunkKey(chunk.worldKey(), chunk.dimension(), chunk.chunkX(), chunk.chunkZ()), chunk)
);
}
} catch (IOException exception) {
AtlasMod.LOGGER.warn("Impossible de lire les chunks visites d'Atlas.", exception);
}
}
private static void save(Minecraft client) {
ensureLoaded(client);
Path file = storageFile(client);
try {
Files.createDirectories(file.getParent());
List<String> lines = new ArrayList<>();
lines.add("# Atlas visited chunks v1");
CHUNKS.values().stream()
.sorted(Comparator
.comparing(VisitedChunk::worldKey)
.thenComparing(VisitedChunk::dimension)
.thenComparingInt(VisitedChunk::chunkX)
.thenComparingInt(VisitedChunk::chunkZ))
.map(VisitedChunk::toLine)
.forEach(lines::add);
Files.write(file, lines, StandardCharsets.UTF_8);
dirty = false;
saveCooldownTicks = 0;
} catch (IOException exception) {
AtlasMod.LOGGER.warn("Impossible d'enregistrer les chunks visites d'Atlas.", exception);
saveCooldownTicks = SAVE_COOLDOWN_TICKS;
}
}
private static Path storageFile(Minecraft client) {
return client.gameDirectory.toPath().resolve("atlas").resolve(FILE_NAME);
}
private static String worldKey(Minecraft client) {
ServerData serverData = client.getCurrentServer();
if (serverData != null && serverData.ip != null && !serverData.ip.isBlank()) {
return "server:" + serverData.ip;
}
IntegratedServer server = client.getSingleplayerServer();
if (server != null && server.getWorldData() != null) {
return "singleplayer:" + server.getWorldData().getLevelName();
}
return "local";
}
private static String dimensionKey(Minecraft client) {
return client.level.dimension().identifier().toString();
}
private static String encode(String value) {
return Base64.getUrlEncoder().withoutPadding().encodeToString(value.getBytes(StandardCharsets.UTF_8));
}
private static String decode(String value) {
return new String(Base64.getUrlDecoder().decode(value), StandardCharsets.UTF_8);
}
private record ChunkKey(String worldKey, String dimension, int chunkX, int chunkZ) {
}
public record VisitedChunk(
String worldKey,
String dimension,
int chunkX,
int chunkZ,
int surfaceY,
long lastVisited
) {
private static java.util.Optional<VisitedChunk> fromLine(String line) {
String[] parts = line.split("\\t");
if (parts.length != 6) {
return java.util.Optional.empty();
}
try {
return java.util.Optional.of(new VisitedChunk(
decode(parts[0]),
decode(parts[1]),
Integer.parseInt(parts[2]),
Integer.parseInt(parts[3]),
Integer.parseInt(parts[4]),
Long.parseLong(parts[5])
));
} catch (IllegalArgumentException exception) {
return java.util.Optional.empty();
}
}
private String toLine() {
return encode(this.worldKey) + "\t"
+ encode(this.dimension) + "\t"
+ this.chunkX + "\t"
+ this.chunkZ + "\t"
+ this.surfaceY + "\t"
+ this.lastVisited;
}
private VisitedChunk withLastVisited(long visitedAt) {
return new VisitedChunk(this.worldKey, this.dimension, this.chunkX, this.chunkZ, this.surfaceY, visitedAt);
}
}
}
@@ -0,0 +1,37 @@
package fr.koka99cab.atlas.client.mixin;
import fr.koka99cab.atlas.client.AtlasMapScreen;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PauseScreen.class)
public abstract class PauseScreenMixin extends Screen {
private static final int BUTTON_X = 8;
private static final int BUTTON_Y = 8;
private static final int BUTTON_WIDTH = 74;
private static final int BUTTON_HEIGHT = 20;
protected PauseScreenMixin(Component title) {
super(title);
}
@Inject(method = "init", at = @At("TAIL"))
private void atlas$addMapButton(CallbackInfo ci) {
if (this.minecraft == null || this.minecraft.player == null || this.minecraft.level == null) {
return;
}
this.addRenderableWidget(Button.builder(
Component.translatable("button.atlas.map"),
button -> this.minecraft.setScreen(new AtlasMapScreen())
)
.bounds(BUTTON_X, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT)
.build());
}
}
@@ -0,0 +1,11 @@
{
"required": true,
"package": "fr.koka99cab.atlas.client.mixin",
"compatibilityLevel": "JAVA_25",
"client": [
"PauseScreenMixin"
],
"injectors": {
"defaultRequire": 1
}
}
@@ -0,0 +1,22 @@
package fr.koka99cab.atlas;
import fr.koka99cab.atlas.registry.AtlasItems;
import net.fabricmc.api.ModInitializer;
import net.minecraft.resources.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class AtlasMod implements ModInitializer {
public static final String MOD_ID = "atlas";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Identifier id(String path) {
return Identifier.fromNamespaceAndPath(MOD_ID, path);
}
@Override
public void onInitialize() {
AtlasItems.initialize();
LOGGER.info("Atlas charge pour Minecraft 26.1.2.");
}
}
@@ -0,0 +1,18 @@
package fr.koka99cab.atlas.client;
public final class AtlasClientBridge {
private static Runnable mapOpener = () -> {
};
private AtlasClientBridge() {
}
public static void setMapOpener(Runnable mapOpener) {
AtlasClientBridge.mapOpener = mapOpener == null ? () -> {
} : mapOpener;
}
public static void openMap() {
mapOpener.run();
}
}
@@ -0,0 +1,40 @@
package fr.koka99cab.atlas.item;
import fr.koka99cab.atlas.client.AtlasClientBridge;
import java.util.function.Consumer;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.TooltipDisplay;
import net.minecraft.world.level.Level;
public class AtlasItem extends Item {
public AtlasItem(Properties settings) {
super(settings);
}
@Override
public InteractionResult use(Level world, Player player, InteractionHand hand) {
if (world.isClientSide()) {
AtlasClientBridge.openMap();
}
return InteractionResult.CONSUME;
}
@Override
public void appendHoverText(
ItemStack stack,
TooltipContext context,
TooltipDisplay displayComponent,
Consumer<Component> textConsumer,
TooltipFlag type
) {
textConsumer.accept(Component.translatable("tooltip.atlas.open").withStyle(ChatFormatting.GRAY));
}
}
@@ -0,0 +1,38 @@
package fr.koka99cab.atlas.registry;
import fr.koka99cab.atlas.AtlasMod;
import fr.koka99cab.atlas.item.AtlasItem;
import java.util.function.Function;
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
public final class AtlasItems {
public static final Item ATLAS = register("atlas", settings -> new AtlasItem(settings.stacksTo(1)));
private AtlasItems() {
}
public static void initialize() {
CreativeModeTabEvents.modifyOutputEvent(vanillaTab("tools_and_utilities")).register(entries ->
entries.accept(new ItemStack(ATLAS), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS)
);
}
private static Item register(String path, Function<Item.Properties, Item> factory) {
Identifier id = AtlasMod.id(path);
ResourceKey<Item> key = ResourceKey.create(Registries.ITEM, id);
Item.Properties settings = new Item.Properties().setId(key);
return Registry.register(BuiltInRegistries.ITEM, key, factory.apply(settings));
}
private static ResourceKey<CreativeModeTab> vanillaTab(String path) {
return ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.fromNamespaceAndPath("minecraft", path));
}
}
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "minecraft:item/map"
}
}
@@ -0,0 +1,10 @@
{
"item.atlas.atlas": "Atlas",
"tooltip.atlas.open": "Opens the Atlas map",
"screen.atlas.map": "Atlas",
"screen.atlas.chunk_count": "Visited chunks: %s (%s visible)",
"screen.atlas.zoom": "Zoom %s",
"button.atlas.map": "Atlas",
"key.categories.atlas.atlas": "Atlas",
"key.atlas.open_map": "Open Atlas map"
}
@@ -0,0 +1,10 @@
{
"item.atlas.atlas": "Atlas",
"tooltip.atlas.open": "Ouvre la carte Atlas",
"screen.atlas.map": "Atlas",
"screen.atlas.chunk_count": "Chunks visites : %s (%s visibles)",
"screen.atlas.zoom": "Zoom %s",
"button.atlas.map": "Atlas",
"key.categories.atlas.atlas": "Atlas",
"key.atlas.open_map": "Ouvrir la carte Atlas"
}
@@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"pattern": [
"PPP",
"PCP",
"PBP"
],
"key": {
"B": "minecraft:book",
"C": "minecraft:compass",
"P": "minecraft:paper"
},
"result": {
"id": "atlas:atlas",
"count": 1
}
}
@@ -0,0 +1,29 @@
{
"schemaVersion": 1,
"id": "atlas",
"version": "${version}",
"name": "Atlas",
"description": "A portable marker atlas for every world, dimension, and modded exploration route.",
"authors": [
"KOKA99CAB"
],
"license": "LGPL-3.0-or-later",
"environment": "*",
"entrypoints": {
"main": [
"fr.koka99cab.atlas.AtlasMod"
],
"client": [
"fr.koka99cab.atlas.client.AtlasClient"
]
},
"mixins": [
"atlas.client.mixins.json"
],
"depends": {
"fabricloader": ">=0.19.2",
"minecraft": "~26.1.2",
"java": ">=25",
"fabric-api": "*"
}
}