├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── resources │ ├── assets │ │ └── lambdamap │ │ │ ├── textures │ │ │ ├── markers │ │ │ │ ├── doctor4t.md │ │ │ │ └── doctor4t.png │ │ │ └── gui │ │ │ │ ├── map_hud_slot.png │ │ │ │ └── icon_selection.png │ │ │ ├── flags │ │ │ ├── genderfluid.json │ │ │ ├── polysexual.json │ │ │ ├── genderqueer.json │ │ │ ├── polyamorous.json │ │ │ ├── agender.json │ │ │ ├── demiboy.json │ │ │ └── demigirl.json │ │ │ └── lang │ │ │ └── en_us.json │ ├── lambdamap.toml │ ├── lambdamap.mixins.json │ └── quilt.mod.json │ └── java │ └── dev │ └── lambdaurora │ └── lambdamap │ ├── extension │ └── WorldChunkExtension.java │ ├── mixin │ ├── BiomeAccessAccessor.java │ ├── MapColorAccessor.java │ ├── PersistentStateManagerAccessor.java │ ├── ChunkDeltaUpdateS2CPacketAccessor.java │ ├── BlockColorsAccessor.java │ ├── ClientPlayerEntityMixin.java │ ├── WorldChunkMixin.java │ ├── ClientPlayerInteractionManagerMixin.java │ └── ClientPlayNetworkHandlerMixin.java │ ├── gui │ ├── hud │ │ ├── EmptyHudDecorator.java │ │ ├── SimpleTexturedHudDecorator.java │ │ ├── CompositeTexturedHudDecorator.java │ │ ├── HudDecorator.java │ │ ├── HudDecorators.java │ │ └── MapHud.java │ ├── MarkerTabWidget.java │ ├── ConfirmDeletionWidget.java │ ├── WorldMapScreen.java │ ├── MarkerTypeButton.java │ ├── RandomPrideFlagBackground.java │ ├── NewMarkerFormWidget.java │ ├── WorldMapWidget.java │ ├── MarkerListWidget.java │ └── WorldMapRenderer.java │ ├── map │ ├── marker │ │ ├── MarkerSource.java │ │ ├── MarkerManager.java │ │ ├── MarkerType.java │ │ └── Marker.java │ ├── ChunkGetterMode.java │ ├── storage │ │ └── MapRegionFile.java │ └── WorldMap.java │ ├── util │ └── ClientWorldWrapper.java │ ├── BlockSearcher.java │ ├── LambdaMapConfig.java │ └── LambdaMap.java ├── settings.gradle ├── gradle.properties ├── .github └── workflows │ └── gradle_build.yml ├── README.md ├── codeformat └── HEADER ├── .gitignore ├── gradlew.bat ├── LICENSE └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdAurora/LambdaMap/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/textures/markers/doctor4t.md: -------------------------------------------------------------------------------- 1 | Credits to [doctor4t](https://github.com/doctor4t) for the custom icons in `doctor4t.png`. -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/genderfluid.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#ff75a2", 4 | "#ffffff", 5 | "#be18d6", 6 | "#000000", 7 | "#333ebd" 8 | ] 9 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/textures/gui/map_hud_slot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdAurora/LambdaMap/HEAD/src/main/resources/assets/lambdamap/textures/gui/map_hud_slot.png -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/textures/markers/doctor4t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdAurora/LambdaMap/HEAD/src/main/resources/assets/lambdamap/textures/markers/doctor4t.png -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/textures/gui/icon_selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LambdAurora/LambdaMap/HEAD/src/main/resources/assets/lambdamap/textures/gui/icon_selection.png -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/polysexual.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#f61cb9", 4 | "#f61cb9", 5 | "#07d569", 6 | "#07d569", 7 | "#1c92f6", 8 | "#1c92f6" 9 | ] 10 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/genderqueer.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#b57edc", 4 | "#b57edc", 5 | "#ffffff", 6 | "#ffffff", 7 | "#4a8123", 8 | "#4a8123" 9 | ] 10 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/polyamorous.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#5541ef", 4 | "#5541ef", 5 | "#d62900", 6 | "#d62900", 7 | "#292929", 8 | "#292929" 9 | ] 10 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/agender.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#000000", 4 | "#b9b9b9", 5 | "#ffffff", 6 | "#b8f483", 7 | "#ffffff", 8 | "#b9b9b9", 9 | "#000000" 10 | ] 11 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/demiboy.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#838483", 4 | "#c6c6c6", 5 | "#5bcefa", 6 | "#ffffff", 7 | "#5bcefa", 8 | "#c6c6c6", 9 | "#838483" 10 | ] 11 | } -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/flags/demigirl.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors": [ 3 | "#838483", 4 | "#c6c6c6", 5 | "#f5a9b8", 6 | "#ffffff", 7 | "#f5a9b8", 8 | "#c6c6c6", 9 | "#838483" 10 | ] 11 | } -------------------------------------------------------------------------------- /src/main/resources/lambdamap.toml: -------------------------------------------------------------------------------- 1 | # LambdaMap Configuration 2 | 3 | [map] 4 | render_biome_colors = true 5 | [map.hud] 6 | visible = true 7 | scale = 2 8 | north_lock = false 9 | direction_indicators = true 10 | decorator = "lambdamap:map" 11 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name 'Quilt' 5 | url 'https://maven.quiltmc.org/repository/release' 6 | } 7 | maven { 8 | name 'Fabric' 9 | url 'https://maven.fabricmc.net/' 10 | } 11 | gradlePluginPortal() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1G 2 | 3 | # Quilt properties 4 | minecraft_version=1.20.1 5 | quilt_mappings=23 6 | loader_version=0.19.2 7 | fabric_api_version=7.1.2+0.87.0 8 | qsl_version=6.1.1 9 | 10 | # Mod properties 11 | mod_version=1.0.0-alpha.1 12 | maven_group=dev.lambdaurora 13 | archives_base_name=lambdamap 14 | 15 | # Dependencies 16 | spruceui_version=5.0.2+1.20 17 | pridelib_version=1.2.0+1.19.4 18 | -------------------------------------------------------------------------------- /.github/workflows/gradle_build.yml: -------------------------------------------------------------------------------- 1 | name: Gradle Build 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Set up JDK 17 11 | uses: actions/setup-java@v2 12 | with: 13 | java-version: 17 14 | distribution: 'temurin' 15 | 16 | - name: Build with Gradle 17 | run: ./gradlew build 18 | 19 | - uses: actions/upload-artifact@v2 20 | with: 21 | name: Artifacts 22 | path: ./build/libs/ 23 | -------------------------------------------------------------------------------- /src/main/resources/lambdamap.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "dev.lambdaurora.lambdamap.mixin", 4 | "compatibilityLevel": "JAVA_17", 5 | "client": [ 6 | "BiomeAccessAccessor", 7 | "BlockColorsAccessor", 8 | "ChunkDeltaUpdateS2CPacketAccessor", 9 | "ClientPlayerEntityMixin", 10 | "ClientPlayerInteractionManagerMixin", 11 | "ClientPlayNetworkHandlerMixin", 12 | "MapColorAccessor", 13 | "PersistentStateManagerAccessor", 14 | "WorldChunkMixin" 15 | ], 16 | "injectors": { 17 | "defaultRequire": 1 18 | } 19 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LambdaMap 2 | 3 | 4 | ![Java 17](https://img.shields.io/badge/language-Java%2017-9B599A.svg?style=flat-square) 5 | [![GitHub license](https://img.shields.io/github/license/LambdAurora/LambdaMap?style=flat-square)](https://raw.githubusercontent.com/LambdAurora/LambdaMap/1.18/LICENSE) 6 | ![Environment: Client](https://img.shields.io/badge/environment-client-1976d2?style=flat-square) 7 | [![Mod loader: Quilt]][quilt] 8 | 9 | An experimental mini-map and world-map mod for Quilt 1.18. 10 | 11 | [quilt]: https://quiltmc.org 12 | [Mod loader: Quilt]: https://img.shields.io/badge/modloader-Quilt-1976d2?style=flat-square 13 | -------------------------------------------------------------------------------- /codeformat/HEADER: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021-2022 LambdAurora 2 | 3 | This program is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU Lesser General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Lesser General Public License for more details. 12 | 13 | You should have received a copy of the GNU Lesser General Public License 14 | along with this program. If not, see . 15 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/extension/WorldChunkExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.extension; 19 | 20 | public interface WorldChunkExtension { 21 | boolean lambdamap$isDirty(); 22 | boolean lambdamap$isBiomeDirty(); 23 | 24 | void lambdamap$markDirty(); 25 | 26 | void lambdamap$markClean(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/BiomeAccessAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import net.minecraft.world.biome.source.BiomeAccess; 21 | import org.spongepowered.asm.mixin.Mixin; 22 | import org.spongepowered.asm.mixin.gen.Accessor; 23 | 24 | @Mixin(BiomeAccess.class) 25 | public interface BiomeAccessAccessor { 26 | @Accessor 27 | long getSeed(); 28 | } 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # LambdAurora's ignore file 3 | # 4 | # v0.20 5 | 6 | # JetBrains 7 | .idea/ 8 | *.iml 9 | *.ipr 10 | *.iws 11 | ## Intellij IDEA 12 | out/ 13 | ## CLion 14 | cmake-build-debug*/ 15 | cmake-build-release*/ 16 | ## Eclipse 17 | eclipse 18 | *.launch 19 | .settings 20 | .metadata 21 | .classpath 22 | .project 23 | ## Visual Studio 24 | .vs/ 25 | CMakeSettings.json 26 | 27 | # Build system 28 | ## Cargo 29 | Cargo.lock 30 | ## CMake 31 | CMakeCache.txt 32 | CMakeLists.txt.user 33 | CMakeFiles/ 34 | ## QMake 35 | .qmake.stash 36 | ## Gradle 37 | .gradle/ 38 | ## Node.JS 39 | node_modules/ 40 | 41 | # Editors 42 | ## VSCode 43 | .vscode/ 44 | 45 | # Logging 46 | logs/ 47 | 48 | # Languages 49 | ## Java 50 | classes/ 51 | ## Python 52 | __pycache__/ 53 | venv/ 54 | ## Rust 55 | **/*.rs.bk 56 | 57 | # OS 58 | ## Windows 59 | desktop.ini 60 | # MacOS 61 | .DS_Store 62 | 63 | # File types 64 | *.dll 65 | *.db 66 | *.tar.?z 67 | 68 | # Asset files automatic backup 69 | .*.png-autosave.kra 70 | *.png~ 71 | 72 | # Compilation artifacts/Binaries 73 | *.o 74 | *.so 75 | *.dylib 76 | *.lib 77 | lib*.a 78 | 79 | # Common 80 | bin/ 81 | build/ 82 | dist/ 83 | lib/ 84 | !src/lib/ 85 | !src/**/lib/ 86 | obj/ 87 | run/ 88 | target/ 89 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/MapColorAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import net.minecraft.block.MapColor; 21 | import org.spongepowered.asm.mixin.Mixin; 22 | import org.spongepowered.asm.mixin.gen.Accessor; 23 | 24 | @Mixin(MapColor.class) 25 | public interface MapColorAccessor { 26 | @Accessor("COLORS") 27 | static MapColor[] getColors() { 28 | throw new AssertionError(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/PersistentStateManagerAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import net.minecraft.world.PersistentStateManager; 21 | import org.spongepowered.asm.mixin.Mixin; 22 | import org.spongepowered.asm.mixin.gen.Accessor; 23 | 24 | import java.io.File; 25 | 26 | @Mixin(PersistentStateManager.class) 27 | public interface PersistentStateManagerAccessor { 28 | @Accessor 29 | File getDirectory(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/ChunkDeltaUpdateS2CPacketAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket; 21 | import net.minecraft.util.math.ChunkSectionPos; 22 | import org.spongepowered.asm.mixin.Mixin; 23 | import org.spongepowered.asm.mixin.gen.Accessor; 24 | 25 | @Mixin(ChunkDeltaUpdateS2CPacket.class) 26 | public interface ChunkDeltaUpdateS2CPacketAccessor { 27 | @Accessor 28 | ChunkSectionPos getSectionPos(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/BlockColorsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import net.minecraft.client.color.block.BlockColorProvider; 21 | import net.minecraft.client.color.block.BlockColors; 22 | import net.minecraft.util.collection.IdList; 23 | import org.spongepowered.asm.mixin.Mixin; 24 | import org.spongepowered.asm.mixin.gen.Accessor; 25 | 26 | @Mixin(BlockColors.class) 27 | public interface BlockColorsAccessor { 28 | @Accessor 29 | IdList getProviders(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/EmptyHudDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import net.minecraft.client.gui.GuiGraphics; 22 | import net.minecraft.client.render.VertexConsumerProvider; 23 | import net.minecraft.util.Identifier; 24 | 25 | public final class EmptyHudDecorator extends HudDecorator { 26 | public static final Identifier ID = LambdaMap.id("none"); 27 | 28 | EmptyHudDecorator() { 29 | super(ID); 30 | } 31 | 32 | @Override 33 | public int getMargin() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public void render(GuiGraphics graphics, VertexConsumerProvider.Immediate immediate, int width, int height) { 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/resources/quilt.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema_version": 1, 3 | "quilt_loader": { 4 | "group": "dev.lambdaurora", 5 | "id": "lambdamap", 6 | "version": "${version}", 7 | "metadata": { 8 | "name": "LambdaMap", 9 | "description": "Minimap mod", 10 | "contributors": { 11 | "LambdAurora": "Author" 12 | }, 13 | "contact": { 14 | "homepage": "https://modrinth.com/mod/lambdamap", 15 | "sources": "https://github.com/LambdAurora/LambdaMap.git", 16 | "issues": "https://github.com/LambdAurora/LambdaMap/issues" 17 | }, 18 | "license": "LGPL-3.0-only", 19 | "icon": "assets/lambdamap/icon.png" 20 | }, 21 | "intermediate_mappings": "net.fabricmc:intermediary", 22 | "entrypoints": { 23 | "client_init": [ 24 | "dev.lambdaurora.lambdamap.LambdaMap::INSTANCE" 25 | ], 26 | "client_events": [ 27 | "dev.lambdaurora.lambdamap.LambdaMap::INSTANCE" 28 | ] 29 | }, 30 | "depends": [ 31 | { 32 | "id": "minecraft", 33 | "versions": "~1.20" 34 | }, 35 | { 36 | "id": "quilt_loader", 37 | "versions": "0.16.1" 38 | }, 39 | "quilt_crash_info", 40 | "quilt_lifecycle_events", 41 | "quilt_resource_loader", 42 | "quilted_fabric_key_binding_api_v1", 43 | "quilted_fabric_rendering_v1", 44 | { 45 | "id": "spruceui", 46 | "versions": ">=5.0.0" 47 | } 48 | ] 49 | }, 50 | "mixin": "lambdamap.mixins.json" 51 | } -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/marker/MarkerSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map.marker; 19 | 20 | import java.util.Locale; 21 | 22 | /** 23 | * Represents the source of a marker. 24 | * 25 | * @author LambdAurora 26 | * @version 1.0.0 27 | * @since 1.0.0 28 | */ 29 | public enum MarkerSource { 30 | USER, 31 | FILLED_MAP, 32 | BANNER; 33 | 34 | public String getId() { 35 | return this.name().toLowerCase(Locale.ROOT); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return this.getId(); 41 | } 42 | 43 | public static MarkerSource fromId(String id) { 44 | for (MarkerSource source : values()) { 45 | if (source.getId().equalsIgnoreCase(id)) 46 | return source; 47 | } 48 | return USER; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/ClientPlayerEntityMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import net.minecraft.client.MinecraftClient; 22 | import net.minecraft.client.network.ClientPlayerEntity; 23 | import org.spongepowered.asm.mixin.Final; 24 | import org.spongepowered.asm.mixin.Mixin; 25 | import org.spongepowered.asm.mixin.Shadow; 26 | import org.spongepowered.asm.mixin.injection.At; 27 | import org.spongepowered.asm.mixin.injection.Inject; 28 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 29 | 30 | @Mixin(ClientPlayerEntity.class) 31 | public class ClientPlayerEntityMixin { 32 | @Final 33 | @Shadow 34 | protected MinecraftClient client; 35 | 36 | @Inject(method = "init", at = @At("HEAD")) 37 | private void onInit(CallbackInfo ci) { 38 | LambdaMap.get().unloadMap(); 39 | LambdaMap.get().loadMap(client, client.world); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/WorldChunkMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import dev.lambdaurora.lambdamap.extension.WorldChunkExtension; 21 | import net.minecraft.world.chunk.WorldChunk; 22 | import org.spongepowered.asm.mixin.Mixin; 23 | import org.spongepowered.asm.mixin.Unique; 24 | 25 | @Mixin(WorldChunk.class) 26 | public class WorldChunkMixin implements WorldChunkExtension { 27 | @Unique 28 | private boolean lambdamap$dirty; 29 | @Unique 30 | private boolean lambdamap$biomeDirty = true; 31 | 32 | @Override 33 | public boolean lambdamap$isDirty() { 34 | return this.lambdamap$dirty; 35 | } 36 | 37 | @Override 38 | public boolean lambdamap$isBiomeDirty() { 39 | return this.lambdamap$biomeDirty; 40 | } 41 | 42 | @Override 43 | public void lambdamap$markDirty() { 44 | this.lambdamap$dirty = true; 45 | } 46 | 47 | @Override 48 | public void lambdamap$markClean() { 49 | this.lambdamap$dirty = false; 50 | this.lambdamap$biomeDirty = false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/ChunkGetterMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map; 19 | 20 | import org.jetbrains.annotations.Nullable; 21 | 22 | /** 23 | * Represents a chunk getter mode. 24 | * 25 | * @author LambdAurora 26 | * @version 1.0.0 27 | * @since 1.0.0 28 | */ 29 | public enum ChunkGetterMode { 30 | /** 31 | * Gets the chunk from memory. 32 | */ 33 | GET(WorldMap::getChunk), 34 | /** 35 | * Gets the chunk from memory, or if absent loads the chunk from disk. 36 | */ 37 | LOAD(WorldMap::getChunkOrLoad), 38 | /** 39 | * Gets or loads the chunk, if absent creates a new empty chunk. 40 | */ 41 | CREATE(WorldMap::getChunkOrCreate); 42 | 43 | private final ChunkFactory factory; 44 | 45 | ChunkGetterMode(ChunkFactory factory) { 46 | this.factory = factory; 47 | } 48 | 49 | public @Nullable MapChunk getChunk(WorldMap map, int x, int z) { 50 | return this.factory.getChunk(map, x, z); 51 | } 52 | 53 | @FunctionalInterface 54 | public interface ChunkFactory { 55 | @Nullable MapChunk getChunk(WorldMap map, int x, int z); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/SimpleTexturedHudDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import net.minecraft.client.gui.GuiGraphics; 21 | import net.minecraft.client.render.VertexConsumerProvider; 22 | import net.minecraft.util.Identifier; 23 | 24 | public class SimpleTexturedHudDecorator extends HudDecorator { 25 | private final int margin; 26 | private final Identifier texture; 27 | private final int bottomHeight; 28 | private final int coordinatesOffset; 29 | 30 | public SimpleTexturedHudDecorator(Identifier id, int margin, Identifier texture, int bottomHeight, int coordinatesOffset) { 31 | super(id); 32 | this.margin = margin; 33 | this.texture = texture; 34 | this.bottomHeight = bottomHeight; 35 | this.coordinatesOffset = coordinatesOffset; 36 | } 37 | 38 | @Override 39 | public int getMargin() { 40 | return this.margin; 41 | } 42 | 43 | @Override 44 | public int getCoordinatesOffset() { 45 | return this.coordinatesOffset; 46 | } 47 | 48 | @Override 49 | public void render(GuiGraphics graphics, VertexConsumerProvider.Immediate immediate, int width, int height) { 50 | graphics.drawTexture(this.texture, 0, 0, width, height + this.bottomHeight, 0, 0, 51 | width, height + this.bottomHeight, width, height + this.bottomHeight); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/assets/lambdamap/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "lambdamap.config.category.general": "General", 3 | "lambdamap.config.render_biome_colors": "Render Biome Colors", 4 | "lambdamap.config.category.hud": "HUD", 5 | "lambdamap.config.hud.visible": "Show HUD", 6 | "lambdamap.config.hud.scale": "Scale", 7 | "lambdamap.config.hud.scale.tooltip": "Scales the HUD map independently from the GUI scale.", 8 | "lambdamap.config.hud.north_lock": "North Lock", 9 | "lambdamap.config.hud.north_lock.tooltip": "Locks the HUD map to always have north on top.", 10 | "lambdamap.config.hud.direction_indicators": "Direction Indicators", 11 | "lambdamap.config.hud.direction_indicators.tooltip": "Sets whether the direction indicators show up in the map HUD.", 12 | "lambdamap.config.hud.decorator": "Style", 13 | "lambdamap.config.hud.decorator.tooltip": "Determines how the HUD map will look.", 14 | 15 | "lambdamap.hud.decorator.none": "None", 16 | "lambdamap.hud.decorator.map": "Map-like", 17 | "lambdamap.hud.decorator.slot": "Slot-like", 18 | 19 | "lambdamap.compass.short.north": "N", 20 | "lambdamap.compass.short.east": "E", 21 | "lambdamap.compass.short.south": "S", 22 | "lambdamap.compass.short.west": "W", 23 | 24 | "key.categories.lambdamap": "LambdaMap", 25 | "lambdamap.keybind.map": "Open World Map", 26 | "lambdamap.keybind.hud": "Toggle Map HUD", 27 | 28 | "lambdamap.marker.new.name": "Marker Name:", 29 | "lambdamap.marker.new.player_pos": "Player Pos", 30 | "lambdamap.marker.new.x": "X:", 31 | "lambdamap.marker.new.z": "Z:", 32 | "lambdamap.marker.confirm_deletion.prompt": "Are you sure you want to %s %s?", 33 | "lambdamap.marker.confirm_deletion.prompt.action": "permanently delete", 34 | "lambdamap.marker.confirm_deletion.prompt.unnamed": "Unnamed Marker", 35 | 36 | "lambdamap.tabs.config": "Config", 37 | "lambdamap.tabs.config.description": "Mod configuration", 38 | "lambdamap.tabs.markers": "Markers", 39 | "lambdamap.tabs.markers.description": "Mark places in your world!", 40 | "lambdamap.tabs.world_map": "World Map", 41 | "lambdamap.tabs.world_map.description": "Explore the world!" 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/ClientPlayerInteractionManagerMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import dev.lambdaurora.lambdamap.map.marker.Marker; 22 | import net.minecraft.client.network.ClientPlayerEntity; 23 | import net.minecraft.client.network.ClientPlayerInteractionManager; 24 | import net.minecraft.client.world.ClientWorld; 25 | import net.minecraft.util.ActionResult; 26 | import net.minecraft.util.Hand; 27 | import net.minecraft.util.hit.BlockHitResult; 28 | import org.spongepowered.asm.mixin.Mixin; 29 | import org.spongepowered.asm.mixin.injection.At; 30 | import org.spongepowered.asm.mixin.injection.Inject; 31 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 32 | 33 | @Mixin(ClientPlayerInteractionManager.class) 34 | public class ClientPlayerInteractionManagerMixin { 35 | @Inject( 36 | method = "method_41934", 37 | at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getStackInHand(Lnet/minecraft/util/Hand;)Lnet/minecraft/item/ItemStack;", ordinal = 0) 38 | ) 39 | private void onInteractBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { 40 | var marker = Marker.fromBanner(player.clientWorld, hitResult.getBlockPos()); 41 | if (marker != null) { 42 | LambdaMap.get().getMap().getMarkerManager().addMarker(marker); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/CompositeTexturedHudDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import net.minecraft.client.gui.GuiGraphics; 21 | import net.minecraft.client.render.VertexConsumerProvider; 22 | import net.minecraft.util.Identifier; 23 | 24 | public class CompositeTexturedHudDecorator extends HudDecorator { 25 | private final int margin; 26 | private final Identifier textureId; 27 | private final Identifier bottomId; 28 | 29 | public CompositeTexturedHudDecorator(Identifier id, int margin, Identifier textureId, Identifier bottomId) { 30 | super(id); 31 | this.margin = margin; 32 | this.textureId = textureId; 33 | this.bottomId = bottomId; 34 | } 35 | 36 | public CompositeTexturedHudDecorator(Identifier id, int margin, Identifier textureId) { 37 | this(id, margin, textureId, textureId); 38 | } 39 | 40 | @Override 41 | public int getMargin() { 42 | return this.margin; 43 | } 44 | 45 | @Override 46 | public void render(GuiGraphics graphics, VertexConsumerProvider.Immediate immediate, int width, int height) { 47 | graphics.drawTexture(this.textureId, 0, 0, width, height - this.margin - 1, 0, 0, 48 | 128, 128 - this.margin - 1, 128, 128); 49 | 50 | int bottomHeight = this.client.textRenderer.fontHeight + 2 + this.margin - 1; 51 | graphics.drawTexture(this.bottomId, 0, height - this.margin - 1, width, bottomHeight, 52 | 0, 128 - bottomHeight, 128, bottomHeight, 128, 128); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/HudDecorator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import net.minecraft.client.MinecraftClient; 22 | import net.minecraft.client.gui.GuiGraphics; 23 | import net.minecraft.client.render.VertexConsumerProvider; 24 | import net.minecraft.text.Text; 25 | import net.minecraft.util.Identifier; 26 | 27 | /** 28 | * Represents a map HUD decorator. 29 | * 30 | * @author LambdAurora 31 | * @version 1.0.0 32 | * @since 1.0.0 33 | */ 34 | public abstract class HudDecorator { 35 | protected final MinecraftClient client = MinecraftClient.getInstance(); 36 | private final Identifier id; 37 | 38 | protected HudDecorator(Identifier id) { 39 | this.id = id; 40 | } 41 | 42 | /** 43 | * {@return the identifier of this map HUD decorator} 44 | */ 45 | public Identifier getId() { 46 | return this.id; 47 | } 48 | 49 | public String getTranslationKey() { 50 | var prefix = "lambdamap.hud.decorator."; 51 | if (!id.getNamespace().equals(LambdaMap.NAMESPACE)) 52 | prefix += id.getNamespace() + '.'; 53 | return prefix + id.getPath().replace('/', '.'); 54 | } 55 | 56 | public Text getName() { 57 | return Text.translatable(this.getTranslationKey()); 58 | } 59 | 60 | public abstract int getMargin(); 61 | 62 | public int getCoordinatesOffset() { 63 | return 0; 64 | } 65 | 66 | public abstract void render(GuiGraphics graphics, VertexConsumerProvider.Immediate immediate, int width, int height); 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/mixin/ClientPlayNetworkHandlerMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.mixin; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import net.minecraft.client.network.ClientPlayNetworkHandler; 22 | import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; 23 | import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket; 24 | import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket; 25 | import org.spongepowered.asm.mixin.Mixin; 26 | import org.spongepowered.asm.mixin.injection.At; 27 | import org.spongepowered.asm.mixin.injection.Inject; 28 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 29 | 30 | @Mixin(ClientPlayNetworkHandler.class) 31 | public class ClientPlayNetworkHandlerMixin { 32 | @Inject(method = "onChunkData", at = @At("RETURN")) 33 | private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo ci) { 34 | LambdaMap.get().onChunkUpdate(packet.chunkX(), packet.chunkZ()); 35 | } 36 | 37 | @Inject(method = "onChunkDeltaUpdate", at = @At("RETURN")) 38 | private void onChunkDeltaUpdate(ChunkDeltaUpdateS2CPacket packet, CallbackInfo ci) { 39 | var accessor = (ChunkDeltaUpdateS2CPacketAccessor) packet; 40 | LambdaMap.get().onChunkUpdate(accessor.getSectionPos().getX(), accessor.getSectionPos().getZ()); 41 | } 42 | 43 | @Inject(method = "onBlockUpdate", at = @At("RETURN")) 44 | private void onBlockUpdate(BlockUpdateS2CPacket packet, CallbackInfo ci) { 45 | LambdaMap.get().onBlockUpdate(packet.getPos().getX(), packet.getPos().getZ()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/HudDecorators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import net.minecraft.util.Identifier; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public final class HudDecorators { 27 | private static final List DECORATORS = new ArrayList<>(); 28 | 29 | public static final HudDecorator NONE = register(new EmptyHudDecorator()); 30 | public static final HudDecorator MAP = register(new CompositeTexturedHudDecorator(LambdaMap.id("map"), 7, 31 | new Identifier("textures/map/map_background_checkerboard.png"), new Identifier("textures/map/map_background.png"))); 32 | public static final HudDecorator SLOT = register(new SimpleTexturedHudDecorator(LambdaMap.id("slot"), 3, 33 | LambdaMap.id("textures/gui/map_hud_slot.png"), 13, 2)); 34 | 35 | public static T register(T decorator) { 36 | DECORATORS.add(decorator); 37 | return decorator; 38 | } 39 | 40 | public static HudDecorator get(Identifier id) { 41 | for (var decorator : DECORATORS) { 42 | if (decorator.getId().equals(id)) 43 | return decorator; 44 | } 45 | 46 | return NONE; 47 | } 48 | 49 | public static HudDecorator pick(HudDecorator current, int amount) { 50 | if (current == null) return DECORATORS.get(0); 51 | 52 | int index = DECORATORS.indexOf(current); 53 | int newIndex = (index + amount) % DECORATORS.size(); 54 | 55 | return DECORATORS.get(newIndex); 56 | } 57 | 58 | private HudDecorators() { 59 | throw new IllegalStateException("HudDecorators only contain static definitions."); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/MarkerTabWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import dev.lambdaurora.lambdamap.map.marker.MarkerManager; 22 | import dev.lambdaurora.spruceui.Position; 23 | import dev.lambdaurora.spruceui.widget.container.SpruceContainerWidget; 24 | 25 | public class MarkerTabWidget extends SpruceContainerWidget { 26 | private final MarkerListWidget list; 27 | private final NewMarkerFormWidget newMarkerFormWidget; 28 | private final ConfirmDeletionWidget confirmDeletionWidget; 29 | 30 | public MarkerTabWidget(LambdaMap mod, Position position, int width, int height) { 31 | super(position, width, height); 32 | 33 | MarkerManager markers = mod.getMap().getMarkerManager(); 34 | 35 | int newMarkerFormHeight = width < 480 ? 80 : 40; 36 | this.list = new MarkerListWidget(this, Position.origin(), width, height - newMarkerFormHeight, markers); 37 | this.newMarkerFormWidget = new NewMarkerFormWidget(Position.of(this, 0, list.getHeight()), width, newMarkerFormHeight, markers, list); 38 | this.confirmDeletionWidget = new ConfirmDeletionWidget(this, Position.origin(), width, height); 39 | 40 | this.addChild(list); 41 | this.addChild(newMarkerFormWidget); 42 | this.addChild(confirmDeletionWidget); 43 | this.switchBack(); 44 | } 45 | 46 | public void promptForDeletion(MarkerListWidget.MarkerEntry entry) { 47 | this.list.setVisible(false); 48 | this.newMarkerFormWidget.setVisible(false); 49 | this.confirmDeletionWidget.setVisible(true); 50 | this.confirmDeletionWidget.setMarkerEntry(entry); 51 | } 52 | 53 | public void switchBack() { 54 | this.list.setVisible(true); 55 | this.newMarkerFormWidget.setVisible(true); 56 | this.confirmDeletionWidget.setVisible(false); 57 | } 58 | 59 | @Override 60 | public void setFocused(boolean focused) { 61 | if(!focused) { 62 | this.switchBack(); 63 | } 64 | super.setFocused(focused); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/ConfirmDeletionWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.vertex.Tessellator; 21 | import dev.lambdaurora.spruceui.Position; 22 | import dev.lambdaurora.spruceui.background.EmptyBackground; 23 | import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; 24 | import dev.lambdaurora.spruceui.widget.container.SpruceContainerWidget; 25 | import net.minecraft.client.gui.GuiGraphics; 26 | import net.minecraft.client.render.VertexConsumerProvider; 27 | import net.minecraft.text.CommonTexts; 28 | import net.minecraft.text.OrderedText; 29 | import net.minecraft.text.Text; 30 | import net.minecraft.util.Formatting; 31 | 32 | public class ConfirmDeletionWidget extends SpruceContainerWidget { 33 | private MarkerListWidget.MarkerEntry markerEntry; 34 | 35 | public ConfirmDeletionWidget(MarkerTabWidget parent, Position position, int width, int height) { 36 | super(position, width, height); 37 | this.setBackground(EmptyBackground.EMPTY_BACKGROUND); 38 | int offset = 5; 39 | int spacing = 10; 40 | 41 | int fixedY = this.getHeight() / 3 * 2 - 10; 42 | int fixedWidth = this.getWidth() / 2 - 2 * spacing; 43 | 44 | SpruceButtonWidget deleteButton = new SpruceButtonWidget(Position.of(this, spacing + offset, fixedY), 45 | fixedWidth, 20, CommonTexts.PROCEED, button -> { 46 | this.markerEntry.parent.removeMarker(markerEntry); 47 | parent.switchBack(); 48 | }); 49 | SpruceButtonWidget cancelButton = new SpruceButtonWidget(Position.of(this, getWidth() / 2 + spacing - offset, fixedY), 50 | fixedWidth, 20, CommonTexts.CANCEL, button -> parent.switchBack()); 51 | 52 | this.addChild(deleteButton); 53 | this.addChild(cancelButton); 54 | } 55 | 56 | @Override 57 | protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 58 | this.forEach(child -> child.render(graphics, mouseX, mouseY, delta)); 59 | 60 | VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBufferBuilder()); 61 | 62 | String name = this.markerEntry.marker.getName() == null ? "" : this.markerEntry.marker.getName().getString(); 63 | OrderedText prompt = Text.translatable("lambdamap.marker.confirm_deletion.prompt", 64 | Text.translatable("lambdamap.marker.confirm_deletion.prompt.action").formatted(Formatting.RED), 65 | name.equals("") ? Text.translatable("lambdamap.marker.confirm_deletion.prompt.unnamed") : name) 66 | .asOrderedText(); 67 | 68 | graphics.drawCenteredShadowedText(this.client.textRenderer, prompt, this.getX() + this.getWidth() / 2, this.getHeight() / 3, 0xffffffff); 69 | 70 | immediate.draw(); 71 | } 72 | 73 | public void setMarkerEntry(MarkerListWidget.MarkerEntry markerEntry) { 74 | this.markerEntry = markerEntry; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/WorldMapScreen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import dev.lambdaurora.spruceui.Position; 22 | import dev.lambdaurora.spruceui.background.EmptyBackground; 23 | import dev.lambdaurora.spruceui.option.SpruceSeparatorOption; 24 | import dev.lambdaurora.spruceui.screen.SpruceScreen; 25 | import dev.lambdaurora.spruceui.widget.container.SpruceOptionListWidget; 26 | import dev.lambdaurora.spruceui.widget.container.tabbed.SpruceTabbedWidget; 27 | import net.minecraft.text.Text; 28 | import net.minecraft.util.Formatting; 29 | 30 | public class WorldMapScreen extends SpruceScreen { 31 | private final LambdaMap mod = LambdaMap.get(); 32 | 33 | public WorldMapScreen() { 34 | super(Text.literal("World Map")); 35 | } 36 | 37 | @Override 38 | public void removed() { 39 | super.removed(); 40 | } 41 | 42 | @Override 43 | protected void init() { 44 | super.init(); 45 | 46 | if (this.mod.getConfig().isWorldMapFullscreen()) { 47 | this.addDrawableChild(new WorldMapWidget(Position.origin(), width, height)); 48 | } else { 49 | SpruceTabbedWidget tabs = this.addDrawableChild(new SpruceTabbedWidget(Position.origin(), this.width, this.height, Text.literal("LambdaMap"))); 50 | tabs.getList().setBackground(RandomPrideFlagBackground.random()); 51 | tabs.addTabEntry(Text.translatable("lambdamap.tabs.world_map"), Text.translatable("lambdamap.tabs.world_map.description").formatted(Formatting.GRAY), 52 | (width, height) -> new WorldMapWidget(Position.origin(), width, height)); 53 | tabs.addTabEntry(Text.translatable("lambdamap.tabs.markers"), Text.translatable("lambdamap.tabs.markers.description").formatted(Formatting.GRAY), 54 | (width, height) -> new MarkerTabWidget(this.mod, Position.origin(), width, height)); 55 | tabs.addTabEntry(Text.translatable("lambdamap.tabs.config"), Text.translatable("lambdamap.tabs.config.description").formatted(Formatting.GRAY), 56 | this::buildConfigTab); 57 | } 58 | } 59 | 60 | private SpruceOptionListWidget buildConfigTab(int width, int height) { 61 | var list = new SpruceOptionListWidget(Position.origin(), width, height); 62 | list.setBackground(EmptyBackground.EMPTY_BACKGROUND); 63 | 64 | list.addSingleOptionEntry(new SpruceSeparatorOption("lambdamap.config.category.general", true, null)); 65 | list.addSingleOptionEntry(this.mod.getConfig().getRenderBiomeColorsOption()); 66 | list.addSingleOptionEntry(new SpruceSeparatorOption("lambdamap.config.category.hud", true, null)); 67 | list.addSingleOptionEntry(this.mod.getConfig().getShowHudOption()); 68 | list.addOptionEntry(this.mod.getConfig().getHudScaleOption(), null); 69 | list.addOptionEntry(this.mod.getConfig().getNorthLockOption(), this.mod.getConfig().getDirectionIndicatorsOption()); 70 | list.addSingleOptionEntry(this.mod.getConfig().getHudDecoratorOption()); 71 | return list; 72 | } 73 | 74 | @Override 75 | public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { 76 | return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/MarkerTypeButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.vertex.Tessellator; 21 | import dev.lambdaurora.lambdamap.LambdaMap; 22 | import dev.lambdaurora.lambdamap.map.marker.MarkerType; 23 | import dev.lambdaurora.spruceui.Position; 24 | import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; 25 | import net.minecraft.client.gui.GuiGraphics; 26 | import net.minecraft.client.render.LightmapTextureManager; 27 | import net.minecraft.client.render.VertexConsumerProvider; 28 | import net.minecraft.text.Text; 29 | import net.minecraft.util.Identifier; 30 | import org.lwjgl.glfw.GLFW; 31 | 32 | import java.util.function.Consumer; 33 | 34 | public class MarkerTypeButton extends SpruceButtonWidget { 35 | private static final Identifier FOCUSED_TEXTURE = LambdaMap.id("textures/gui/icon_selection.png"); 36 | private final Consumer changeListener; 37 | private MarkerType type; 38 | 39 | public MarkerTypeButton(Position position, MarkerType type, Consumer changeListener) { 40 | super(position, 20, 20, Text.empty(), btn -> { 41 | MarkerType next = MarkerType.next(((MarkerTypeButton) btn).type); 42 | ((MarkerTypeButton) btn).type = next; 43 | changeListener.accept(next); 44 | }); 45 | this.changeListener = changeListener; 46 | this.type = type; 47 | } 48 | 49 | @Override 50 | protected boolean onMouseClick(double mouseX, double mouseY, int button) { 51 | if (super.onMouseClick(mouseX, mouseY, button)) { 52 | return true; 53 | } else if (button == GLFW.GLFW_MOUSE_BUTTON_2) { 54 | this.playDownSound(); 55 | MarkerType next = MarkerType.previous(this.type); 56 | this.type = next; 57 | this.changeListener.accept(next); 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | @Override 64 | protected boolean onMouseScroll(double mouseX, double mouseY, double amount) { 65 | this.playDownSound(); 66 | MarkerType next = amount > 0 ? MarkerType.next(this.type) : MarkerType.previous(this.type); 67 | this.type = next; 68 | this.changeListener.accept(next); 69 | return true; 70 | } 71 | 72 | public MarkerType getMarkerType() { 73 | return this.type; 74 | } 75 | 76 | public void setMarkerType(MarkerType type) { 77 | this.type = type; 78 | } 79 | 80 | @Override 81 | protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 82 | graphics.getMatrices().push(); 83 | graphics.getMatrices().translate(this.getX() + 9, this.getY() + 11, 5); 84 | graphics.getMatrices().scale(2, 2, 1); 85 | VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBufferBuilder()); 86 | this.type.render(graphics, immediate, 180.f, null, LightmapTextureManager.pack(15, 15)); 87 | immediate.draw(); 88 | graphics.getMatrices().pop(); 89 | } 90 | 91 | @Override 92 | protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 93 | if (this.isFocused()) { 94 | int width = this.getWidth(); 95 | int height = this.getHeight(); 96 | graphics.drawTexture(FOCUSED_TEXTURE, this.getX(), this.getY(), 0, 0, width, height, width, height); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/util/ClientWorldWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.util; 19 | 20 | import dev.lambdaurora.lambdamap.map.MapChunk; 21 | import dev.lambdaurora.lambdamap.mixin.MapColorAccessor; 22 | import dev.lambdaurora.spruceui.util.ColorUtil; 23 | import net.minecraft.block.BlockState; 24 | import net.minecraft.block.Blocks; 25 | import net.minecraft.block.entity.BlockEntity; 26 | import net.minecraft.client.color.biome.BiomeColorProvider; 27 | import net.minecraft.client.world.ClientWorld; 28 | import net.minecraft.fluid.FluidState; 29 | import net.minecraft.util.math.BlockPos; 30 | import net.minecraft.util.math.Direction; 31 | import net.minecraft.world.BlockRenderView; 32 | import net.minecraft.world.chunk.light.LightingProvider; 33 | import org.jetbrains.annotations.Nullable; 34 | 35 | /** 36 | * Represents a client world wrapper as a {@link BlockRenderView} with a {@link MapChunk} associated to provide biome coloring. 37 | * 38 | * @author LambdAurora 39 | * @version 1.0.0 40 | * @since 1.0.0 41 | */ 42 | public class ClientWorldWrapper implements BlockRenderView { 43 | private final ClientWorld world; 44 | private final MapChunk chunk; 45 | 46 | public ClientWorldWrapper(ClientWorld world, MapChunk chunk) { 47 | this.world = world; 48 | this.chunk = chunk; 49 | } 50 | 51 | @Override 52 | public float getBrightness(Direction direction, boolean shaded) { 53 | return this.world.getBrightness(direction, shaded); 54 | } 55 | 56 | @Override 57 | public LightingProvider getLightingProvider() { 58 | return this.world.getLightingProvider(); 59 | } 60 | 61 | @Override 62 | public int getColor(BlockPos pos, BiomeColorProvider colorResolver) { 63 | if (this.chunk == null || this.chunk.isEmpty()) 64 | return 0; 65 | var biome = this.chunk.getBiome(pos.getX(), pos.getZ()); 66 | if (biome == null) { 67 | int color = this.chunk.getColor(pos.getX(), pos.getZ()) & 255; 68 | return MapColorAccessor.getColors()[color / 4].color; // Give up 69 | } 70 | int color = colorResolver.getColor(biome, pos.getX(), pos.getZ()); 71 | 72 | var state = chunk.getBlockState(pos.getX(), pos.getZ()); 73 | if (state != null && (state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.TALL_GRASS 74 | || state.getBlock() == Blocks.VINE)) { 75 | return ColorUtil.argbMultiply(color, .8f, 0xff); 76 | } 77 | 78 | return color; 79 | } 80 | 81 | @Override 82 | public @Nullable BlockEntity getBlockEntity(BlockPos pos) { 83 | return this.world.getBlockEntity(pos); 84 | } 85 | 86 | @Override 87 | public BlockState getBlockState(BlockPos pos) { 88 | return this.world.getBlockState(pos); 89 | } 90 | 91 | @Override 92 | public FluidState getFluidState(BlockPos pos) { 93 | return this.world.getFluidState(pos); 94 | } 95 | 96 | @Override 97 | public int getBottomSectionCoord() { 98 | return this.world.getBottomSectionCoord(); 99 | } 100 | 101 | @Override 102 | public int getHeight() { 103 | return this.world.getHeight(); 104 | } 105 | 106 | @Override 107 | public int getBottomY() { 108 | return this.world.getBottomY(); 109 | } 110 | 111 | @Override 112 | public int countVerticalSections() { 113 | return this.world.countVerticalSections(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/BlockSearcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap; 19 | 20 | import net.minecraft.block.BlockState; 21 | import net.minecraft.block.Blocks; 22 | import net.minecraft.block.MapColor; 23 | import net.minecraft.util.math.BlockPos; 24 | import net.minecraft.util.math.Direction; 25 | import net.minecraft.world.Heightmap; 26 | import net.minecraft.world.World; 27 | import net.minecraft.world.chunk.Chunk; 28 | 29 | /** 30 | * Represents the block searcher. 31 | * 32 | * @author comp500 33 | */ 34 | public class BlockSearcher { 35 | private final World world; 36 | public final BlockPos.Mutable pos = new BlockPos.Mutable(); 37 | private final BlockPos.Mutable depthTestPos = new BlockPos.Mutable(); 38 | private BlockState state; 39 | private int height; 40 | private int waterDepth; 41 | 42 | public BlockSearcher(World world) { 43 | this.world = world; 44 | } 45 | 46 | public BlockState getState() { 47 | return this.state; 48 | } 49 | 50 | public int getHeight() { 51 | return this.height; 52 | } 53 | 54 | public int getWaterDepth() { 55 | return this.waterDepth; 56 | } 57 | 58 | public void searchForBlock(Chunk chunk, Heightmap surfaceHeightmap, int x, int z, int chunkStartX, int chunkStartZ) { 59 | this.height = surfaceHeightmap.get(x & 15, z & 15); 60 | this.pos.set(chunkStartX + x, this.height, chunkStartZ + z); 61 | int minimumY = this.world.getBottomY(); 62 | if (this.height <= minimumY + 1) { 63 | this.state = Blocks.AIR.getDefaultState(); 64 | } else { 65 | do { 66 | this.pos.setY(--this.height); 67 | this.state = chunk.getBlockState(this.pos); 68 | } while (this.state.getMapColor(this.world, this.pos) == MapColor.NONE && this.height > minimumY); 69 | } 70 | } 71 | 72 | public void calcWaterDepth(Chunk chunk) { 73 | int heightTemp = this.height - 1; 74 | this.waterDepth = 0; 75 | this.depthTestPos.set(this.pos); 76 | 77 | BlockState depthTestBlock; 78 | do { 79 | this.depthTestPos.setY(heightTemp--); 80 | depthTestBlock = chunk.getBlockState(depthTestPos); 81 | ++this.waterDepth; 82 | } while (heightTemp > 0 && !depthTestBlock.getFluidState().isEmpty()); 83 | 84 | this.state = this.getFluidStateIfVisible(this.world, this.state, this.depthTestPos); 85 | } 86 | 87 | public void searchForBlockCeil(Chunk chunk, int x, int z, int chunkStartX, int chunkStartZ) { 88 | this.height = 85; 89 | boolean brokeThroughCeil = false; 90 | this.pos.set(chunkStartX + x, this.height, chunkStartZ + z); 91 | var firstBlockState = chunk.getBlockState(this.pos); 92 | this.state = firstBlockState; 93 | if (this.state.isAir()) { 94 | brokeThroughCeil = true; 95 | } 96 | while ((!brokeThroughCeil || this.state.getMapColor(this.world, this.pos) == MapColor.NONE) 97 | && this.height > this.world.getBottomSectionCoord()) { 98 | this.pos.setY(--this.height); 99 | this.state = chunk.getBlockState(this.pos); 100 | if (this.state.isAir()) { 101 | brokeThroughCeil = true; 102 | } 103 | } 104 | if (!brokeThroughCeil) { 105 | this.state = firstBlockState; 106 | this.height = 85; 107 | this.pos.setY(this.height); 108 | } 109 | } 110 | 111 | private BlockState getFluidStateIfVisible(World world, BlockState state, BlockPos pos) { 112 | var fluidState = state.getFluidState(); 113 | return !fluidState.isEmpty() && !state.isSideSolidFullSquare(world, pos, Direction.UP) ? fluidState.getBlockState() : state; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/RandomPrideFlagBackground.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.systems.RenderSystem; 21 | import com.mojang.blaze3d.vertex.Tessellator; 22 | import com.mojang.blaze3d.vertex.VertexFormat; 23 | import com.mojang.blaze3d.vertex.VertexFormats; 24 | import dev.lambdaurora.spruceui.background.Background; 25 | import dev.lambdaurora.spruceui.background.SimpleColorBackground; 26 | import dev.lambdaurora.spruceui.util.ColorUtil; 27 | import dev.lambdaurora.spruceui.widget.SpruceWidget; 28 | import io.github.queerbric.pride.PrideFlag; 29 | import io.github.queerbric.pride.PrideFlagShapes; 30 | import io.github.queerbric.pride.PrideFlags; 31 | import net.minecraft.client.gui.GuiGraphics; 32 | import net.minecraft.client.render.GameRenderer; 33 | import net.minecraft.util.Identifier; 34 | 35 | import java.util.Random; 36 | 37 | /** 38 | * Displays a pride flag. 39 | *

40 | * If you have an issue with this, I don't care. 41 | * 42 | * @author LambdAurora 43 | * @version 1.0.0 44 | * @since 1.0.0 45 | */ 46 | public class RandomPrideFlagBackground implements Background { 47 | private static final Background SECOND_LAYER = new SimpleColorBackground(0xe0101010); 48 | private static final Random RANDOM = new Random(); 49 | 50 | private final PrideFlag flag; 51 | 52 | public RandomPrideFlagBackground(PrideFlag flag) { 53 | this.flag = flag; 54 | } 55 | 56 | @Override 57 | public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) { 58 | int x = widget.getX(); 59 | int y = widget.getY(); 60 | 61 | RenderSystem.setShader(GameRenderer::getPositionColorShader); 62 | if (this.flag.getShape() == PrideFlagShapes.get(new Identifier("pride", "horizontal_stripes"))) { 63 | var model = graphics.getMatrices().peek().getModel(); 64 | var tessellator = Tessellator.getInstance(); 65 | var vertices = tessellator.getBufferBuilder(); 66 | vertices.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR); 67 | 68 | int width = widget.getWidth(); 69 | int height = widget.getHeight(); 70 | 71 | float partHeight = height / (this.flag.getColors().size() - 1.f); 72 | 73 | // First one 74 | float rightY = y; 75 | float leftY = y; 76 | 77 | int[] color = ColorUtil.unpackARGBColor(this.flag.getColors().getInt(0)); 78 | vertices.vertex(model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next(); 79 | vertices.vertex(model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next(); 80 | vertices.vertex(model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next(); 81 | 82 | rightY += partHeight; 83 | 84 | for (int i = 1; i < this.flag.getColors().size() - 1; i++) { 85 | color = ColorUtil.unpackARGBColor(this.flag.getColors().getInt(i)); 86 | 87 | vertices.vertex(model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next(); 88 | vertices.vertex(model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next(); 89 | vertices.vertex(model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next(); 90 | 91 | vertices.vertex(model, x + width, rightY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next(); 92 | vertices.vertex(model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next(); 93 | vertices.vertex(model, x, leftY + partHeight, 0).color(color[0], color[1], color[2], color[3]).next(); 94 | 95 | rightY += partHeight; 96 | leftY += partHeight; 97 | } 98 | 99 | // Last one 100 | color = ColorUtil.unpackARGBColor(this.flag.getColors().getInt(this.flag.getColors().size() - 1)); 101 | vertices.vertex(model, x + width, rightY, 0).color(color[0], color[1], color[2], color[3]).next(); 102 | vertices.vertex(model, x, leftY, 0).color(color[0], color[1], color[2], color[3]).next(); 103 | vertices.vertex(model, x, y + height, 0).color(color[0], color[1], color[2], color[3]).next(); 104 | 105 | tessellator.draw(); 106 | } else { 107 | this.flag.render(graphics.getMatrices(), x, y, widget.getWidth(), widget.getHeight()); 108 | } 109 | 110 | SECOND_LAYER.render(graphics, widget, vOffset, mouseX, mouseY, delta); 111 | } 112 | 113 | /** 114 | * Returns a random pride flag as background. 115 | * 116 | * @return the background 117 | */ 118 | public static Background random() { 119 | return new RandomPrideFlagBackground(PrideFlags.getRandomFlag(RANDOM)); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/NewMarkerFormWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import dev.lambdaurora.lambdamap.map.marker.MarkerManager; 21 | import dev.lambdaurora.lambdamap.map.marker.MarkerSource; 22 | import dev.lambdaurora.lambdamap.map.marker.MarkerType; 23 | import dev.lambdaurora.spruceui.Position; 24 | import dev.lambdaurora.spruceui.SpruceTexts; 25 | import dev.lambdaurora.spruceui.background.SimpleColorBackground; 26 | import dev.lambdaurora.spruceui.util.SpruceUtil; 27 | import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; 28 | import dev.lambdaurora.spruceui.widget.container.SpruceContainerWidget; 29 | import dev.lambdaurora.spruceui.widget.text.SpruceNamedTextFieldWidget; 30 | import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; 31 | import net.minecraft.item.map.MapIcon; 32 | import net.minecraft.text.OrderedText; 33 | import net.minecraft.text.Style; 34 | import net.minecraft.text.Text; 35 | import net.minecraft.util.Formatting; 36 | import net.minecraft.util.math.BlockPos; 37 | 38 | public class NewMarkerFormWidget extends SpruceContainerWidget { 39 | private final MarkerTypeButton typeButton; 40 | private final SpruceNamedTextFieldWidget nameField; 41 | private final SpruceNamedTextFieldWidget xFieldWidget; 42 | private final SpruceNamedTextFieldWidget zFieldWidget; 43 | private SpruceButtonWidget doneButton; 44 | 45 | public NewMarkerFormWidget(Position position, int width, int height, MarkerManager markers, MarkerListWidget list) { 46 | super(position, width, height); 47 | 48 | this.setBackground(new SimpleColorBackground(0xe00a0a0a)); 49 | 50 | int x = 7; 51 | int y = 3; 52 | this.typeButton = new MarkerTypeButton(Position.of(this, x, y + 13), MarkerType.getVanillaMarkerType(MapIcon.Type.TARGET_POINT), type -> { 53 | this.doneButton.setActive(true); 54 | }); 55 | this.addChild(typeButton); 56 | 57 | x += this.typeButton.getWidth() + 6; 58 | 59 | this.nameField = new SpruceNamedTextFieldWidget(new SpruceTextFieldWidget(Position.of(this, x, y), 60 | width < 480 ? width - 48 : width / 2 - 48, 61 | 20, Text.translatable("lambdamap.marker.new.name"))); 62 | this.nameField.setChangedListener(input -> this.doneButton.setActive(true)); 63 | this.addChild(nameField); 64 | 65 | if (width < 480) { 66 | x = 6; 67 | y += this.nameField.getHeight() + 4; 68 | } else { 69 | x = width / 2; 70 | } 71 | 72 | this.xFieldWidget = new SpruceNamedTextFieldWidget(new SpruceTextFieldWidget( 73 | Position.of(this, x, y), 74 | width < 480 ? 64 : 48, 20, 75 | Text.translatable("lambdamap.marker.new.x"))); 76 | this.xFieldWidget.setChangedListener(input -> this.doneButton.setActive(true)); 77 | this.setupCoordinatesField(this.xFieldWidget); 78 | this.addChild(xFieldWidget); 79 | 80 | this.zFieldWidget = new SpruceNamedTextFieldWidget(new SpruceTextFieldWidget( 81 | Position.of(this, x += this.xFieldWidget.getWidth() + 4, y), 82 | width < 480 ? 64 : 48, 20, 83 | Text.translatable("lambdamap.marker.new.z"))); 84 | this.zFieldWidget.setChangedListener(input -> this.doneButton.setActive(true)); 85 | this.setupCoordinatesField(this.zFieldWidget); 86 | this.addChild(this.zFieldWidget); 87 | 88 | this.addChild(new SpruceButtonWidget(Position.of(this, x + this.zFieldWidget.getWidth() + 4, y + 13), 89 | 80, 20, Text.translatable("lambdamap.marker.new.player_pos"), btn -> { 90 | BlockPos pos = this.client.player.getBlockPos(); 91 | this.xFieldWidget.setText(String.valueOf(pos.getX())); 92 | this.zFieldWidget.setText(String.valueOf(pos.getZ())); 93 | })); 94 | 95 | this.doneButton = new SpruceButtonWidget(Position.of(this, width - 52, y + 13), 96 | 50, 20, SpruceTexts.GUI_DONE, btn -> { 97 | String text = this.nameField.getText(); 98 | markers.addMarker(this.typeButton.getMarkerType(), MarkerSource.USER, 99 | parseInt(this.xFieldWidget), 0, parseInt(this.zFieldWidget), 100 | 180.f, text.isEmpty() ? null : Text.literal(text)); 101 | list.rebuildList(); 102 | this.init(); 103 | }); 104 | this.addChild(this.doneButton); 105 | 106 | this.init(); 107 | } 108 | 109 | private void init() { 110 | this.typeButton.setMarkerType(MarkerType.getVanillaMarkerType(MapIcon.Type.TARGET_POINT)); 111 | this.nameField.setText(""); 112 | this.xFieldWidget.setText("0"); 113 | this.zFieldWidget.setText("0"); 114 | 115 | this.doneButton.setActive(false); 116 | } 117 | 118 | private int parseInt(SpruceNamedTextFieldWidget textFieldWidget) { 119 | return SpruceUtil.parseIntFromString(textFieldWidget.getText()); 120 | } 121 | 122 | private void setupCoordinatesField(SpruceNamedTextFieldWidget textField) { 123 | textField.setTextPredicate(SpruceTextFieldWidget.INTEGER_INPUT_PREDICATE); 124 | textField.setRenderTextProvider((displayedText, offset) -> { 125 | try { 126 | Integer.parseInt(textField.getText()); 127 | return OrderedText.forward(displayedText, Style.EMPTY); 128 | } catch (NumberFormatException e) { 129 | return OrderedText.forward(displayedText, Style.EMPTY.withColor(Formatting.RED)); 130 | } 131 | }); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/marker/MarkerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map.marker; 19 | 20 | import com.electronwill.nightconfig.core.Config; 21 | import com.electronwill.nightconfig.core.InMemoryCommentedFormat; 22 | import com.electronwill.nightconfig.core.file.FileConfig; 23 | import dev.lambdaurora.lambdamap.map.WorldMap; 24 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 25 | import net.fabricmc.fabric.api.util.NbtType; 26 | import net.minecraft.client.MinecraftClient; 27 | import net.minecraft.item.FilledMapItem; 28 | import net.minecraft.item.ItemStack; 29 | import net.minecraft.item.Items; 30 | import net.minecraft.item.map.MapIcon; 31 | import net.minecraft.item.map.MapState; 32 | import net.minecraft.nbt.NbtCompound; 33 | import net.minecraft.nbt.NbtIo; 34 | import net.minecraft.nbt.NbtList; 35 | import net.minecraft.text.Text; 36 | import net.minecraft.util.math.BlockPos; 37 | import net.minecraft.world.World; 38 | import net.minecraft.world.chunk.Chunk; 39 | import net.minecraft.world.chunk.ChunkStatus; 40 | import org.apache.logging.log4j.LogManager; 41 | import org.apache.logging.log4j.Logger; 42 | import org.jetbrains.annotations.Nullable; 43 | 44 | import java.io.File; 45 | import java.io.IOException; 46 | import java.util.ArrayList; 47 | import java.util.Iterator; 48 | import java.util.List; 49 | import java.util.function.Consumer; 50 | import java.util.stream.Collectors; 51 | 52 | /** 53 | * Manages the markers of a world map. 54 | * 55 | * @author LambdAurora 56 | * @version 1.0.0 57 | * @since 1.0.0 58 | */ 59 | public class MarkerManager implements Iterable { 60 | private static final Logger LOGGER = LogManager.getLogger(); 61 | 62 | private final List markers = new ArrayList<>(); 63 | private final WorldMap map; 64 | private final File file; 65 | private final FileConfig config; 66 | 67 | private ItemStack lastFilledMapStack; 68 | 69 | public MarkerManager(WorldMap map) { 70 | this.map = map; 71 | this.file = new File(this.map.getDirectory(), "markers.toml"); 72 | this.config = FileConfig.builder(this.file).autosave().build(); 73 | } 74 | 75 | public Marker addMarker(MarkerType type, MarkerSource source, int x, int y, int z, float rotation, @Nullable Text text) { 76 | Marker marker = new Marker(type, source, x, y, z, rotation, text); 77 | this.addMarker(marker); 78 | 79 | this.save(); 80 | return marker; 81 | } 82 | 83 | public void addMarker(Marker marker) { 84 | for (Marker o : this) { 85 | if (o.isAt(marker)) { 86 | o.merge(marker); 87 | return; 88 | } 89 | } 90 | 91 | this.markers.add(marker); 92 | } 93 | 94 | public void removeMarkersAt(BlockPos pos) { 95 | this.markers.removeIf(other -> pos.getX() == other.getX() && pos.getY() == other.getY() && pos.getZ() == other.getZ()); 96 | } 97 | 98 | public void removeMarker(Marker marker) { 99 | this.markers.remove(marker); 100 | } 101 | 102 | @Override 103 | public Iterator iterator() { 104 | return this.markers.iterator(); 105 | } 106 | 107 | public void forEachInBox(int minX, int minZ, int sizeX, int sizeZ, Consumer consumer) { 108 | int maxX = minX + sizeX; 109 | int maxZ = minZ + sizeZ; 110 | for (Marker marker : this.markers) { 111 | if (marker.isIn(minX, minZ, maxX, maxZ)) 112 | consumer.accept(marker); 113 | } 114 | } 115 | 116 | public void tick(World world) { 117 | // Check for existence of the banner markers in the world if possible. 118 | Iterator it = this.markers.iterator(); 119 | while (it.hasNext()) { 120 | Marker marker = it.next(); 121 | if (marker.getSource() != MarkerSource.BANNER) 122 | continue; 123 | Chunk chunk = world.getChunk(marker.getChunkX(), marker.getChunkZ(), ChunkStatus.FULL, false); 124 | if (chunk == null) 125 | continue; 126 | Marker bannerMarker = Marker.fromBanner(world, marker.getPos()); 127 | if (bannerMarker == null) 128 | it.remove(); 129 | } 130 | 131 | MinecraftClient client = MinecraftClient.getInstance(); 132 | 133 | // Filled map stuff 134 | // 1. Try to import the markers of the filled map. 135 | // 2. Try to import the colors of the filled map if it has absolute coordinates markers. 136 | ItemStack stack = client.player.getMainHandStack(); 137 | if (!stack.isEmpty() && stack.isOf(Items.FILLED_MAP) && stack.hasNbt() && stack != this.lastFilledMapStack) { 138 | NbtCompound nbt = stack.getNbt(); 139 | var mapMarkers = new ArrayList(); 140 | nbt.getList("Decorations", NbtType.COMPOUND).stream().map(decoration -> ((NbtCompound) decoration)).forEach(decoration -> { 141 | var type = MapIcon.Type.byId(decoration.getByte("type")); 142 | if (type.isAlwaysRendered()) { 143 | mapMarkers.add(this.addMarker(MarkerType.getVanillaMarkerType(type), MarkerSource.FILLED_MAP, 144 | (int) decoration.getDouble("x"), 64, (int) decoration.getDouble("z"), 145 | decoration.getFloat("rot"), null)); 146 | } 147 | }); 148 | 149 | if (!mapMarkers.isEmpty()) { 150 | Integer mapId = FilledMapItem.getMapId(stack); 151 | if (mapId != null) { 152 | MapState mapState = FilledMapItem.getMapState(mapId, world); 153 | if (mapState != null) { 154 | this.map.importMapState(mapState, mapMarkers); 155 | } 156 | } 157 | } 158 | this.lastFilledMapStack = stack; 159 | } 160 | } 161 | 162 | public void load() { 163 | if (!this.file.exists()) { 164 | var nbtFile = new File(this.file.getParentFile(), this.file.getName().replace(".toml", ".nbt")); 165 | if (nbtFile.exists()) { 166 | try { 167 | this.readNbt(NbtIo.readCompressed(nbtFile)); 168 | return; 169 | } catch (IOException e) { 170 | LOGGER.error("Failed to read markers from " + nbtFile + ".", e); 171 | } 172 | } 173 | } 174 | 175 | this.config.load(); 176 | 177 | this.markers.clear(); 178 | List markers = this.config.getOrElse("markers", ArrayList::new); 179 | markers.forEach(config -> this.markers.add(Marker.fromConfig(config))); 180 | } 181 | 182 | public void save() { 183 | /*try { 184 | NbtIo.writeCompressed(this.toNbt(), this.file); 185 | } catch (IOException e) { 186 | LOGGER.error("Failed to save markers to " + this.file + ".", e); 187 | }*/ 188 | 189 | List markers = new ArrayList<>(); 190 | this.markers.forEach(marker -> markers.add( 191 | marker.writeTo(InMemoryCommentedFormat.defaultInstance().createConfig(Object2ObjectOpenHashMap::new)) 192 | )); 193 | 194 | this.config.set("markers", markers); 195 | } 196 | 197 | public void readNbt(NbtCompound nbt) { 198 | this.markers.clear(); 199 | 200 | NbtList list = nbt.getList("markers", NbtType.COMPOUND); 201 | list.forEach(child -> this.markers.add(Marker.fromNbt((NbtCompound) child))); 202 | } 203 | 204 | public NbtCompound toNbt() { 205 | NbtCompound nbt = new NbtCompound(); 206 | nbt.put("markers", this.markers.stream().map(Marker::toNbt).collect(Collectors.toCollection(NbtList::new))); 207 | return nbt; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/marker/MarkerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map.marker; 19 | 20 | import com.mojang.blaze3d.vertex.VertexConsumer; 21 | import dev.lambdaurora.lambdamap.LambdaMap; 22 | import dev.lambdaurora.lambdamap.gui.WorldMapRenderer; 23 | import it.unimi.dsi.fastutil.objects.Object2ObjectMap; 24 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 25 | import net.fabricmc.api.EnvType; 26 | import net.fabricmc.api.Environment; 27 | import net.minecraft.client.MinecraftClient; 28 | import net.minecraft.client.font.TextRenderer; 29 | import net.minecraft.client.gui.GuiGraphics; 30 | import net.minecraft.client.render.RenderLayer; 31 | import net.minecraft.client.render.VertexConsumerProvider; 32 | import net.minecraft.item.map.MapIcon; 33 | import net.minecraft.text.Text; 34 | import net.minecraft.util.Identifier; 35 | import net.minecraft.util.math.Axis; 36 | import net.minecraft.util.math.MathHelper; 37 | import org.jetbrains.annotations.Nullable; 38 | import org.joml.Matrix4f; 39 | 40 | import java.util.ArrayList; 41 | import java.util.List; 42 | import java.util.Locale; 43 | 44 | /** 45 | * Represents a marker type. 46 | * 47 | * @author LambdAurora 48 | * @version 1.0.0 49 | * @since 1.0.0 50 | */ 51 | public class MarkerType { 52 | private static final Object2ObjectMap TYPES_MAP = new Object2ObjectOpenHashMap<>(); 53 | private static final List TYPES = new ArrayList<>(); 54 | 55 | public static final MarkerType PLAYER = registerVanilla(MapIcon.Type.PLAYER); 56 | public static final MarkerType TARGET_POINT = registerVanilla(MapIcon.Type.TARGET_POINT); 57 | 58 | private final String id; 59 | private final RenderLayer renderLayer; 60 | private final float uMin; 61 | private final float vMin; 62 | private final float uMax; 63 | private final float vMax; 64 | private final boolean player; 65 | 66 | MarkerType(String id, RenderLayer renderLayer, float uMin, float vMin, float uMax, float vMax, boolean player) { 67 | this.id = id; 68 | this.renderLayer = renderLayer; 69 | this.uMin = uMin; 70 | this.vMin = vMin; 71 | this.uMax = uMax; 72 | this.vMax = vMax; 73 | this.player = player; 74 | 75 | if (!TYPES_MAP.containsKey(this.id)) { 76 | TYPES.add(this); 77 | TYPES_MAP.put(this.id, this); 78 | } 79 | } 80 | 81 | public String getId() { 82 | return this.id; 83 | } 84 | 85 | @Environment(EnvType.CLIENT) 86 | public void render(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, float rotation, @Nullable Text text, int light) { 87 | graphics.getMatrices().push(); 88 | graphics.getMatrices().multiply(Axis.Z_POSITIVE.rotationDegrees(rotation)); 89 | graphics.getMatrices().scale(4.f, 4.f, 3.f); 90 | graphics.getMatrices().translate(-0.125, 0.125, 0.0); 91 | VertexConsumer vertices = vertexConsumers.getBuffer(this.renderLayer); 92 | Matrix4f model = graphics.getMatrices().peek().getModel(); 93 | WorldMapRenderer.vertex(vertices, model, -1.f, 1.f, this.uMin, this.vMin, light); 94 | WorldMapRenderer.vertex(vertices, model, 1.f, 1.f, this.uMax, this.vMin, light); 95 | WorldMapRenderer.vertex(vertices, model, 1.f, -1.f, this.uMax, this.vMax, light); 96 | WorldMapRenderer.vertex(vertices, model, -1.f, -1.f, this.uMin, this.vMax, light); 97 | graphics.getMatrices().pop(); 98 | 99 | if (text != null) { 100 | TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; 101 | float textWidth = textRenderer.getWidth(text); 102 | float scale = MathHelper.clamp(48.f / textWidth, 0.f, 6.f / 9.f); 103 | graphics.getMatrices().push(); 104 | graphics.getMatrices().translate(-textWidth * scale / 2.0f, 4.f, 0.02500000037252903D); 105 | graphics.getMatrices().scale(scale, scale, -1.f); 106 | graphics.getMatrices().translate(0.f, 0.f, 0.10000000149011612D); 107 | 108 | model = graphics.getMatrices().peek().getModel(); 109 | textRenderer.draw(text, 0.f, 0.f, 0xffffffff, false, model, vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0xaa000000, light); 110 | graphics.getMatrices().pop(); 111 | } 112 | } 113 | 114 | @Override 115 | public String toString() { 116 | return "MarkerType{" + 117 | "key='" + this.id + '\'' + 118 | ", renderLayer=" + this.renderLayer + 119 | ", uMin=" + this.uMin + 120 | ", vMin=" + this.vMin + 121 | ", uMax=" + this.uMax + 122 | ", vMax=" + this.vMax + 123 | '}'; 124 | } 125 | 126 | public static @Nullable MarkerType getMarkerType(String key) { 127 | return TYPES_MAP.getOrDefault(key, TARGET_POINT); 128 | } 129 | 130 | public static MarkerType getVanillaMarkerType(MapIcon.Type type) { 131 | return TYPES_MAP.getOrDefault(type.name().toLowerCase(Locale.ROOT), TARGET_POINT); 132 | } 133 | 134 | public static MarkerType register(String key, Identifier texture, float u, float v) { 135 | return register(key, texture, u, v, u + 0.0625f, v + 0.0625f); 136 | } 137 | 138 | public static MarkerType register(String key, Identifier texture, float uMin, float vMin, float uMax, float vMax) { 139 | return new MarkerType(key, RenderLayer.getText(texture), uMin, vMin, uMax, vMax, false); 140 | } 141 | 142 | public static MarkerType next(MarkerType current) { 143 | MarkerType next; 144 | 145 | int nextIndex = nextIndex(TYPES.indexOf(current)); 146 | 147 | next = TYPES.get(nextIndex); 148 | while (next.player) { 149 | nextIndex = nextIndex(nextIndex); 150 | next = TYPES.get(nextIndex); 151 | } 152 | 153 | return next; 154 | } 155 | 156 | private static int nextIndex(int i) { 157 | if (i + 1 >= TYPES.size()) 158 | return 0; 159 | else 160 | return i + 1; 161 | } 162 | 163 | public static MarkerType previous(MarkerType current) { 164 | MarkerType next; 165 | 166 | int nextIndex = previousIndex(TYPES.indexOf(current)); 167 | 168 | next = TYPES.get(nextIndex); 169 | while (next.player) { 170 | nextIndex = previousIndex(nextIndex); 171 | next = TYPES.get(nextIndex); 172 | } 173 | 174 | return next; 175 | } 176 | 177 | private static int previousIndex(int i) { 178 | if (i - 1 < 0) 179 | return TYPES.size() - 1; 180 | else 181 | return i - 1; 182 | } 183 | 184 | private static MarkerType registerVanilla(MapIcon.Type type) { 185 | byte id = type.getId(); 186 | float uMin = (id % 16) / 16.f; 187 | float vMin = (id / 16) / 16.f; 188 | return new MarkerType(type.name().toLowerCase(Locale.ROOT), LambdaMap.MAP_ICONS, 189 | uMin, vMin, uMin + 0.0625f, vMin + 0.0625f, 190 | !type.isAlwaysRendered() || type == MapIcon.Type.FRAME); 191 | } 192 | 193 | static { 194 | for (var type : MapIcon.Type.values()) { 195 | if (type != MapIcon.Type.TARGET_POINT) 196 | registerVanilla(type); 197 | } 198 | 199 | var texture = LambdaMap.id("textures/markers/doctor4t.png"); 200 | register("creeper", texture, 0.f, 0.f, 1.f / 5.f, 1.f); 201 | register("blaze", texture, 1.f / 5.f, 0.f, 2.f / 5.f, 1.f); 202 | register("witch", texture, 2.f / 5.f, 0.f, 3.f / 5.f, 1.f); 203 | register("village", texture, 3.f / 5.f, 0.f, 4.f / 5.f, 1.f); 204 | register("endcity", texture, 4.f / 5.f, 0.f, 1.f, 1.f); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/WorldMapWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.vertex.Tessellator; 21 | import dev.lambdaurora.lambdamap.LambdaMap; 22 | import dev.lambdaurora.lambdamap.map.MapChunk; 23 | import dev.lambdaurora.spruceui.Position; 24 | import dev.lambdaurora.spruceui.navigation.NavigationDirection; 25 | import dev.lambdaurora.spruceui.util.ScissorManager; 26 | import dev.lambdaurora.spruceui.widget.AbstractSpruceWidget; 27 | import net.minecraft.client.gui.GuiGraphics; 28 | import net.minecraft.client.gui.screen.Screen; 29 | import net.minecraft.client.render.VertexConsumerProvider; 30 | import net.minecraft.util.math.MathHelper; 31 | import org.lwjgl.glfw.GLFW; 32 | 33 | public class WorldMapWidget extends AbstractSpruceWidget { 34 | private final LambdaMap mod = LambdaMap.get(); 35 | private final WorldMapRenderer renderer = this.mod.getRenderer(); 36 | private int intScale = 0; 37 | private float scale = 1.f; 38 | 39 | public WorldMapWidget(Position position, int width, int height) { 40 | super(position); 41 | this.width = width; 42 | this.height = height; 43 | 44 | this.renderer.allocate(this.getWidth(), this.getHeight() - 10); 45 | this.renderer.setWorldMap(this.mod.getMap()); 46 | } 47 | 48 | private void rescale(int amount) { 49 | this.intScale = MathHelper.clamp(this.intScale + amount, -4, 3); 50 | 51 | this.applyScale(); 52 | } 53 | 54 | private void applyScale() { 55 | float oldScale = this.scale; 56 | if (this.intScale < 0) 57 | this.scale = -this.intScale; 58 | else 59 | this.scale = 1.f; 60 | 61 | if (oldScale != this.scale) { 62 | float scaleCompensation = 1.f / this.scale; 63 | this.renderer.allocate((int) (this.getWidth() * scaleCompensation), (int) ((this.getHeight() - 10) * scaleCompensation)); 64 | } 65 | 66 | this.renderer.scale(Math.max(0, this.intScale)); 67 | } 68 | 69 | /* Navigation */ 70 | 71 | @Override 72 | public boolean onNavigation(NavigationDirection direction, boolean tab) { 73 | if (!tab) { 74 | double viewX = this.mod.getMap().getViewX(); 75 | double viewZ = this.mod.getMap().getViewZ(); 76 | double multiplier = Screen.hasShiftDown() ? 10 : 1; 77 | switch (direction) { 78 | case LEFT -> this.renderer.updateView(viewX - multiplier, viewZ); 79 | case RIGHT -> this.renderer.updateView(viewX + multiplier, viewZ); 80 | case UP -> this.renderer.updateView(viewX, viewZ - multiplier); 81 | case DOWN -> this.renderer.updateView(viewX, viewZ + multiplier); 82 | } 83 | return true; 84 | } 85 | return super.onNavigation(direction, tab); 86 | } 87 | 88 | /* Input */ 89 | 90 | @Override 91 | protected boolean onMouseClick(double mouseX, double mouseY, int button) { 92 | double mouseXOffset = mouseX - this.getX(); 93 | double mouseYOffset = mouseY - this.getY(); 94 | 95 | if (mouseXOffset > 0 && mouseXOffset < this.renderer.width() * this.scale && mouseYOffset > this.renderer.height() * this.scale) { 96 | this.mod.getConfig().setWorldMapFullscreen(!this.mod.getConfig().isWorldMapFullscreen()); 97 | this.client.setScreen(new WorldMapScreen()); 98 | } 99 | 100 | return button == GLFW.GLFW_MOUSE_BUTTON_1; 101 | } 102 | 103 | @Override 104 | protected boolean onMouseDrag(double mouseX, double mouseY, int button, double deltaX, double deltaY) { 105 | if (button == GLFW.GLFW_MOUSE_BUTTON_1) { 106 | double viewX = this.mod.getMap().getViewX(); 107 | double viewZ = this.mod.getMap().getViewZ(); 108 | double scaleCompensation = 1d / this.scale; 109 | if (this.renderer.scale() != 1) { 110 | scaleCompensation = this.renderer.scale(); 111 | } 112 | this.renderer.updateView(viewX - deltaX * scaleCompensation, viewZ - deltaY * scaleCompensation); 113 | return true; 114 | } 115 | return super.onMouseDrag(mouseX, mouseY, button, deltaX, deltaY); 116 | } 117 | 118 | @Override 119 | protected boolean onMouseScroll(double mouseX, double mouseY, double amount) { 120 | this.rescale((int) -amount); 121 | return true; 122 | } 123 | 124 | /* Rendering */ 125 | 126 | @Override 127 | protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 128 | ScissorManager.push(this.getX(), this.getY(), this.getWidth(), this.getHeight() - 10); 129 | graphics.getMatrices().push(); 130 | graphics.getMatrices().translate(this.getX(), this.getY(), 0); 131 | graphics.getMatrices().scale(this.scale, this.scale, 1.f); 132 | var immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBufferBuilder()); 133 | this.renderer.render(graphics, immediate, delta); 134 | immediate.draw(); 135 | graphics.getMatrices().pop(); 136 | ScissorManager.pop(); 137 | 138 | int mouseXOffset = mouseX - this.getX(); 139 | int mouseYOffset = mouseY - this.getY(); 140 | float scaleCompensation = 1.f / this.scale; 141 | if (this.renderer.scale() != 1) { 142 | scaleCompensation = this.renderer.scale(); 143 | } 144 | 145 | if (mouseXOffset > 0 && mouseXOffset < this.renderer.width() * this.scale 146 | && mouseYOffset > 0 && mouseYOffset < this.renderer.height() * this.scale) { 147 | float x = this.renderer.cornerX() + mouseXOffset * scaleCompensation; 148 | float z = this.renderer.cornerZ() + mouseYOffset * scaleCompensation; 149 | graphics.drawCenteredShadowedText(this.client.textRenderer, String.format("X: %.1f Z: %.1f", x, z), 150 | this.getX() + this.getWidth() / 2, this.getY() + this.getHeight() - 9, 0xffffffff); 151 | 152 | var chunk = this.renderer.worldMap().getChunk(MapChunk.blockToChunk((int) x), MapChunk.blockToChunk((int) z)); 153 | if (chunk != null) { 154 | var biome = chunk.getBiome((int) x, (int) z); 155 | var registry = this.renderer.worldMap().getBiomeRegistry(); 156 | if (biome != null && registry != null) { 157 | var id = registry.getId(biome); 158 | if (id != null) { 159 | int width = this.client.textRenderer.getWidth(id.toString()); 160 | graphics.drawShadowedText(this.client.textRenderer, id.toString(), this.getX() + this.getWidth() - 5 - width, this.getY() + this.getHeight() - 9, 0xffffffff); 161 | } 162 | } 163 | } 164 | } 165 | 166 | if (!this.mod.getConfig().isWorldMapFullscreen() 167 | || mouseXOffset <= 0 || mouseYOffset < this.renderer.height() * this.scale) { 168 | var scale = "1:" + this.renderer.scale(); 169 | if (this.intScale < 0) { 170 | scale = -this.intScale + ":1"; 171 | } 172 | graphics.drawShadowedText(this.client.textRenderer, scale, this.getX(), this.getY() + this.getHeight() - 9, 0xffffffff); 173 | } 174 | 175 | if (mouseXOffset > 0 && mouseYOffset >= this.renderer.height() * this.scale) { 176 | if (this.mod.getConfig().isWorldMapFullscreen()) 177 | graphics.drawShadowedText(this.client.textRenderer, "LambdaMap", 178 | this.getX(), this.getY() + this.getHeight() - 9, 179 | 0xffffffff 180 | ); 181 | else 182 | graphics.drawCenteredShadowedText(this.client.textRenderer, "[Toggle Fullscreen]", 183 | this.getX() + this.getWidth() / 2, this.getY() + this.getHeight() - 9, 184 | 0xffffffff 185 | ); 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/marker/Marker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map.marker; 19 | 20 | import com.electronwill.nightconfig.core.Config; 21 | import net.fabricmc.api.EnvType; 22 | import net.fabricmc.api.Environment; 23 | import net.fabricmc.fabric.api.util.NbtType; 24 | import net.minecraft.client.gui.GuiGraphics; 25 | import net.minecraft.client.render.VertexConsumerProvider; 26 | import net.minecraft.item.map.MapBannerMarker; 27 | import net.minecraft.nbt.NbtCompound; 28 | import net.minecraft.text.Text; 29 | import net.minecraft.util.math.BlockPos; 30 | import net.minecraft.util.math.ChunkSectionPos; 31 | import net.minecraft.world.BlockView; 32 | import org.jetbrains.annotations.Nullable; 33 | 34 | import java.util.Objects; 35 | 36 | /** 37 | * Represents a marker. 38 | * 39 | * @author LambdAurora 40 | * @version 1.0.0 41 | * @since 1.0.0 42 | */ 43 | public class Marker { 44 | private MarkerType type; 45 | private MarkerSource source; 46 | private int x; 47 | private int y; 48 | private int z; 49 | private float rotation; 50 | private @Nullable Text name; 51 | 52 | public Marker(MarkerType type, MarkerSource source, int x, int y, int z, float rotation, @Nullable Text name) { 53 | this.type = type; 54 | this.source = source; 55 | this.x = x; 56 | this.y = y; 57 | this.z = z; 58 | this.rotation = rotation; 59 | this.name = name; 60 | } 61 | 62 | public MarkerType getType() { 63 | return this.type; 64 | } 65 | 66 | public void setType(MarkerType type) { 67 | this.type = type; 68 | } 69 | 70 | public MarkerSource getSource() { 71 | return this.source; 72 | } 73 | 74 | public void setSource(MarkerSource source) { 75 | this.source = source; 76 | } 77 | 78 | public int getX() { 79 | return this.x; 80 | } 81 | 82 | public void setX(int x) { 83 | this.x = x; 84 | } 85 | 86 | public int getY() { 87 | return this.y; 88 | } 89 | 90 | public void setY(int y) { 91 | this.y = y; 92 | } 93 | 94 | public int getZ() { 95 | return this.z; 96 | } 97 | 98 | public void setZ(int z) { 99 | this.z = z; 100 | } 101 | 102 | public BlockPos getPos() { 103 | return new BlockPos(this.getX(), this.getY(), this.getZ()); 104 | } 105 | 106 | public int getChunkX() { 107 | return ChunkSectionPos.getSectionCoord(this.getX()); 108 | } 109 | 110 | public int getChunkZ() { 111 | return ChunkSectionPos.getSectionCoord(this.getZ()); 112 | } 113 | 114 | public float getRotation() { 115 | return this.rotation; 116 | } 117 | 118 | public void setRotation(float rotation) { 119 | this.rotation = rotation; 120 | } 121 | 122 | public @Nullable Text getName() { 123 | return this.name; 124 | } 125 | 126 | public void setName(@Nullable Text name) { 127 | this.name = name; 128 | } 129 | 130 | /** 131 | * Returns whether this marker is in the specified box. 132 | * 133 | * @param minX the minimum X-coordinate of the box 134 | * @param minZ the minimum Z-coordinate of the box 135 | * @param maxX the maximum X-coordinate of the box 136 | * @param maxZ the maximum Z-coordinate of the box 137 | * @return {@code true} if the marker is in the box, else {@code false} 138 | */ 139 | public boolean isIn(int minX, int minZ, int maxX, int maxZ) { 140 | return this.getX() >= minX && this.getZ() >= minZ && this.getX() < maxX && this.getZ() < maxZ; 141 | } 142 | 143 | public boolean isAt(int x, int y, int z) { 144 | return this.getX() == x && this.getY() == y && this.getZ() == z; 145 | } 146 | 147 | public boolean isAt(Marker marker) { 148 | return this.isAt(marker.getX(), marker.getY(), marker.getZ()); 149 | } 150 | 151 | public void merge(Marker marker) { 152 | this.setType(marker.getType()); 153 | this.setSource(marker.getSource()); 154 | this.setX(marker.getX()); 155 | this.setY(marker.getY()); 156 | this.setZ(marker.getZ()); 157 | this.setRotation(marker.getRotation()); 158 | if (marker.getName() != null) 159 | this.setName(marker.getName()); 160 | } 161 | 162 | @Environment(EnvType.CLIENT) 163 | public void render(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, int startX, int startZ, float scale, int light) { 164 | graphics.getMatrices().push(); 165 | int x = this.getX() - startX; 166 | int z = this.getZ() - startZ; 167 | 168 | graphics.getMatrices().translate(x / scale, z / scale, 1.f); 169 | this.getType().render(graphics, vertexConsumers, this.getRotation(), this.getName(), light); 170 | graphics.getMatrices().pop(); 171 | } 172 | 173 | public NbtCompound toNbt() { 174 | NbtCompound nbt = new NbtCompound(); 175 | nbt.putString("type", this.type.getId()); 176 | nbt.putString("source", this.source.getId()); 177 | nbt.putInt("x", this.x); 178 | nbt.putInt("y", this.y); 179 | nbt.putInt("z", this.z); 180 | nbt.putFloat("rotation", this.rotation); 181 | if (this.name != null) { 182 | nbt.putString("name", Text.Serializer.toJson(this.name)); 183 | } 184 | return nbt; 185 | } 186 | 187 | public Config writeTo(Config config) { 188 | config.set("type", this.type.getId()); 189 | config.set("source", this.source.getId()); 190 | config.set("x", this.x); 191 | config.set("y", this.y); 192 | config.set("z", this.z); 193 | config.set("rotation", this.rotation); 194 | if (this.name != null) { 195 | config.set("name", Text.Serializer.toJson(this.name)); 196 | } 197 | return config; 198 | } 199 | 200 | @Override 201 | public String toString() { 202 | return "Marker{" + 203 | "type=" + this.getType() + 204 | ", source=" + this.getSource() + 205 | ", x=" + this.getX() + 206 | ", y=" + this.getY() + 207 | ", z=" + this.getZ() + 208 | ", rotation=" + this.getRotation() + 209 | ", name=" + this.getName() + 210 | '}'; 211 | } 212 | 213 | @Override 214 | public boolean equals(Object o) { 215 | if (this == o) return true; 216 | if (o == null || getClass() != o.getClass()) return false; 217 | Marker marker = (Marker) o; 218 | return this.x == marker.x && this.y == marker.y && this.z == marker.z && this.rotation == marker.rotation 219 | && Objects.equals(this.type, marker.type) && Objects.equals(this.name, marker.name); 220 | } 221 | 222 | @Override 223 | public int hashCode() { 224 | return Objects.hash(type, x, y, z, rotation, name); 225 | } 226 | 227 | public static @Nullable Marker fromBanner(BlockView world, BlockPos pos) { 228 | MapBannerMarker bannerMarker = MapBannerMarker.fromWorldBlock(world, pos); 229 | if (bannerMarker == null) 230 | return null; 231 | 232 | return new Marker(MarkerType.getVanillaMarkerType(bannerMarker.getIconType()), MarkerSource.BANNER, 233 | pos.getX(), pos.getY(), pos.getZ(), 180.f, bannerMarker.getName()); 234 | } 235 | 236 | public static Marker fromNbt(NbtCompound nbt) { 237 | MarkerType type = MarkerType.getMarkerType(nbt.getString("type")); 238 | Text name = null; 239 | if (nbt.contains("name", NbtType.STRING)) 240 | name = Text.Serializer.fromJson(nbt.getString("name")); 241 | return new Marker(type, MarkerSource.fromId(nbt.getString("source")), 242 | nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"), nbt.getFloat("rotation"), name); 243 | } 244 | 245 | public static Marker fromConfig(Config config) { 246 | MarkerType type = MarkerType.getMarkerType(config.getOrElse("type", MarkerType.TARGET_POINT.getId())); 247 | MarkerSource source = MarkerSource.fromId(config.getOrElse("source", MarkerSource.USER.getId())); 248 | Text name = null; 249 | if (config.contains("name")) 250 | name = Text.Serializer.fromJson(config.getOrElse("name", "{}")); 251 | return new Marker(type, source, 252 | config.getIntOrElse("x", 0), 253 | config.getIntOrElse("y", 0), 254 | config.getIntOrElse("z", 0), 255 | config.getOrElse("rotation", 0.0).floatValue(), 256 | name); 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Use the maximum available, or set MAX_FD != -1 to use that value. 89 | MAX_FD=maximum 90 | 91 | warn () { 92 | echo "$*" 93 | } >&2 94 | 95 | die () { 96 | echo 97 | echo "$*" 98 | echo 99 | exit 1 100 | } >&2 101 | 102 | # OS specific support (must be 'true' or 'false'). 103 | cygwin=false 104 | msys=false 105 | darwin=false 106 | nonstop=false 107 | case "$( uname )" in #( 108 | CYGWIN* ) cygwin=true ;; #( 109 | Darwin* ) darwin=true ;; #( 110 | MSYS* | MINGW* ) msys=true ;; #( 111 | NONSTOP* ) nonstop=true ;; 112 | esac 113 | 114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 115 | 116 | 117 | # Determine the Java command to use to start the JVM. 118 | if [ -n "$JAVA_HOME" ] ; then 119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 120 | # IBM's JDK on AIX uses strange locations for the executables 121 | JAVACMD=$JAVA_HOME/jre/sh/java 122 | else 123 | JAVACMD=$JAVA_HOME/bin/java 124 | fi 125 | if [ ! -x "$JAVACMD" ] ; then 126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 127 | 128 | Please set the JAVA_HOME variable in your environment to match the 129 | location of your Java installation." 130 | fi 131 | else 132 | JAVACMD=java 133 | if ! command -v java >/dev/null 2>&1 134 | then 135 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 136 | 137 | Please set the JAVA_HOME variable in your environment to match the 138 | location of your Java installation." 139 | fi 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | 201 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 202 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 203 | 204 | # Collect all arguments for the java command; 205 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 206 | # shell script including quotes and variable substitutions, so put them in 207 | # double quotes to make sure that they get re-expanded; and 208 | # * put everything else in single quotes, so that it's not re-expanded. 209 | 210 | set -- \ 211 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 212 | -classpath "$CLASSPATH" \ 213 | org.gradle.wrapper.GradleWrapperMain \ 214 | "$@" 215 | 216 | # Stop when "xargs" is not available. 217 | if ! command -v xargs >/dev/null 2>&1 218 | then 219 | die "xargs is not available" 220 | fi 221 | 222 | # Use "xargs" to parse quoted args. 223 | # 224 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 225 | # 226 | # In Bash we could simply go: 227 | # 228 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 229 | # set -- "${ARGS[@]}" "$@" 230 | # 231 | # but POSIX shell has neither arrays nor command substitution, so instead we 232 | # post-process each arg (as a line of input to sed) to backslash-escape any 233 | # character that might be a shell metacharacter, then use eval to reverse 234 | # that process (while maintaining the separation between arguments), and wrap 235 | # the whole thing up as a single "set" statement. 236 | # 237 | # This will of course break if any of these variables contains a newline or 238 | # an unmatched quote. 239 | # 240 | 241 | eval "set -- $( 242 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 243 | xargs -n1 | 244 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 245 | tr '\n' ' ' 246 | )" '"$@"' 247 | 248 | exec "$JAVACMD" "$@" 249 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/LambdaMapConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap; 19 | 20 | import com.electronwill.nightconfig.core.file.FileConfig; 21 | import dev.lambdaurora.lambdamap.gui.hud.HudDecorator; 22 | import dev.lambdaurora.lambdamap.gui.hud.HudDecorators; 23 | import dev.lambdaurora.spruceui.option.SpruceCheckboxBooleanOption; 24 | import dev.lambdaurora.spruceui.option.SpruceCyclingOption; 25 | import dev.lambdaurora.spruceui.option.SpruceOption; 26 | import net.minecraft.text.Text; 27 | import net.minecraft.util.Identifier; 28 | import net.minecraft.util.math.MathHelper; 29 | import org.apache.logging.log4j.LogManager; 30 | import org.apache.logging.log4j.Logger; 31 | import org.jetbrains.annotations.Range; 32 | 33 | import java.io.IOException; 34 | import java.nio.file.Files; 35 | import java.nio.file.Path; 36 | import java.nio.file.Paths; 37 | 38 | /** 39 | * Represents the mod configuration. 40 | * 41 | * @author LambdAurora 42 | * @version 1.0.0 43 | * @since 1.0.0 44 | */ 45 | public final class LambdaMapConfig { 46 | private static final boolean DEFAULT_RENDER_BIOME_COLORS = true; 47 | private static final boolean DEFAULT_SHOW_HUD = true; 48 | private static final boolean DEFAULT_FULLSCREEN = false; 49 | private static final int DEFAULT_HUD_SCALE = 2; 50 | private static final boolean DEFAULT_SHOW_DIRECTION_INDICATORS = true; 51 | private static final boolean DEFAULT_NORTH_LOCK = false; 52 | 53 | public static final Path CONFIG_FILE_PATH = Paths.get(LambdaMap.NAMESPACE, "config.toml"); 54 | 55 | private static final Logger LOGGER = LogManager.getLogger(); 56 | 57 | private final LambdaMap mod; 58 | private final FileConfig config; 59 | 60 | private final SpruceOption renderBiomeColorsOption; 61 | private final SpruceOption showHudOption; 62 | private final SpruceOption hudScaleOption; 63 | private final SpruceOption northLockOption; 64 | private final SpruceOption directionIndicatorsOption; 65 | private final SpruceOption hudDecoratorOption; 66 | 67 | private boolean renderBiomeColors; 68 | private boolean showHud; 69 | private boolean worldMapFullscreen; 70 | private int hudScale; 71 | private boolean northLock; 72 | private boolean showDirectionIndicators; 73 | private HudDecorator hudDecorator; 74 | 75 | public LambdaMapConfig(LambdaMap mod) { 76 | this.mod = mod; 77 | this.config = FileConfig.builder(CONFIG_FILE_PATH).defaultResource("/lambdamap.toml").autosave().build(); 78 | 79 | this.renderBiomeColorsOption = new SpruceCheckboxBooleanOption("lambdamap.config.render_biome_colors", 80 | this::shouldRenderBiomeColors, value -> { 81 | this.setRenderBiomeColors(value); 82 | this.mod.getRenderer().update(true); 83 | this.mod.hud.markDirty(); 84 | }, null, true); 85 | this.showHudOption = new SpruceCheckboxBooleanOption("lambdamap.config.hud.visible", 86 | this::isHudVisible, this::setHudVisible, null, true); 87 | this.hudScaleOption = new SpruceCyclingOption("lambdamap.config.hud.scale", 88 | amount -> this.setHudScale((this.hudScale + amount) % 4), option -> option.getDisplayText(Text.literal(String.valueOf(this.getHudScale()))), 89 | Text.translatable("lambdamap.config.hud.scale.tooltip")); 90 | this.northLockOption = new SpruceCheckboxBooleanOption("lambdamap.config.hud.north_lock", 91 | this::isNorthLocked, this::setNorthLock, 92 | Text.translatable("lambdamap.config.hud.north_lock.tooltip"), true); 93 | this.directionIndicatorsOption = new SpruceCheckboxBooleanOption("lambdamap.config.hud.direction_indicators", 94 | this::isDirectionIndicatorsVisible, this::setDirectionIndicatorsVisible, 95 | Text.translatable("lambdamap.config.hud.direction_indicators.tooltip"), true); 96 | this.hudDecoratorOption = new SpruceCyclingOption("lambdamap.config.hud.decorator", 97 | amount -> this.setHudDecorator(HudDecorators.pick(this.getHudDecorator(), amount)), 98 | option -> option.getDisplayText(this.getHudDecorator().getName()), 99 | Text.translatable("lambdamap.config.hud.decorator.tooltip")); 100 | } 101 | 102 | /** 103 | * Loads the configuration. 104 | */ 105 | public void load() { 106 | if (!Files.exists(CONFIG_FILE_PATH.getParent())) { 107 | try { 108 | Files.createDirectory(CONFIG_FILE_PATH.getParent()); 109 | } catch (IOException e) { 110 | LOGGER.error("Could not create parent directory for configuration.", e); 111 | } 112 | } 113 | 114 | this.config.load(); 115 | 116 | this.renderBiomeColors = this.config.getOrElse("map.render_biome_colors", DEFAULT_RENDER_BIOME_COLORS); 117 | this.showHud = this.config.getOrElse("map.hud.visible", DEFAULT_SHOW_HUD); 118 | this.hudScale = MathHelper.clamp(this.config.getIntOrElse("map.hud.scale", DEFAULT_HUD_SCALE), 1, 3); 119 | this.northLock = this.config.getOrElse("map.hud.north_lock", DEFAULT_NORTH_LOCK); 120 | this.showDirectionIndicators = this.config.getOrElse("map.hud.direction_indicators", DEFAULT_SHOW_DIRECTION_INDICATORS); 121 | this.hudDecorator = this.config.getOptional("map.hud.decorator") 122 | .map(o -> { 123 | if (o instanceof String name) { 124 | return Identifier.tryParse(name); 125 | } 126 | 127 | return null; 128 | }).map(HudDecorators::get) 129 | .orElse(HudDecorators.MAP); 130 | this.worldMapFullscreen = this.config.getOrElse("map.config.world_map.fullscreen", DEFAULT_FULLSCREEN); 131 | 132 | LOGGER.info("Configuration loaded."); 133 | } 134 | 135 | /** 136 | * Saves the configuration. 137 | */ 138 | public void save() { 139 | this.config.save(); 140 | } 141 | 142 | /** 143 | * Resets the configuration. 144 | */ 145 | public void reset() { 146 | this.setRenderBiomeColors(DEFAULT_RENDER_BIOME_COLORS); 147 | this.setHudVisible(DEFAULT_SHOW_HUD); 148 | this.setHudScale(DEFAULT_HUD_SCALE); 149 | this.setNorthLock(DEFAULT_NORTH_LOCK); 150 | this.setDirectionIndicatorsVisible(DEFAULT_SHOW_DIRECTION_INDICATORS); 151 | this.setHudDecorator(HudDecorators.MAP); 152 | } 153 | 154 | public boolean shouldRenderBiomeColors() { 155 | return this.renderBiomeColors; 156 | } 157 | 158 | public void setRenderBiomeColors(boolean renderBiomeColors) { 159 | this.renderBiomeColors = renderBiomeColors; 160 | this.config.set("map.render_biome_colors", renderBiomeColors); 161 | } 162 | 163 | public SpruceOption getRenderBiomeColorsOption() { 164 | return this.renderBiomeColorsOption; 165 | } 166 | 167 | /** 168 | * {@return {@code true} if the map HUD is visible, otherwise {@code false}} 169 | */ 170 | public boolean isHudVisible() { 171 | return this.showHud; 172 | } 173 | 174 | public void setHudVisible(boolean visible) { 175 | this.showHud = visible; 176 | this.config.set("map.hud.visible", visible); 177 | } 178 | 179 | public SpruceOption getShowHudOption() { 180 | return this.showHudOption; 181 | } 182 | 183 | /** 184 | * {@return the scale of the map HUD} 185 | */ 186 | public int getHudScale() { 187 | return this.hudScale; 188 | } 189 | 190 | /** 191 | * Sets the scale of the map HUD 192 | * 193 | * @param scale the scale 194 | */ 195 | public void setHudScale(@Range(from = 1, to = 3) int scale) { 196 | this.hudScale = MathHelper.clamp(scale, 1, 3); 197 | this.config.set("map.hud.scale", this.hudScale); 198 | } 199 | 200 | public SpruceOption getHudScaleOption() { 201 | return this.hudScaleOption; 202 | } 203 | 204 | /** 205 | * {@return {@code true} if the map is locked in place with North being towards up, otherwise {@code false}} 206 | */ 207 | public boolean isNorthLocked() { 208 | return this.northLock; 209 | } 210 | 211 | public void setNorthLock(boolean northLock) { 212 | this.northLock = northLock; 213 | this.config.set("map.hud.north_lock", northLock); 214 | } 215 | 216 | public SpruceOption getNorthLockOption() { 217 | return this.northLockOption; 218 | } 219 | 220 | /** 221 | * {@return {@code true} if the direction indicators are shown on the map HUD, otherwise {@code false}} 222 | */ 223 | public boolean isDirectionIndicatorsVisible() { 224 | return this.showDirectionIndicators; 225 | } 226 | 227 | public void setDirectionIndicatorsVisible(boolean directionIndicatorsVisible) { 228 | this.showDirectionIndicators = directionIndicatorsVisible; 229 | this.config.set("map.hud.direction_indicators", directionIndicatorsVisible); 230 | } 231 | 232 | public SpruceOption getDirectionIndicatorsOption() { 233 | return this.directionIndicatorsOption; 234 | } 235 | 236 | /** 237 | * {@return the map HUD decorator} 238 | */ 239 | public HudDecorator getHudDecorator() { 240 | return this.hudDecorator; 241 | } 242 | 243 | /** 244 | * Sets the map HUD decorator. 245 | * 246 | * @param decorator the decorator to use 247 | */ 248 | public void setHudDecorator(HudDecorator decorator) { 249 | this.hudDecorator = decorator; 250 | this.config.set("map.hud.decorator", decorator.getId().toString()); 251 | } 252 | 253 | public SpruceOption getHudDecoratorOption() { 254 | return this.hudDecoratorOption; 255 | } 256 | 257 | public void setWorldMapFullscreen(boolean visible) { 258 | this.worldMapFullscreen = visible; 259 | this.config.set("map.config.fullscreen", visible); 260 | } 261 | 262 | public Boolean isWorldMapFullscreen() { 263 | return this.worldMapFullscreen; 264 | } 265 | } 266 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/storage/MapRegionFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map.storage; 19 | 20 | import dev.lambdaurora.lambdamap.map.MapChunk; 21 | import dev.lambdaurora.lambdamap.map.WorldMap; 22 | import net.minecraft.nbt.NbtIo; 23 | import org.apache.logging.log4j.LogManager; 24 | import org.apache.logging.log4j.Logger; 25 | import org.jetbrains.annotations.Nullable; 26 | 27 | import java.io.*; 28 | import java.nio.ByteBuffer; 29 | import java.nio.LongBuffer; 30 | import java.nio.channels.FileChannel; 31 | import java.nio.charset.StandardCharsets; 32 | 33 | /** 34 | * Represents a region file. 35 | * 36 | * @author LambdAurora 37 | * @version 1.0.0 38 | * @since 1.0.0 39 | */ 40 | public class MapRegionFile implements Closeable { 41 | private static final Logger LOGGER = LogManager.getLogger(); 42 | private static final int VERSION = 0; 43 | private static final int CHUNKS = 8; 44 | private static final int HEADER_SIZE = 1024; 45 | private static final long INVALID_CHUNK = 0xffffffff; 46 | 47 | private final WorldMap worldMap; 48 | private final File file; 49 | private final RandomAccessFile raf; 50 | private final Header header; 51 | private int loadedChunks = 0; 52 | 53 | public MapRegionFile(WorldMap worldMap, File file, RandomAccessFile raf, Header header) { 54 | this.worldMap = worldMap; 55 | this.file = file; 56 | this.raf = raf; 57 | this.header = header; 58 | } 59 | 60 | public int getX() { 61 | return this.header.getX(); 62 | } 63 | 64 | public int getZ() { 65 | return this.header.getZ(); 66 | } 67 | 68 | /** 69 | * Returns the world map of this region file. 70 | * 71 | * @return the world map 72 | */ 73 | public WorldMap worldMap() { 74 | return this.worldMap; 75 | } 76 | 77 | public void incrementLoadedChunk() { 78 | this.loadedChunks++; 79 | } 80 | 81 | private static MapRegionFile open(WorldMap map, int x, int z, File file) throws IOException { 82 | boolean exists = file.exists(); 83 | 84 | var raf = new RandomAccessFile(file, "rw"); 85 | 86 | raf.seek(0); 87 | var header = new Header(raf.getChannel(), x, z); 88 | if (!exists) { 89 | header.writeDefault(); 90 | } else { 91 | header.read(); 92 | } 93 | 94 | return new MapRegionFile(map, file, raf, header); 95 | } 96 | 97 | /** 98 | * Loads the region file if found. 99 | * 100 | * @param worldMap the world map 101 | * @param x the region X-coordinate 102 | * @param z the region Z-coordinate 103 | * @return the region file if exists, else {@code null} 104 | * @throws IOException if the file cannot be created or opened or if the header fails to be written/read 105 | */ 106 | public static @Nullable MapRegionFile load(WorldMap worldMap, int x, int z) throws IOException { 107 | var file = new File(worldMap.getDirectory(), "region_" + x + "_" + z + ".lmr"); 108 | if (file.exists()) 109 | return open(worldMap, x, z, file); 110 | return null; 111 | } 112 | 113 | /** 114 | * Loads the region file if found, or create a new one. 115 | * 116 | * @param worldMap the world map 117 | * @param x the region X-coordinate 118 | * @param z the region Z-coordinate 119 | * @return the region file 120 | * @throws IOException if the file cannot be created or opened or if the header fails to be written/read 121 | */ 122 | public static MapRegionFile loadOrCreate(WorldMap worldMap, int x, int z) throws IOException { 123 | var file = new File(worldMap.getDirectory(), "region_" + x + "_" + z + ".lmr"); 124 | return open(worldMap, x, z, file); 125 | } 126 | 127 | public synchronized @Nullable MapChunk loadChunk(int x, int z) { 128 | long chunkPos = this.header.getChunkEntry(x, z); 129 | if (chunkPos == INVALID_CHUNK) { 130 | return null; 131 | } 132 | 133 | try { 134 | this.raf.seek(HEADER_SIZE + chunkPos); 135 | int size = this.raf.readInt(); 136 | if (size < 0) { 137 | LOGGER.error("Chunk ({}, {}) has an invalid size: {}", x, z, size); 138 | return null; 139 | } 140 | byte[] chunkBytes = new byte[size]; 141 | int readBytes = this.raf.read(chunkBytes); 142 | if (readBytes != size) { 143 | LOGGER.error("Chunk ({}, {}) is truncated: expected {} but read {}", x, z, size, readBytes); 144 | return null; 145 | } 146 | 147 | var nbt = NbtIo.readCompressed(new ByteArrayInputStream(chunkBytes)); 148 | return MapChunk.fromNbt(this, nbt); 149 | } catch (IOException e) { 150 | LOGGER.error("Failed to load chunk (" + x + ", " + z + ")", e); 151 | } 152 | return null; 153 | } 154 | 155 | public MapChunk loadChunkOrCreate(int x, int z) { 156 | var chunk = this.loadChunk(x, z); 157 | if (chunk == null) { 158 | chunk = new MapChunk(this.worldMap(), this, x, z); 159 | } 160 | return chunk; 161 | } 162 | 163 | public synchronized void unloadChunk(MapChunk chunk) { 164 | this.loadedChunks--; 165 | try { 166 | this.saveChunk(chunk); 167 | } catch (IOException e) { 168 | LOGGER.error("Could not save chunk " + chunk, e); 169 | } 170 | 171 | if (this.loadedChunks == 0) { 172 | try { 173 | this.close(); 174 | } catch (IOException e) { 175 | LOGGER.error("Failed to close region file (" + this.getX() + ", " + this.getZ() + ")", e); 176 | } 177 | } 178 | } 179 | 180 | public synchronized void saveChunk(MapChunk chunk) throws IOException { 181 | if (chunk.isEmpty()) 182 | return; 183 | 184 | var stream = new ByteArrayOutputStream(8096); 185 | chunk.lock(); 186 | NbtIo.writeCompressed(chunk.toNbt(), stream); 187 | chunk.unlock(); 188 | 189 | int size = stream.size(); 190 | long chunkPos = this.header.getChunkEntry(chunk.getX(), chunk.getZ()); 191 | if (chunkPos == INVALID_CHUNK) { 192 | chunkPos = Math.max(this.raf.length(), HEADER_SIZE); 193 | this.header.writeChunkEntry(chunk.getX(), chunk.getZ(), chunkPos - HEADER_SIZE); 194 | } else { 195 | chunkPos += HEADER_SIZE; 196 | this.raf.seek(chunkPos); 197 | this.shiftChunksIfNeeded( 198 | chunkPos, 199 | this.raf.readInt() + 4, // Read old size of the chunk, including the size int. 200 | size + 4); 201 | } 202 | 203 | this.raf.seek(chunkPos); 204 | this.raf.writeInt(size); 205 | this.raf.write(stream.toByteArray()); 206 | this.header.write(); 207 | stream.close(); 208 | } 209 | 210 | public void shiftChunksIfNeeded(long pos, long oldSize, long newSize) throws IOException { 211 | long delta = newSize - oldSize; 212 | 213 | if (delta <= 0 || this.raf.length() == pos + oldSize) { 214 | return; 215 | } 216 | 217 | for (int i = 0; i < this.header.getEntriesCount(); i++) { 218 | long offset = this.header.getChunkEntry(i); 219 | if (offset != INVALID_CHUNK && pos < offset + HEADER_SIZE) { 220 | this.header.writeChunkEntry(i, offset + delta); 221 | } 222 | } 223 | 224 | long size = this.raf.length() - pos - oldSize; 225 | 226 | this.raf.seek(pos + oldSize); 227 | // Hopefully the data to shift is small enough. 228 | // If the data is too big then shift by blocks of 512 or 1024 bytes. 229 | byte[] dataToShift = new byte[(int) size]; 230 | int readBytes = this.raf.read(dataToShift); 231 | this.raf.seek(pos + newSize); 232 | this.raf.write(dataToShift); 233 | } 234 | 235 | @Override 236 | public void close() throws IOException { 237 | this.header.write(); 238 | 239 | boolean empty = this.header.isEmpty(); 240 | 241 | this.raf.close(); 242 | this.worldMap.unloadRegion(this); 243 | 244 | if (empty) { 245 | if (!this.file.delete()) { 246 | LOGGER.warn("Failed to delete empty region file {}.", this.file); 247 | } else { 248 | LOGGER.debug("Deleted empty region file {}.", this.file); 249 | } 250 | } 251 | } 252 | 253 | /** 254 | * Represents the header of a region file. 255 | *

256 | * The header is a 1024 bytes space containing: 257 | *

    258 | *
  • The UTF-8 string {@code "LambdaMapRegion "}
  • 259 | *
  • The version as a 16-bit unsigned integer
  • 260 | *
  • An ASCII space {@code ' '}
  • 261 | *
  • The X-coordinate as a 32-bit signed integer
  • 262 | *
  • The Z-coordinate as a 32-bit signed integer
  • 263 | *
  • Starting at the 32th byte, ordered list (size 64) of chunk offset from the Header as 64-bit unsigned integers
  • 264 | *
265 | * 266 | * @version 1.0.0 267 | * @since 1.0.0 268 | */ 269 | static class Header { 270 | private final FileChannel channel; 271 | private final ByteBuffer header; 272 | private final LongBuffer chunkData; 273 | private final int x; 274 | private final int z; 275 | 276 | private Header(FileChannel channel, int x, int z) { 277 | this.channel = channel; 278 | this.header = ByteBuffer.allocateDirect(HEADER_SIZE); 279 | this.header.position(32); 280 | this.chunkData = this.header.asLongBuffer(); 281 | this.chunkData.limit(CHUNKS * CHUNKS); 282 | this.x = x; 283 | this.z = z; 284 | } 285 | 286 | public int getX() { 287 | return this.x; 288 | } 289 | 290 | public int getZ() { 291 | return this.z; 292 | } 293 | 294 | public long getEntriesCount() { 295 | return this.chunkData.limit(); 296 | } 297 | 298 | public void writeDefault() throws IOException { 299 | this.header.position(0); 300 | for (int i = 0; i < 32; i++) { 301 | this.header.put((byte) 0); 302 | } 303 | this.chunkData.position(0); 304 | for (int i = 0; i < this.chunkData.limit(); i++) { 305 | this.chunkData.put(INVALID_CHUNK); 306 | } 307 | this.write(); 308 | } 309 | 310 | public void write() throws IOException { 311 | // Header start 312 | this.header.position(0); 313 | this.header.put("LambdaMapRegion ".getBytes(StandardCharsets.UTF_8)); 314 | this.header.putShort((short) VERSION); 315 | this.header.put((byte) ' '); 316 | this.header.putInt(this.x); 317 | this.header.putInt(this.z); 318 | 319 | this.header.position(0); 320 | this.channel.write(this.header, 0L); 321 | } 322 | 323 | public void read() throws IOException { 324 | this.header.position(0); 325 | this.channel.read(this.header, 0L); 326 | 327 | this.header.position(16); 328 | 329 | short version = this.header.getShort(); 330 | this.header.get(); 331 | this.header.getInt(); 332 | this.header.getInt(); 333 | } 334 | 335 | public void writeChunkEntry(int index, long offset) { 336 | this.chunkData.put(index, offset); 337 | } 338 | 339 | public void writeChunkEntry(int x, int z, long offset) { 340 | this.writeChunkEntry((z & 7) * CHUNKS + (x & 7), offset); 341 | } 342 | 343 | public long getChunkEntry(int index) { 344 | return this.chunkData.get(index); 345 | } 346 | 347 | public long getChunkEntry(int x, int z) { 348 | return this.getChunkEntry((z & 7) * CHUNKS + (x & 7)); 349 | } 350 | 351 | public boolean hasChunk(int x, int z) { 352 | return this.getChunkEntry(x, z) != INVALID_CHUNK; 353 | } 354 | 355 | public boolean isEmpty() { 356 | for (int i = 0; i < CHUNKS * CHUNKS; i++) { 357 | if (this.getChunkEntry(i) != INVALID_CHUNK) 358 | return false; 359 | } 360 | return true; 361 | } 362 | } 363 | } 364 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/MarkerListWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.vertex.Tessellator; 21 | import dev.lambdaurora.lambdamap.map.marker.Marker; 22 | import dev.lambdaurora.lambdamap.map.marker.MarkerManager; 23 | import dev.lambdaurora.lambdamap.map.marker.MarkerSource; 24 | import dev.lambdaurora.spruceui.Position; 25 | import dev.lambdaurora.spruceui.background.EmptyBackground; 26 | import dev.lambdaurora.spruceui.navigation.NavigationDirection; 27 | import dev.lambdaurora.spruceui.navigation.NavigationUtils; 28 | import dev.lambdaurora.spruceui.util.SpruceUtil; 29 | import dev.lambdaurora.spruceui.widget.SpruceButtonWidget; 30 | import dev.lambdaurora.spruceui.widget.SpruceWidget; 31 | import dev.lambdaurora.spruceui.widget.container.SpruceEntryListWidget; 32 | import dev.lambdaurora.spruceui.widget.container.SpruceParentWidget; 33 | import dev.lambdaurora.spruceui.widget.text.SpruceTextFieldWidget; 34 | import net.minecraft.client.font.TextRenderer; 35 | import net.minecraft.client.gui.GuiGraphics; 36 | import net.minecraft.client.render.LightmapTextureManager; 37 | import net.minecraft.client.render.VertexConsumerProvider; 38 | import net.minecraft.text.OrderedText; 39 | import net.minecraft.text.Style; 40 | import net.minecraft.text.Text; 41 | import net.minecraft.util.Formatting; 42 | import org.jetbrains.annotations.Nullable; 43 | import org.joml.Matrix4f; 44 | import org.lwjgl.glfw.GLFW; 45 | 46 | import java.util.ArrayList; 47 | import java.util.Iterator; 48 | import java.util.List; 49 | 50 | public class MarkerListWidget extends SpruceEntryListWidget { 51 | protected final MarkerTabWidget parent; 52 | protected final MarkerManager markerManager; 53 | private int lastIndex = 0; 54 | 55 | public MarkerListWidget(MarkerTabWidget parent, Position position, int width, int height, MarkerManager markerManager) { 56 | super(position, width, height, 0, MarkerEntry.class); 57 | this.parent = parent; 58 | this.markerManager = markerManager; 59 | 60 | this.setBackground(EmptyBackground.EMPTY_BACKGROUND); 61 | this.setRenderTransition(false); 62 | this.rebuildList(); 63 | } 64 | 65 | public void rebuildList() { 66 | this.clearEntries(); 67 | this.markerManager.forEach(this::addMarker); 68 | } 69 | 70 | public void addMarker(Marker marker) { 71 | this.addEntry(new MarkerEntry(this, marker)); 72 | } 73 | 74 | public void removeMarker(MarkerEntry entry) { 75 | markerManager.removeMarker(entry.marker); 76 | removeEntry(entry); 77 | } 78 | 79 | public static class MarkerEntry extends SpruceEntryListWidget.Entry implements SpruceParentWidget { 80 | protected final MarkerListWidget parent; 81 | final Marker marker; 82 | private final List children = new ArrayList<>(); 83 | private @Nullable SpruceWidget focused; 84 | 85 | public MarkerEntry(MarkerListWidget parent, Marker marker) { 86 | this.parent = parent; 87 | this.marker = marker; 88 | 89 | var typeBtn = new MarkerTypeButton(Position.of(this, 3, 2), this.marker.getType(), this.marker::setType); 90 | typeBtn.setActive(this.marker.getSource() == MarkerSource.USER); 91 | this.children.add(typeBtn); 92 | this.addNameFieldWidget(); 93 | this.addPositionFieldWidgets(); 94 | 95 | this.children.add(new SpruceButtonWidget(Position.of(this, this.getWidth() - 24, 2), 20, 20, Text.literal("X").formatted(Formatting.RED), 96 | btn -> { 97 | // Force Deletion using SHIFT key to skip the confirmation dialog, might be worth making configurable? 98 | if(GLFW.glfwGetKey(GLFW.glfwGetCurrentContext(), GLFW.GLFW_KEY_LEFT_SHIFT) == GLFW.GLFW_PRESS || 99 | GLFW.glfwGetKey(GLFW.glfwGetCurrentContext(), GLFW.GLFW_KEY_RIGHT_SHIFT) == GLFW.GLFW_PRESS) { 100 | this.parent.removeMarker(this); 101 | } else { 102 | parent.parent.promptForDeletion(this); 103 | } 104 | })); 105 | } 106 | 107 | private void addNameFieldWidget() { 108 | var fieldWidget = new SpruceTextFieldWidget(Position.of(this, 32, 2), this.getWidth() / 2 - 48, 20, Text.literal("Marker Name Field")); 109 | if (this.marker.getName() != null) 110 | fieldWidget.setText(this.marker.getName().getString()); 111 | if (this.marker.getSource() != MarkerSource.BANNER) 112 | fieldWidget.setChangedListener(newName -> { 113 | if (newName.isEmpty()) this.marker.setName(null); 114 | else this.marker.setName(Text.literal(newName)); 115 | }); 116 | else { 117 | fieldWidget.setActive(false); 118 | fieldWidget.setRenderTextProvider((displayedText, offset) -> { 119 | Style style = Style.EMPTY; 120 | if (this.marker.getName() != null) 121 | style = this.marker.getName().getStyle(); 122 | return OrderedText.forward(displayedText, style); 123 | }); 124 | } 125 | this.children.add(fieldWidget); 126 | } 127 | 128 | private void addPositionFieldWidgets() { 129 | int x = this.getWidth() / 2; 130 | 131 | var xField = new SpruceTextFieldWidget(Position.of(this, x + 12, 2), 48, 20, Text.literal("X Field")); 132 | xField.setText(String.valueOf(this.marker.getX())); 133 | xField.setTextPredicate(SpruceTextFieldWidget.INTEGER_INPUT_PREDICATE); 134 | xField.setChangedListener(input -> this.marker.setX(SpruceUtil.parseIntFromString(input))); 135 | this.children.add(xField); 136 | 137 | var zField = new SpruceTextFieldWidget(Position.of(this, x + 64 + 16, 2), 48, 20, Text.literal("Z Field")); 138 | zField.setText(String.valueOf(this.marker.getZ())); 139 | zField.setTextPredicate(SpruceTextFieldWidget.INTEGER_INPUT_PREDICATE); 140 | zField.setChangedListener(input -> this.marker.setZ(SpruceUtil.parseIntFromString(input))); 141 | this.children.add(zField); 142 | 143 | if (this.marker.getSource() != MarkerSource.USER) { 144 | xField.setActive(false); 145 | zField.setActive(false); 146 | } 147 | } 148 | 149 | @Override 150 | public int getWidth() { 151 | return this.parent.getWidth() - 6; 152 | } 153 | 154 | @Override 155 | public int getHeight() { 156 | return 24 + 2; 157 | } 158 | 159 | @Override 160 | public List children() { 161 | return this.children; 162 | } 163 | 164 | @Override 165 | public @Nullable SpruceWidget getFocused() { 166 | return this.focused; 167 | } 168 | 169 | @Override 170 | public void setFocused(@Nullable SpruceWidget focused) { 171 | if (this.focused == focused) 172 | return; 173 | if (this.focused != null) 174 | this.focused.setFocused(false); 175 | this.focused = focused; 176 | if (this.focused != null) 177 | this.focused.setFocused(true); 178 | } 179 | 180 | @Override 181 | public void setFocused(boolean focused) { 182 | super.setFocused(focused); 183 | if (!focused) { 184 | this.setFocused(null); 185 | } 186 | } 187 | 188 | /* Navigation */ 189 | 190 | @Override 191 | public boolean onNavigation(NavigationDirection direction, boolean tab) { 192 | if (this.requiresCursor()) return false; 193 | if (!tab && direction.isVertical()) { 194 | if (this.isFocused()) { 195 | this.setFocused(null); 196 | return false; 197 | } 198 | int lastIndex = this.parent.lastIndex; 199 | if (lastIndex >= this.children.size()) 200 | lastIndex = this.children.size() - 1; 201 | if (!this.children.get(lastIndex).onNavigation(direction, tab)) 202 | return false; 203 | this.setFocused(this.children.get(lastIndex)); 204 | return true; 205 | } 206 | 207 | boolean result = NavigationUtils.tryNavigate(direction, tab, this.children, this.focused, this::setFocused, true); 208 | if (result) { 209 | this.setFocused(true); 210 | if (direction.isHorizontal() && this.getFocused() != null) { 211 | this.parent.lastIndex = this.children.indexOf(this.getFocused()); 212 | } 213 | } 214 | return result; 215 | } 216 | 217 | /* Input */ 218 | 219 | @Override 220 | protected boolean onMouseClick(double mouseX, double mouseY, int button) { 221 | Iterator it = this.iterator(); 222 | 223 | SpruceWidget element; 224 | do { 225 | if (!it.hasNext()) { 226 | return false; 227 | } 228 | 229 | element = it.next(); 230 | } while (!element.mouseClicked(mouseX, mouseY, button)); 231 | 232 | this.setFocused(element); 233 | if (button == GLFW.GLFW_MOUSE_BUTTON_1) 234 | this.dragging = true; 235 | 236 | return true; 237 | } 238 | 239 | @Override 240 | protected boolean onMouseRelease(double mouseX, double mouseY, int button) { 241 | this.dragging = false; 242 | return this.hoveredElement(mouseX, mouseY).filter(element -> element.mouseReleased(mouseX, mouseY, button)).isPresent(); 243 | } 244 | 245 | @Override 246 | protected boolean onMouseScroll(double mouseX, double mouseY, double amount) { 247 | Iterator it = this.iterator(); 248 | 249 | SpruceWidget element; 250 | do { 251 | if (!it.hasNext()) { 252 | return false; 253 | } 254 | 255 | element = it.next(); 256 | } while (!element.mouseScrolled(mouseX, mouseY, amount)); 257 | 258 | this.setFocused(element); 259 | 260 | return true; 261 | } 262 | 263 | @Override 264 | protected boolean onMouseDrag(double mouseX, double mouseY, int button, double deltaX, double deltaY) { 265 | return this.getFocused() != null && this.dragging && button == GLFW.GLFW_MOUSE_BUTTON_1 266 | && this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY); 267 | } 268 | 269 | @Override 270 | protected boolean onKeyPress(int keyCode, int scanCode, int modifiers) { 271 | return this.focused != null && this.focused.keyPressed(keyCode, scanCode, modifiers); 272 | } 273 | 274 | @Override 275 | protected boolean onKeyRelease(int keyCode, int scanCode, int modifiers) { 276 | return this.focused != null && this.focused.keyReleased(keyCode, scanCode, modifiers); 277 | } 278 | 279 | @Override 280 | protected boolean onCharTyped(char chr, int keyCode) { 281 | return this.focused != null && this.focused.charTyped(chr, keyCode); 282 | } 283 | 284 | /* Rendering */ 285 | 286 | @Override 287 | protected void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 288 | this.forEach(widget -> widget.render(graphics, mouseX, mouseY, delta)); 289 | 290 | int light = LightmapTextureManager.pack(15, 15); 291 | 292 | VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBufferBuilder()); 293 | 294 | float textY = this.getY() + this.getHeight() / 2.f - 5; 295 | 296 | Matrix4f model = graphics.getMatrices().peek().getModel(); 297 | 298 | this.client.textRenderer.draw("X: ", this.getX() + this.getWidth() / 2.f, textY, 0xffffffff, true, model, immediate, TextRenderer.TextLayerType.NORMAL, 0, light); 299 | this.client.textRenderer.draw("Z: ", this.getX() + this.getWidth() / 2.f + 48 + 20, textY, 0xffffffff, true, model, immediate, TextRenderer.TextLayerType.NORMAL, 0, light); 300 | 301 | immediate.draw(); 302 | } 303 | 304 | @Override 305 | protected void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 306 | graphics.fill(this.getX(), this.getY(), this.getX() + this.parent.getInnerWidth(), this.getY() + this.getHeight() - 2, 0x55555555); 307 | } 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/LambdaMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap; 19 | 20 | import dev.lambdaurora.lambdamap.extension.WorldChunkExtension; 21 | import dev.lambdaurora.lambdamap.gui.WorldMapRenderer; 22 | import dev.lambdaurora.lambdamap.gui.WorldMapScreen; 23 | import dev.lambdaurora.lambdamap.gui.hud.MapHud; 24 | import dev.lambdaurora.lambdamap.map.WorldMap; 25 | import dev.lambdaurora.lambdamap.mixin.BiomeAccessAccessor; 26 | import dev.lambdaurora.lambdamap.mixin.PersistentStateManagerAccessor; 27 | import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; 28 | import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; 29 | import net.minecraft.block.MapColor; 30 | import net.minecraft.client.MinecraftClient; 31 | import net.minecraft.client.option.KeyBind; 32 | import net.minecraft.client.render.LightmapTextureManager; 33 | import net.minecraft.client.render.RenderLayer; 34 | import net.minecraft.client.world.ClientWorld; 35 | import net.minecraft.entity.player.PlayerEntity; 36 | import net.minecraft.registry.RegistryKey; 37 | import net.minecraft.util.Identifier; 38 | import net.minecraft.util.math.ChunkPos; 39 | import net.minecraft.util.math.ChunkSectionPos; 40 | import net.minecraft.world.Heightmap; 41 | import net.minecraft.world.World; 42 | import net.minecraft.world.biome.Biome; 43 | import net.minecraft.world.chunk.ChunkStatus; 44 | import net.minecraft.world.chunk.WorldChunk; 45 | import org.lwjgl.glfw.GLFW; 46 | import org.quiltmc.loader.api.ModContainer; 47 | import org.quiltmc.loader.api.QuiltLoader; 48 | import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; 49 | import org.quiltmc.qsl.lifecycle.api.client.event.ClientLifecycleEvents; 50 | import org.quiltmc.qsl.lifecycle.api.client.event.ClientWorldTickEvents; 51 | 52 | import java.io.File; 53 | 54 | /** 55 | * Represents the LambdaMap mod. 56 | * 57 | * @author LambdAurora 58 | * @version 1.0.0 59 | * @since 1.0.0 60 | */ 61 | public class LambdaMap implements ClientModInitializer, ClientLifecycleEvents.Ready, ClientWorldTickEvents.Start { 62 | public static final LambdaMap INSTANCE = new LambdaMap(); 63 | 64 | public static final String NAMESPACE = "lambdamap"; 65 | public static final Identifier MAP_ICONS_TEXTURE = new Identifier("textures/map/map_icons.png"); 66 | public static final RenderLayer MAP_ICONS = RenderLayer.getText(MAP_ICONS_TEXTURE); 67 | private final KeyBind hudKeybind = KeyBindingHelper.registerKeyBinding(new KeyBind("lambdamap.keybind.hud", GLFW.GLFW_KEY_O, "key.categories.lambdamap")); 68 | private final KeyBind mapKeybind = KeyBindingHelper.registerKeyBinding(new KeyBind("lambdamap.keybind.map", GLFW.GLFW_KEY_B, "key.categories.lambdamap")); 69 | private final LambdaMapConfig config = new LambdaMapConfig(this); 70 | private final WorldMapRenderer renderer = new WorldMapRenderer(this); 71 | private WorldMap map = null; 72 | public MapHud hud = null; 73 | 74 | private int updatedChunks = 0; 75 | 76 | @Override 77 | public void onInitializeClient(ModContainer mod) { 78 | this.config.load(); 79 | 80 | HudRenderCallback.EVENT.register((matrices, delta) -> { 81 | this.hud.render(matrices, LightmapTextureManager.pack(15, 15), delta); 82 | }); 83 | } 84 | 85 | /** 86 | * Returns the configuration of the mod. 87 | * 88 | * @return the configuration 89 | */ 90 | public LambdaMapConfig getConfig() { 91 | return this.config; 92 | } 93 | 94 | public WorldMap getMap() { 95 | return this.map; 96 | } 97 | 98 | public WorldMapRenderer getRenderer() { 99 | return this.renderer; 100 | } 101 | 102 | @Override 103 | public void readyClient(MinecraftClient client) { 104 | this.hud = new MapHud(this.config, client); 105 | } 106 | 107 | @Override 108 | public void startWorldTick(MinecraftClient client, ClientWorld world) { 109 | if (this.map.updatePlayerViewPos(client.player.getBlockX(), client.player.getBlockZ(), this.hud.getMovementThreshold())) { 110 | this.hud.markDirty(); 111 | } 112 | 113 | this.map.tick(); 114 | this.updateChunks(world, client.player); 115 | 116 | if (this.hudKeybind.wasPressed()) { 117 | this.hud.setVisible(!this.hud.isVisible()); 118 | } 119 | 120 | if (this.mapKeybind.wasPressed()) { 121 | client.setScreen(new WorldMapScreen()); 122 | } 123 | 124 | this.hud.updateTexture(this.getMap()); 125 | } 126 | 127 | public void loadMap(MinecraftClient client, ClientWorld world) { 128 | File directory; 129 | if (client.getServer() != null) { 130 | directory = getWorldMapDirectorySP(client, world.getRegistryKey()); 131 | } else { 132 | var hashedSeed = ((BiomeAccessAccessor) world.getBiomeAccess()).getSeed(); 133 | directory = getWorldMapDirectoryMP(client, world.getRegistryKey(), hashedSeed); 134 | } 135 | this.map = new WorldMap(world, directory); 136 | this.renderer.setWorldMap(this.map); 137 | } 138 | 139 | public void unloadMap() { 140 | if (this.map != null) { 141 | this.map.unload(); 142 | this.map = null; 143 | } 144 | } 145 | 146 | public void onBlockUpdate(int x, int z) { 147 | int chunkX = ChunkSectionPos.getSectionCoord(x); 148 | int chunkZ = ChunkSectionPos.getSectionCoord(z); 149 | int localX = ChunkSectionPos.getLocalCoord(x); 150 | int localZ = ChunkSectionPos.getLocalCoord(z); 151 | 152 | if (localX >= 2 && localX < 14 && localZ >= 2 && localZ < 14) { 153 | var chunk = this.map.getWorld().getChunk(chunkX, chunkZ); 154 | if (chunk != null) { 155 | ((WorldChunkExtension) chunk).lambdamap$markDirty(); 156 | } 157 | } else this.onChunkUpdate(chunkX, chunkZ); 158 | } 159 | 160 | public void onChunkUpdate(int chunkX, int chunkZ) { 161 | for (int x = chunkX - 1; x < chunkX + 2; ++x) { 162 | for (int z = chunkZ - 1; z < chunkZ + 2; ++z) { 163 | var chunk = this.map.getWorld().getChunk(x, z); 164 | if (chunk != null) { 165 | ((WorldChunkExtension) chunk).lambdamap$markDirty(); 166 | } 167 | } 168 | } 169 | } 170 | 171 | public void updateChunks(World world, PlayerEntity entity) { 172 | var pos = entity.getChunkPos(); 173 | var client = MinecraftClient.getInstance(); 174 | int viewDistance = Math.max(2, client.options.getEffectiveViewDistance() - 2); 175 | this.updatedChunks = 0; 176 | for (int x = pos.x - viewDistance; x <= pos.x + viewDistance; x++) { 177 | for (int z = pos.z - viewDistance; z <= pos.z + viewDistance; z++) { 178 | this.updateChunk(world, x, z); 179 | } 180 | } 181 | } 182 | 183 | public void updateChunk(World world, int chunkX, int chunkZ) { 184 | int chunkStartX = ChunkSectionPos.getBlockCoord(chunkX); 185 | int chunkStartZ = ChunkSectionPos.getBlockCoord(chunkZ); 186 | int mapChunkStartX = chunkStartX & 127; 187 | int mapChunkStartZ = chunkStartZ & 127; 188 | 189 | // Big thanks to comp500 for this piece of code 190 | // https://github.com/comp500/tinymap/blob/master/src/main/java/link/infra/tinymap/TileGenerator.java#L103 191 | var searcher = new BlockSearcher(world); 192 | boolean hasCeiling = world.getDimension().hasCeiling(); 193 | 194 | var chunkBefore = (WorldChunk) world.getChunk(chunkX, chunkZ - 1, ChunkStatus.SURFACE, false); 195 | var chunkPosBefore = new ChunkPos(chunkX, chunkZ - 1); 196 | Heightmap chunkBeforeHeightmap; 197 | if (chunkBefore != null) chunkBeforeHeightmap = chunkBefore.getHeightmap(Heightmap.Type.WORLD_SURFACE); 198 | else return; 199 | 200 | int[] lastHeights = new int[16]; 201 | 202 | var chunk = world.getChunk(chunkX, chunkZ, ChunkStatus.SURFACE, false); 203 | if (chunk == null) 204 | return; 205 | 206 | if (chunk instanceof WorldChunkExtension extendedChunk) { 207 | if (!extendedChunk.lambdamap$isDirty()) 208 | return; 209 | } 210 | 211 | this.updatedChunks++; 212 | 213 | var chunkHeightmap = chunk.getHeightmap(Heightmap.Type.WORLD_SURFACE); 214 | 215 | var mapChunk = this.map.getChunkOrCreate(chunkX >> 3, chunkZ >> 3); 216 | 217 | for (int xOffset = 0; xOffset < 16; xOffset++) { 218 | if (!chunkBefore.isEmpty()) { 219 | // Get first line, to calculate proper shade 220 | if (hasCeiling) { 221 | searcher.searchForBlockCeil(chunkBefore, xOffset, 15, chunkPosBefore.getStartX(), chunkPosBefore.getStartZ()); 222 | } else { 223 | searcher.searchForBlock(chunkBefore, chunkBeforeHeightmap, xOffset, 15, chunkPosBefore.getStartX(), chunkPosBefore.getStartZ()); 224 | } 225 | lastHeights[xOffset] = searcher.getHeight(); 226 | } 227 | 228 | for (int zOffset = 0; zOffset < 16; zOffset++) { 229 | if (hasCeiling) { 230 | searcher.searchForBlockCeil(chunk, xOffset, zOffset, chunkStartX, chunkStartZ); 231 | } else { 232 | searcher.searchForBlock(chunk, chunkHeightmap, xOffset, zOffset, chunkStartX, chunkStartZ); 233 | } 234 | 235 | if (searcher.getHeight() > 0 && !searcher.getState().getFluidState().isEmpty()) { 236 | searcher.calcWaterDepth(chunk); 237 | } 238 | 239 | var mapColor = searcher.getState().getMapColor(world, searcher.pos); 240 | Biome biome = null; 241 | if (chunk instanceof WorldChunkExtension extendedChunk && extendedChunk.lambdamap$isBiomeDirty()) { 242 | biome = world.getBiome(searcher.pos).value(); 243 | } 244 | 245 | int shade; 246 | 247 | if (mapColor == MapColor.WATER) { 248 | double shadeTest = (double) searcher.getWaterDepth() * 0.1D + (double) (xOffset + zOffset & 1) * 0.2D; 249 | shade = 1; 250 | if (shadeTest < 0.5D) { 251 | shade = 2; 252 | } 253 | 254 | if (shadeTest > 0.9D) { 255 | shade = 0; 256 | } 257 | } else { 258 | double shadeTest = (searcher.getHeight() - lastHeights[xOffset]) * 4.0D / 5.0D + ((double) (xOffset + zOffset & 1) - 0.5D) * 0.4D; 259 | shade = 1; 260 | if (shadeTest > 0.6D) { 261 | shade = 2; 262 | } 263 | if (shadeTest < -0.6D) { 264 | shade = 0; 265 | } 266 | } 267 | 268 | lastHeights[xOffset] = searcher.getHeight(); 269 | int x = mapChunkStartX + xOffset; 270 | int z = mapChunkStartZ + zOffset; 271 | if (mapChunk.putPixelAndPreserve(x, z, (byte) (mapColor.id * 4 + shade), biome, searcher.getState())) { 272 | this.hud.markDirty(); 273 | } 274 | } 275 | } 276 | 277 | if (chunk instanceof WorldChunkExtension extendedChunk) { 278 | extendedChunk.lambdamap$markClean(); 279 | } 280 | } 281 | 282 | public static File getWorldMapDirectorySP(MinecraftClient client, RegistryKey worldKey) { 283 | var world = client.getServer().getWorld(worldKey); 284 | if (world == null) { 285 | world = client.getServer().getOverworld(); 286 | } 287 | var worldDirectory = ((PersistentStateManagerAccessor) world.getPersistentStateManager()).getDirectory().getParentFile(); 288 | var mapDirectory = new File(worldDirectory, NAMESPACE); 289 | mapDirectory.mkdirs(); 290 | return mapDirectory; 291 | } 292 | 293 | public static File getWorldMapDirectoryMP(MinecraftClient client, RegistryKey worldKey, long hashedSeed) { 294 | var serverInfo = client.getCurrentServerEntry(); 295 | var gameDir = QuiltLoader.getGameDir().toFile(); 296 | var lambdaMapDir = new File(gameDir, NAMESPACE); 297 | var serverDir = new File(lambdaMapDir, (serverInfo.name + "_" + serverInfo.address).replaceAll("[^A-Za-z0-9_.]", "_")); 298 | var seedDir = new File(serverDir, String.valueOf(hashedSeed)); 299 | var worldDir = new File(seedDir, worldKey.getValue().getNamespace() + "/" + worldKey.getValue().getPath()); 300 | if (!worldDir.exists()) 301 | worldDir.mkdirs(); 302 | return worldDir; 303 | } 304 | 305 | public static Identifier id(String path) { 306 | return new Identifier(NAMESPACE, path); 307 | } 308 | 309 | public static LambdaMap get() { 310 | return INSTANCE; 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/hud/MapHud.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui.hud; 19 | 20 | import com.mojang.blaze3d.systems.RenderSystem; 21 | import com.mojang.blaze3d.vertex.Tessellator; 22 | import dev.lambdaurora.lambdamap.LambdaMap; 23 | import dev.lambdaurora.lambdamap.LambdaMapConfig; 24 | import dev.lambdaurora.lambdamap.gui.WorldMapRenderer; 25 | import dev.lambdaurora.lambdamap.map.ChunkGetterMode; 26 | import dev.lambdaurora.lambdamap.map.WorldMap; 27 | import dev.lambdaurora.lambdamap.map.marker.MarkerType; 28 | import dev.lambdaurora.spruceui.util.ColorUtil; 29 | import dev.lambdaurora.spruceui.util.ScissorManager; 30 | import net.minecraft.client.MinecraftClient; 31 | import net.minecraft.client.font.TextRenderer; 32 | import net.minecraft.client.gui.GuiGraphics; 33 | import net.minecraft.client.render.RenderLayer; 34 | import net.minecraft.client.render.VertexConsumerProvider; 35 | import net.minecraft.client.texture.NativeImageBackedTexture; 36 | import net.minecraft.client.util.math.MatrixStack; 37 | import net.minecraft.text.Text; 38 | import net.minecraft.util.math.Axis; 39 | import net.minecraft.util.math.MathHelper; 40 | 41 | public class MapHud implements AutoCloseable { 42 | private static final Text NORTH = Text.translatable("lambdamap.compass.short.north"); 43 | private static final Text EAST = Text.translatable("lambdamap.compass.short.east"); 44 | private static final Text SOUTH = Text.translatable("lambdamap.compass.short.south"); 45 | private static final Text WEST = Text.translatable("lambdamap.compass.short.west"); 46 | 47 | private final LambdaMapConfig config; 48 | private final MinecraftClient client; 49 | private final NativeImageBackedTexture texture = new NativeImageBackedTexture(128 + 64, 128 + 64, true); 50 | private final RenderLayer mapRenderLayer; 51 | private boolean dirty = true; 52 | private int renderPosX; 53 | private int renderPosZ; 54 | 55 | public MapHud(LambdaMapConfig config, MinecraftClient client) { 56 | this.config = config; 57 | this.client = client; 58 | var id = LambdaMap.id("hud"); 59 | client.getTextureManager().registerTexture(id, this.texture); 60 | this.mapRenderLayer = RenderLayer.getText(id); 61 | } 62 | 63 | public void markDirty() { 64 | this.dirty = true; 65 | } 66 | 67 | public boolean isVisible() { 68 | return this.config.isHudVisible(); 69 | } 70 | 71 | public void setVisible(boolean visible) { 72 | this.config.setHudVisible(visible); 73 | } 74 | 75 | private static final int TEXTURE_SIZE = 128 + 64; 76 | private static final int HUD_SIZE = 128; 77 | private static final float THRESHOLD_NORTH_LOCKED = ((TEXTURE_SIZE - HUD_SIZE) / 2f) - 1f; 78 | private static final float THRESHOLD_ROTATED = ((TEXTURE_SIZE / 2f) - MathHelper.sqrt((HUD_SIZE * HUD_SIZE) / 2f)) - 1f; 79 | 80 | /** 81 | * Returns the threshold of distance between rendered and current player position after which to update the map. 82 | * Greater if the map is north-locked, as there is a larger margin around the map. 83 | */ 84 | public float getMovementThreshold() { 85 | return this.config.isNorthLocked() ? THRESHOLD_NORTH_LOCKED : THRESHOLD_ROTATED; 86 | } 87 | 88 | public void updateTexture(WorldMap map) { 89 | if (!this.isVisible() || this.client.currentScreen != null && this.client.currentScreen.isPauseScreen()) 90 | return; 91 | if (!this.dirty) return; 92 | else this.dirty = false; 93 | 94 | int width = this.texture.getImage().getWidth(); 95 | int height = this.texture.getImage().getHeight(); 96 | var corner = this.client.player.getBlockPos().add(-(width / 2), 0, -(height / 2)); 97 | 98 | for (int z = 0; z < width; ++z) { 99 | int absoluteZ = corner.getZ() + z; 100 | 101 | for (int x = 0; x < height; ++x) { 102 | int absoluteX = corner.getX() + x; 103 | this.texture.getImage().setPixelColor(x, z, map.getRenderColor(absoluteX, absoluteZ, ChunkGetterMode.LOAD)); 104 | } 105 | } 106 | 107 | this.texture.upload(); 108 | this.renderPosX = this.client.player.getBlockPos().getX(); 109 | this.renderPosZ = this.client.player.getBlockPos().getZ(); 110 | } 111 | 112 | public void render(GuiGraphics graphics, int light, float delta) { 113 | if (!this.isVisible() || this.client.currentScreen != null && this.client.currentScreen.isPauseScreen()) 114 | return; 115 | 116 | float scaleFactor = (float) this.client.getWindow().getScaleFactor(); 117 | float newScaleFactor = this.config.getHudScale(); 118 | float scaleCompensation = newScaleFactor / scaleFactor; 119 | 120 | int width = (int) (this.client.getWindow().getFramebufferWidth() / scaleFactor); 121 | graphics.getMatrices().push(); 122 | graphics.getMatrices().translate(width - HUD_SIZE * scaleCompensation, 0, -20); 123 | graphics.getMatrices().scale(scaleCompensation, scaleCompensation, 1); 124 | 125 | var immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBufferBuilder()); 126 | 127 | HudDecorator decorator = this.config.getHudDecorator(); 128 | int margin = decorator.getMargin(); 129 | 130 | graphics.getMatrices().translate(-margin * 2, 0, -1); 131 | 132 | graphics.getMatrices().push(); 133 | if (!this.client.options.debugEnabled) { 134 | RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f); 135 | } else { 136 | RenderSystem.setShaderColor(0.25f, 0.25f, 0.25f, 0.5f); 137 | } 138 | decorator.render(graphics, immediate, HUD_SIZE + margin * 2, HUD_SIZE + margin * 2); 139 | graphics.getMatrices().pop(); 140 | 141 | graphics.getMatrices().translate(margin, margin, 1); 142 | 143 | { 144 | int i = (int) ((double) this.client.getWindow().getFramebufferWidth() / newScaleFactor); 145 | int scaledWidth = (double) this.client.getWindow().getFramebufferWidth() / newScaleFactor > (double) i ? i + 1 : i; 146 | ScissorManager.push(scaledWidth - HUD_SIZE - margin, margin, HUD_SIZE, HUD_SIZE, newScaleFactor); 147 | } 148 | 149 | int textureWidth = this.texture.getImage().getWidth(); 150 | int textureHeight = this.texture.getImage().getHeight(); 151 | 152 | graphics.getMatrices().push(); 153 | 154 | float uStart = 0.f; 155 | float uEnd = 1.f; 156 | float vStart = 0.f; 157 | float vEnd = 1.f; 158 | if (!this.config.isNorthLocked()) { 159 | graphics.getMatrices().translate(64, 64, 0); 160 | graphics.getMatrices().multiply(Axis.Z_POSITIVE.rotationDegrees(-this.client.player.getYaw(delta) + 180)); 161 | graphics.getMatrices().translate(-64, -64, 0); 162 | } 163 | // Translate so map is centred 164 | graphics.getMatrices().translate(-32, -32, 0); 165 | 166 | // Translate by offset from position that map was last rendered from 167 | var lerped = this.client.player.getLerpedPos(delta); 168 | float offsetX = (float) (renderPosX - lerped.getX()); 169 | float offsetZ = (float) (renderPosZ - lerped.getZ()); 170 | graphics.getMatrices().translate(offsetX, offsetZ, 0); 171 | 172 | var model = graphics.getMatrices().peek().getModel(); 173 | var vertices = immediate.getBuffer(this.mapRenderLayer); 174 | WorldMapRenderer.vertex(vertices, model, 0.f, textureHeight, uStart, vEnd, light); 175 | WorldMapRenderer.vertex(vertices, model, textureWidth, textureHeight, uEnd, vEnd, light); 176 | WorldMapRenderer.vertex(vertices, model, textureWidth, 0.f, uEnd, vStart, light); 177 | WorldMapRenderer.vertex(vertices, model, 0.f, 0.f, uStart, vStart, light); 178 | 179 | { 180 | int cornerX = renderPosX - (textureWidth / 2); 181 | int cornerZ = renderPosZ - (textureHeight / 2); 182 | LambdaMap.get().getMap().getMarkerManager().forEachInBox(cornerX, cornerZ, textureWidth, textureHeight, marker -> { 183 | graphics.getMatrices().push(); 184 | 185 | float x = (float) (marker.getX() - cornerX); 186 | float z = (float) (marker.getZ() - cornerZ); 187 | 188 | graphics.getMatrices().translate(x, z, 1.f); 189 | if (!this.config.isNorthLocked()) 190 | graphics.getMatrices().multiply(Axis.Z_POSITIVE.rotationDegrees(this.client.player.getYaw(delta) - 180)); 191 | marker.getType().render(graphics, immediate, marker.getRotation(), marker.getName(), light); 192 | graphics.getMatrices().pop(); 193 | }); 194 | } 195 | graphics.getMatrices().pop(); 196 | 197 | this.renderPlayerIcon(graphics, immediate, light, delta); 198 | immediate.draw(); 199 | 200 | ScissorManager.pop(); 201 | 202 | if (this.config.isDirectionIndicatorsVisible()) { 203 | if (this.config.isNorthLocked()) { 204 | this.renderStaticCompassIndicators(graphics.getMatrices(), immediate, light); 205 | } else { 206 | this.renderDynamicCompassIndicators(graphics.getMatrices(), immediate, light, delta); 207 | } 208 | immediate.draw(); 209 | } 210 | 211 | if (!this.client.options.debugEnabled) { 212 | var pos = this.client.player.getBlockPos(); 213 | var str = String.format("X: %d Y: %d Z: %d", pos.getX(), pos.getY(), pos.getZ()); 214 | int strWidth = this.client.textRenderer.getWidth(str); 215 | this.client.textRenderer.draw(str, 64 - strWidth / 2.f, 130 + decorator.getCoordinatesOffset(), ColorUtil.WHITE, true, 216 | graphics.getMatrices().peek().getModel(), immediate, TextRenderer.TextLayerType.NORMAL, 0, light); 217 | immediate.draw(); 218 | } else { 219 | graphics.getMatrices().translate(0.f, 0.f, 1.2f); 220 | graphics.fill(0, 0, 128, 128, 0x88000000); 221 | } 222 | graphics.getMatrices().pop(); 223 | ScissorManager.popScaleFactor(); 224 | } 225 | 226 | private void renderPlayerIcon(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, int light, float delta) { 227 | graphics.getMatrices().push(); 228 | graphics.getMatrices().translate(64.f, 64.f, 1.1f); 229 | MarkerType.PLAYER.render(graphics, vertexConsumers, this.config.isNorthLocked() ? this.client.player.getYaw(delta) : 180, null, light); 230 | graphics.getMatrices().pop(); 231 | } 232 | 233 | private void renderStaticCompassIndicators(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { 234 | int fontHeight = this.client.textRenderer.fontHeight; 235 | this.client.textRenderer.draw(NORTH, 64 - this.client.textRenderer.getWidth(NORTH) / 2.f, 0, 0xffff0000, true, 236 | matrices.peek().getModel(), vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, light); 237 | this.client.textRenderer.draw(SOUTH, 64 - this.client.textRenderer.getWidth(SOUTH) / 2.f, HUD_SIZE - fontHeight, ColorUtil.WHITE, true, 238 | matrices.peek().getModel(), vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, light); 239 | this.client.textRenderer.draw(EAST, HUD_SIZE - this.client.textRenderer.getWidth(EAST), 64 - fontHeight / 2.f, ColorUtil.WHITE, true, 240 | matrices.peek().getModel(), vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, light); 241 | this.client.textRenderer.draw(WEST, 0, 64 - fontHeight / 2.f, ColorUtil.WHITE, true, 242 | matrices.peek().getModel(), vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, light); 243 | } 244 | 245 | private void renderDynamicCompassIndicators(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float delta) { 246 | float yaw = this.client.player.getYaw(delta); 247 | 248 | this.renderCompassIndicator(matrices, vertexConsumers, WEST, light, yaw); 249 | this.renderCompassIndicator(matrices, vertexConsumers, NORTH, light, yaw - 90); 250 | this.renderCompassIndicator(matrices, vertexConsumers, EAST, light, yaw - 180); 251 | this.renderCompassIndicator(matrices, vertexConsumers, SOUTH, light, yaw + 90); 252 | } 253 | 254 | private void renderCompassIndicator(MatrixStack matrices, VertexConsumerProvider vertexConsumers, Text text, int light, float yaw) { 255 | float x = (64 + 32) * MathHelper.cos(-yaw / 360 * MathHelper.TAU) + 64; 256 | float y = (64 + 32) * MathHelper.sin(-yaw / 360 * MathHelper.TAU) + 64; 257 | 258 | x = MathHelper.clamp(x, 0, HUD_SIZE - this.client.textRenderer.getWidth(text)); 259 | y = MathHelper.clamp(y, 0, HUD_SIZE - this.client.textRenderer.fontHeight); 260 | 261 | this.client.textRenderer.draw(text, x, y, text == NORTH ? 0xffff0000 : ColorUtil.WHITE, true, 262 | matrices.peek().getModel(), vertexConsumers, TextRenderer.TextLayerType.NORMAL, 0, light); 263 | } 264 | 265 | @Override 266 | public void close() { 267 | this.texture.close(); 268 | } 269 | } 270 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/map/WorldMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.map; 19 | 20 | import dev.lambdaurora.lambdamap.LambdaMap; 21 | import dev.lambdaurora.lambdamap.gui.WorldMapScreen; 22 | import dev.lambdaurora.lambdamap.map.marker.Marker; 23 | import dev.lambdaurora.lambdamap.map.marker.MarkerManager; 24 | import dev.lambdaurora.lambdamap.map.marker.MarkerType; 25 | import dev.lambdaurora.lambdamap.map.storage.MapRegionFile; 26 | import dev.lambdaurora.lambdamap.mixin.MapColorAccessor; 27 | import dev.lambdaurora.lambdamap.util.ClientWorldWrapper; 28 | import dev.lambdaurora.spruceui.util.ColorUtil; 29 | import it.unimi.dsi.fastutil.longs.Long2ObjectMap; 30 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; 31 | import net.minecraft.block.MapColor; 32 | import net.minecraft.client.MinecraftClient; 33 | import net.minecraft.item.map.MapState; 34 | import net.minecraft.registry.DynamicRegistryManager; 35 | import net.minecraft.registry.Registry; 36 | import net.minecraft.registry.RegistryKeys; 37 | import net.minecraft.util.math.BlockPos; 38 | import net.minecraft.util.math.ChunkPos; 39 | import net.minecraft.util.math.ChunkSectionPos; 40 | import net.minecraft.world.World; 41 | import net.minecraft.world.biome.Biome; 42 | import org.apache.logging.log4j.LogManager; 43 | import org.apache.logging.log4j.Logger; 44 | import org.jetbrains.annotations.Nullable; 45 | 46 | import java.io.File; 47 | import java.io.IOException; 48 | import java.util.List; 49 | import java.util.concurrent.Executors; 50 | import java.util.concurrent.ScheduledExecutorService; 51 | 52 | /** 53 | * Represents the world map. 54 | * 55 | * @author LambdAurora 56 | * @version 1.0.0 57 | * @since 1.0.0 58 | */ 59 | public class WorldMap { 60 | private static final Logger LOGGER = LogManager.getLogger(); 61 | 62 | private static final int VIEW_RANGE = 10000; 63 | 64 | private final Long2ObjectMap regionFiles = new Long2ObjectOpenHashMap<>(); 65 | private final Long2ObjectMap chunks = new Long2ObjectOpenHashMap<>(); 66 | private final MinecraftClient client = MinecraftClient.getInstance(); 67 | private final File directory; 68 | private final MarkerManager markerManager; 69 | 70 | final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); 71 | 72 | private final World world; 73 | 74 | private double viewX = 0; 75 | private double viewZ = 0; 76 | private double playerViewX = 0; 77 | private double playerViewZ = 0; 78 | 79 | public WorldMap(World world, File directory) { 80 | this.directory = directory; 81 | if (!this.directory.exists()) 82 | this.directory.mkdirs(); 83 | this.markerManager = new MarkerManager(this); 84 | this.markerManager.load(); 85 | 86 | this.world = world; 87 | } 88 | 89 | public File getDirectory() { 90 | return this.directory; 91 | } 92 | 93 | public MarkerManager getMarkerManager() { 94 | return this.markerManager; 95 | } 96 | 97 | public World getWorld() { 98 | return this.world; 99 | } 100 | 101 | public DynamicRegistryManager getRegistryManager() { 102 | return this.world.getRegistryManager(); 103 | } 104 | 105 | public Registry getBiomeRegistry() { 106 | return this.getRegistryManager().get(RegistryKeys.BIOME); 107 | } 108 | 109 | public double getViewX() { 110 | return this.viewX; 111 | } 112 | 113 | public double getViewZ() { 114 | return this.viewZ; 115 | } 116 | 117 | public boolean updateViewPos(double viewX, double viewZ) { 118 | boolean changed = viewX != this.viewX || viewZ != this.viewZ; 119 | this.viewX = viewX; 120 | this.viewZ = viewZ; 121 | return changed; 122 | } 123 | 124 | public boolean updatePlayerViewPos(int viewX, int viewZ, float threshold) { 125 | if (Math.abs(viewX - this.playerViewX) > threshold || Math.abs(viewZ - this.playerViewZ) > threshold) { 126 | this.playerViewX = viewX; 127 | this.playerViewZ = viewZ; 128 | if (!(client.currentScreen instanceof WorldMapScreen)) 129 | this.updateViewPos(viewX, viewZ); 130 | return true; 131 | } else { 132 | return false; 133 | } 134 | } 135 | 136 | /** 137 | * Returns the ARGB color at the specified coordinates. 138 | *

139 | * Coordinates are absolute. 140 | * 141 | * @param x the X coordinate 142 | * @param z the Z coordinate 143 | * @param mode the chunk getter mode 144 | * @return the ARGB color 145 | */ 146 | public int getRenderColor(int x, int z, ChunkGetterMode mode) { 147 | var chunk = mode.getChunk(this, MapChunk.blockToChunk(x), MapChunk.blockToChunk(z)); 148 | if (chunk == null || chunk.isEmpty()) 149 | return 0; 150 | int index = chunk.getIndex(x, z); 151 | int color = chunk.getColor(index) & 255; 152 | if (color / 4 == 0) 153 | return 0; 154 | else { 155 | var mapColor = MapColorAccessor.getColors()[color / 4]; 156 | if (LambdaMap.get().getConfig().shouldRenderBiomeColors()) { 157 | if (mapColor == MapColor.WATER) { 158 | var biome = chunk.getBiome(index); 159 | if (biome != null) { 160 | return this.calculateWaterColor(x, z, biome, color & 3, mode); 161 | } 162 | } else { 163 | var state = chunk.getBlockState(index); 164 | if (state != null) { 165 | int argb = 0xff000000 | this.client.getBlockColors().getColor(state, new ClientWorldWrapper(this.client.world, chunk), new BlockPos(x, 64, z), 0); 166 | return applyShade(ColorUtil.argbMultiply(argb, 0xffb9bcb9), color & 3); 167 | } 168 | } 169 | } 170 | return applyShade(mapColor.color, color & 3); 171 | } 172 | } 173 | 174 | private int calculateWaterColor(int x, int z, Biome sourceBiome, int shade, ChunkGetterMode mode) { 175 | int biomeBlendRadius = this.client.options.getBiomeBlendRadius().get(); 176 | if (biomeBlendRadius == 0) { 177 | return applyShade(ColorUtil.argbDarken(sourceBiome.getWaterColor()), shade); 178 | } else { 179 | biomeBlendRadius = 2; 180 | int multiplier = (biomeBlendRadius * 2 + 1) * (biomeBlendRadius * 2 + 1); 181 | int r = 0; 182 | int g = 0; 183 | int b = 0; 184 | 185 | for (int offsetZ = -biomeBlendRadius; offsetZ < biomeBlendRadius; offsetZ++) { 186 | int resolveZ = z + offsetZ; 187 | for (int offsetX = -biomeBlendRadius; offsetX < biomeBlendRadius; offsetX++) { 188 | int resolveX = x + offsetX; 189 | var chunk = mode.getChunk(this, MapChunk.blockToChunk(resolveX), MapChunk.blockToChunk(resolveZ)); 190 | if (chunk != null) { 191 | var biome = chunk.getBiome(chunk.getIndex(resolveX, resolveZ)); 192 | if (biome != null) { 193 | int waterColor = biome.getWaterColor(); 194 | r += (waterColor & 0x00ff0000) >> 16; 195 | g += (waterColor & 0x0000ff00) >> 8; 196 | b += waterColor & 0xff; 197 | } 198 | } else multiplier--; 199 | } 200 | } 201 | 202 | return applyShade(ColorUtil.packARGBColor(r / multiplier & 255, g / multiplier & 255, b / multiplier & 255, 0xff), shade); 203 | } 204 | } 205 | 206 | private static int applyShade(int color, int shade) { 207 | int modifier = 220; 208 | if (shade == 3) { 209 | modifier = 135; 210 | } 211 | 212 | if (shade == 2) { 213 | modifier = 255; 214 | } 215 | 216 | if (shade == 0) { 217 | modifier = 180; 218 | } 219 | 220 | int j = (color >> 16 & 255) * modifier / 255; 221 | int k = (color >> 8 & 255) * modifier / 255; 222 | int l = (color & 255) * modifier / 255; 223 | return -16777216 | l << 16 | k << 8 | j; 224 | } 225 | 226 | public @Nullable MapChunk getChunk(int x, int z) { 227 | return this.getChunk(ChunkPos.toLong(x, z)); 228 | } 229 | 230 | public @Nullable MapChunk getChunk(long pos) { 231 | return this.chunks.get(pos); 232 | } 233 | 234 | public @Nullable MapChunk getChunkOrLoad(int x, int z) { 235 | return this.getChunkOrLoad(ChunkPos.toLong(x, z)); 236 | } 237 | 238 | public @Nullable MapChunk getChunkOrLoad(long pos) { 239 | var chunk = this.getChunk(pos); 240 | if (chunk == null) { 241 | int x = ChunkPos.getPackedX(pos); 242 | int z = ChunkPos.getPackedZ(pos); 243 | chunk = MapChunk.load(this, x, z); 244 | if (chunk != null) 245 | this.chunks.put(pos, chunk); 246 | } 247 | return chunk; 248 | } 249 | 250 | public MapChunk getChunkOrCreate(int x, int z) { 251 | long pos = ChunkPos.toLong(x, z); 252 | var chunk = this.getChunk(pos); 253 | if (chunk == null) { 254 | chunk = MapChunk.loadOrCreate(this, x, z); 255 | this.chunks.put(pos, chunk); 256 | } 257 | return chunk; 258 | } 259 | 260 | public MapChunk getChunkOrCreate(long pos) { 261 | var chunk = this.getChunk(pos); 262 | if (chunk == null) { 263 | int x = ChunkPos.getPackedX(pos); 264 | int z = ChunkPos.getPackedZ(pos); 265 | chunk = MapChunk.loadOrCreate(this, x, z); 266 | this.chunks.put(pos, chunk); 267 | } 268 | return chunk; 269 | } 270 | 271 | public @Nullable MapRegionFile getOrLoadRegion(int x, int z) { 272 | x = MapChunk.chunkToRegion(x); 273 | z = MapChunk.chunkToRegion(z); 274 | long pos = ChunkPos.toLong(x, z); 275 | var regionFile = this.regionFiles.get(pos); 276 | 277 | if (regionFile == null) { 278 | try { 279 | regionFile = MapRegionFile.load(this, x, z); 280 | if (regionFile != null) 281 | this.regionFiles.put(pos, regionFile); 282 | } catch (IOException e) { 283 | LOGGER.error("Could not load or create region file (" + x + ", " + z + ")", e); 284 | return null; 285 | } 286 | } 287 | 288 | return regionFile; 289 | } 290 | 291 | public MapRegionFile getOrCreateRegion(int x, int z) { 292 | x = MapChunk.chunkToRegion(x); 293 | z = MapChunk.chunkToRegion(z); 294 | long pos = ChunkPos.toLong(x, z); 295 | var regionFile = this.regionFiles.get(pos); 296 | 297 | if (regionFile == null) { 298 | try { 299 | regionFile = MapRegionFile.loadOrCreate(this, x, z); 300 | this.regionFiles.put(pos, regionFile); 301 | } catch (IOException e) { 302 | LOGGER.error("Could not load or create region file (" + x + ", " + z + ")", e); 303 | return null; 304 | } 305 | } 306 | 307 | return regionFile; 308 | } 309 | 310 | public void unloadRegion(MapRegionFile regionFile) { 311 | this.regionFiles.remove(ChunkPos.toLong(regionFile.getX(), regionFile.getZ())); 312 | } 313 | 314 | public void importMapState(MapState mapState, List markers) { 315 | int scale = 1 << mapState.scale; 316 | 317 | int cornerX = mapState.centerX - 64 * scale; 318 | int cornerZ = mapState.centerZ - 64 * scale; 319 | 320 | var marker = markers.get(0); 321 | for (var icon : mapState.getIcons()) { 322 | if (marker.getType() == MarkerType.getVanillaMarkerType(icon.getType())) { 323 | int iconX = (int) (icon.getX() / 2.f + 64) * scale; 324 | int iconZ = (int) (icon.getZ() / 2.f + 64) * scale; 325 | 326 | cornerX = marker.getX() - iconX; 327 | cornerZ = marker.getZ() - iconZ; 328 | } 329 | } 330 | 331 | for (int z = 0; z < 128 * scale; z++) { 332 | int i = z / scale; 333 | int chunkZ = MapChunk.blockToChunk(cornerZ + z); 334 | 335 | for (int x = 0; x < 128 * scale; x++) { 336 | byte color = mapState.colors[x / scale + i * 128]; 337 | if (color / 4 == 0) 338 | continue; 339 | 340 | int chunkX = MapChunk.blockToChunk(cornerX + x); 341 | var chunk = this.getChunkOrCreate(chunkX, chunkZ); 342 | 343 | if (chunk.getColor(cornerX + x, cornerZ + z) / 4 == 0) { 344 | chunk.putColor(cornerX + x, cornerZ + z, color); 345 | } 346 | } 347 | } 348 | } 349 | 350 | public void tick() { 351 | var client = MinecraftClient.getInstance(); 352 | int viewDistance = Math.max(2, client.options.getEffectiveViewDistance() - 2); 353 | 354 | int chunkX = ChunkSectionPos.getSectionCoord(this.playerViewX); 355 | int chunkZ = ChunkSectionPos.getSectionCoord(this.playerViewZ); 356 | 357 | int playerViewStartX = (chunkX - viewDistance) >> 3; 358 | int playerViewStartZ = (chunkZ - viewDistance) >> 3; 359 | int playerViewEndX = (chunkX + viewDistance) >> 3; 360 | int playerViewEndZ = (chunkZ + viewDistance) >> 3; 361 | 362 | int viewStartX = (int) (this.viewX - VIEW_RANGE); 363 | int viewStartZ = (int) (this.viewZ - VIEW_RANGE); 364 | int viewEndX = (int) (this.viewX + VIEW_RANGE); 365 | int viewEndZ = (int) (this.viewZ + VIEW_RANGE); 366 | 367 | boolean hasViewer = this.viewX != this.playerViewX || this.viewZ != this.playerViewZ; 368 | this.chunks.values().removeIf(chunk -> { 369 | if (!((chunk.getX() >= playerViewStartX && chunk.getX() <= playerViewEndX && chunk.getZ() >= playerViewStartZ && chunk.getZ() <= playerViewEndZ) 370 | || (hasViewer && chunk.isCenterInBox(viewStartX, viewStartZ, viewEndX, viewEndZ)))) { 371 | chunk.unload(); 372 | return true; 373 | } 374 | return false; 375 | }); 376 | 377 | this.getMarkerManager().tick(this.world); 378 | } 379 | 380 | public void unload() { 381 | this.service.shutdown(); 382 | this.markerManager.save(); 383 | this.chunks.forEach((pos, chunk) -> chunk.unload()); 384 | this.chunks.clear(); 385 | this.regionFiles.clear(); 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /src/main/java/dev/lambdaurora/lambdamap/gui/WorldMapRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 LambdAurora 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | package dev.lambdaurora.lambdamap.gui; 19 | 20 | import com.mojang.blaze3d.systems.RenderSystem; 21 | import com.mojang.blaze3d.vertex.VertexConsumer; 22 | import dev.lambdaurora.lambdamap.LambdaMap; 23 | import dev.lambdaurora.lambdamap.map.ChunkGetterMode; 24 | import dev.lambdaurora.lambdamap.map.MapChunk; 25 | import dev.lambdaurora.lambdamap.map.WorldMap; 26 | import dev.lambdaurora.lambdamap.map.marker.MarkerType; 27 | import net.minecraft.client.MinecraftClient; 28 | import net.minecraft.client.gui.GuiGraphics; 29 | import net.minecraft.client.render.LightmapTextureManager; 30 | import net.minecraft.client.render.RenderLayer; 31 | import net.minecraft.client.render.VertexConsumerProvider; 32 | import net.minecraft.client.texture.NativeImageBackedTexture; 33 | import org.apache.logging.log4j.LogManager; 34 | import org.apache.logging.log4j.Logger; 35 | import org.joml.Matrix4f; 36 | 37 | import java.util.ArrayList; 38 | import java.util.List; 39 | import java.util.Objects; 40 | 41 | /** 42 | * Represents the world map renderer. 43 | * 44 | * @author LambdAurora 45 | * @version 1.0.0 46 | * @since 1.0.0 47 | */ 48 | public class WorldMapRenderer { 49 | private static final Logger LOGGER = LogManager.getLogger(); 50 | 51 | /** 52 | * Stores all the registered world map chunk textures. 53 | */ 54 | private static final List TEXTURES = new ArrayList<>(); 55 | 56 | private int width; 57 | private int height; 58 | 59 | private WorldMap worldMap; 60 | 61 | private ChunkTextureManager textureManager; 62 | 63 | private int cornerViewX; 64 | private int cornerViewZ; 65 | 66 | private int scale = 1; 67 | 68 | public WorldMapRenderer(LambdaMap mod) { 69 | 70 | } 71 | 72 | public WorldMap worldMap() { 73 | return this.worldMap; 74 | } 75 | 76 | public void setWorldMap(WorldMap worldMap) { 77 | this.worldMap = worldMap; 78 | 79 | this.updateView(worldMap.getViewX(), worldMap.getViewZ(), true); 80 | } 81 | 82 | public void allocate(int width, int height) { 83 | this.width = width; 84 | this.height = height; 85 | this.scale = 1; 86 | 87 | int texturesX = this.width / 128 + 2; 88 | int texturesZ = this.height / 128 + 2; 89 | 90 | this.textureManager = new ChunkTextureManager(texturesZ, texturesX); 91 | } 92 | 93 | public void scale(int scale) { 94 | this.scale = 1 << scale; 95 | 96 | if (this.worldMap != null) { 97 | double x = this.worldMap.getViewX(); 98 | double z = this.worldMap.getViewZ(); 99 | 100 | this.worldMap.updateViewPos(x, z); 101 | 102 | this.cornerViewX = (int) (x - (this.scaledWidth() / 2)); 103 | this.cornerViewZ = (int) (z - (this.scaledHeight() / 2)); 104 | 105 | if (this.textureManager != null) { 106 | this.textureManager.updateTextures(true); 107 | } 108 | } 109 | } 110 | 111 | public int scale() { 112 | return this.scale; 113 | } 114 | 115 | /** 116 | * Returns the X coordinate of the north-west corner. 117 | * 118 | * @return the corner block X coordinate 119 | */ 120 | public int cornerX() { 121 | return this.cornerViewX; 122 | } 123 | 124 | /** 125 | * Returns the Z coordinate of the north-west corner. 126 | * 127 | * @return the corner block Z coordinate 128 | */ 129 | public int cornerZ() { 130 | return this.cornerViewZ; 131 | } 132 | 133 | public int getCornerMapChunkX() { 134 | return MapChunk.blockToChunk(this.cornerViewX); 135 | } 136 | 137 | public int getCornerMapChunkZ() { 138 | return MapChunk.blockToChunk(this.cornerViewZ); 139 | } 140 | 141 | /** 142 | * Returns the width of the area. 143 | * 144 | * @return the width 145 | */ 146 | public int width() { 147 | return this.width; 148 | } 149 | 150 | public int scaledWidth() { 151 | return this.width() * this.scale(); 152 | } 153 | 154 | /** 155 | * Returns the height of the area. 156 | * 157 | * @return the height 158 | */ 159 | public int height() { 160 | return this.height; 161 | } 162 | 163 | public int scaledHeight() { 164 | return this.height() * this.scale(); 165 | } 166 | 167 | public void updateView(double x, double z) { 168 | this.updateView(x, z, false); 169 | } 170 | 171 | public void updateView(double x, double z, boolean forceUpdate) { 172 | this.worldMap.updateViewPos(x, z); 173 | 174 | x -= (this.scaledWidth() / 2); 175 | z -= (this.scaledHeight() / 2); 176 | 177 | boolean shouldUpdate = false; 178 | if (this.cornerViewX != x && this.textureManager != null) { 179 | int oldChunkX = this.getCornerMapChunkX(); 180 | int newChunkX = MapChunk.blockToChunk((int) x); 181 | 182 | if (oldChunkX != newChunkX) { 183 | int offset = Math.abs(newChunkX - oldChunkX); 184 | if (newChunkX < oldChunkX) for (int i = 0; i < offset; i++) this.textureManager.shiftRight(); 185 | else for (int i = 0; i < offset; i++) this.textureManager.shiftLeft(); 186 | shouldUpdate = true; 187 | } 188 | } 189 | 190 | if (this.cornerViewZ != z && this.textureManager != null) { 191 | int oldChunkZ = this.getCornerMapChunkZ(); 192 | int newChunkZ = MapChunk.blockToChunk((int) z); 193 | 194 | if (oldChunkZ != newChunkZ) { 195 | int offset = Math.abs(newChunkZ - oldChunkZ); 196 | if (newChunkZ < oldChunkZ) for (int i = 0; i < offset; i++) this.textureManager.shiftDown(); 197 | else for (int i = 0; i < offset; i++) this.textureManager.shiftUp(); 198 | shouldUpdate = true; 199 | } 200 | } 201 | 202 | this.cornerViewX = (int) x; 203 | this.cornerViewZ = (int) z; 204 | 205 | if (shouldUpdate || forceUpdate) 206 | this.update(forceUpdate); 207 | } 208 | 209 | public void update(boolean forceRedraw) { 210 | if (this.textureManager != null) { 211 | this.textureManager.updateTextures(forceRedraw); 212 | } 213 | } 214 | 215 | public void render(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, float delta) { 216 | graphics.fill(0, 0, this.width, this.height, 0x44000000); 217 | 218 | int light = LightmapTextureManager.pack(15, 15); 219 | this.textureManager.render(graphics, vertexConsumers, light); 220 | 221 | this.worldMap.getMarkerManager().forEachInBox(this.cornerViewX - 5, this.cornerViewZ - 5, 222 | this.scaledWidth() + 10, this.scaledHeight() + 10, 223 | marker -> marker.render(graphics, vertexConsumers, this.cornerViewX, this.cornerViewZ, this.scale, light)); 224 | 225 | this.renderPlayerIcon(graphics, vertexConsumers, light, delta); 226 | } 227 | 228 | private void renderPlayerIcon(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, int light, float delta) { 229 | var client = MinecraftClient.getInstance(); 230 | 231 | var pos = client.player.getBlockPos(); 232 | 233 | if (this.cornerViewX > pos.getX() || this.cornerViewZ > pos.getZ() 234 | || this.cornerViewX + this.scaledWidth() < pos.getX() || this.cornerViewZ + this.scaledHeight() < pos.getZ()) 235 | return; 236 | 237 | graphics.getMatrices().push(); 238 | graphics.getMatrices().translate((pos.getX() - this.cornerViewX) / (float) this.scale, (pos.getZ() - this.cornerViewZ) / (float) this.scale, 1.1f); 239 | MarkerType.PLAYER.render(graphics, vertexConsumers, client.player.getYaw(delta), null, light); 240 | graphics.getMatrices().pop(); 241 | } 242 | 243 | public static void vertex( 244 | VertexConsumer vertices, Matrix4f model, 245 | float x, float y, 246 | float u, float v, 247 | int light 248 | ) { 249 | vertices.vertex(model, x, y, 0.f).color(255, 255, 255, 255) 250 | .uv(u, v).light(light).next(); 251 | } 252 | 253 | /** 254 | * Represents the chunk texture manager. Manages all the world map textures and re-position them if needed. 255 | * 256 | * @version 1.0.0 257 | * @since 1.0.0 258 | */ 259 | class ChunkTextureManager { 260 | private final ChunkTexture[][] textures; 261 | 262 | public ChunkTextureManager(int texturesZ, int texturesX) { 263 | this.textures = new ChunkTexture[texturesZ][texturesX]; 264 | 265 | for (int z = 0; z < this.textures.length; z++) { 266 | ChunkTexture[] line = this.textures[z]; 267 | for (int x = 0; x < line.length; x++) { 268 | int index = z * line.length + x; 269 | ChunkTexture texture; 270 | if (TEXTURES.size() <= index) { 271 | texture = new ChunkTexture(); 272 | } else { 273 | texture = TEXTURES.get(index); 274 | } 275 | line[x] = texture; 276 | } 277 | } 278 | } 279 | 280 | public void shiftUp() { 281 | ChunkTexture[] firstLine = this.textures[0]; 282 | 283 | System.arraycopy(this.textures, 1, this.textures, 0, this.textures.length - 1); 284 | 285 | this.textures[this.textures.length - 1] = firstLine; 286 | } 287 | 288 | public void shiftDown() { 289 | ChunkTexture[] lastLine = this.textures[this.textures.length - 1]; 290 | 291 | System.arraycopy(this.textures, 0, this.textures, 1, this.textures.length - 1); 292 | 293 | this.textures[0] = lastLine; 294 | } 295 | 296 | public void shiftLeft() { 297 | for (var line : this.textures) { 298 | ChunkTexture first = line[0]; 299 | System.arraycopy(line, 1, line, 0, line.length - 1); 300 | line[line.length - 1] = first; 301 | } 302 | } 303 | 304 | public void shiftRight() { 305 | for (var line : this.textures) { 306 | ChunkTexture last = line[line.length - 1]; 307 | System.arraycopy(line, 0, line, 1, line.length - 1); 308 | line[0] = last; 309 | } 310 | } 311 | 312 | public void updateTextures(boolean forceRedraw) { 313 | int chunkX = WorldMapRenderer.this.getCornerMapChunkX(); 314 | int chunkZ = WorldMapRenderer.this.getCornerMapChunkZ(); 315 | 316 | int scale = WorldMapRenderer.this.scale; 317 | int count = 0; 318 | 319 | long start = System.currentTimeMillis(); 320 | for (int z = 0; z < this.textures.length; z++) { 321 | ChunkTexture[] line = this.textures[z]; 322 | for (int x = 0; x < line.length; x++) { 323 | if (forceRedraw) 324 | line[x].resetCache(); 325 | line[x].update(WorldMapRenderer.this.worldMap, chunkX + x * scale, chunkZ + z * scale, scale); 326 | count++; 327 | } 328 | } 329 | 330 | LOGGER.debug("Took {}ms to update {} textures.", (System.currentTimeMillis() - start), count); 331 | } 332 | 333 | public void render(GuiGraphics graphics, VertexConsumerProvider vertexConsumers, int light) { 334 | int scale = WorldMapRenderer.this.scale; 335 | float originX = -((WorldMapRenderer.this.cornerViewX & 127) / (float) scale); 336 | float originZ = -((WorldMapRenderer.this.cornerViewZ & 127) / (float) scale); 337 | int offsetZ = (int) -originZ; 338 | 339 | for (int z = 0; z < this.textures.length; z++) { 340 | ChunkTexture[] line = this.textures[z]; 341 | 342 | if (originZ + z * 128 > WorldMapRenderer.this.height) 343 | break; 344 | 345 | int offsetX = (int) -originX; 346 | float height = 128; 347 | 348 | if (originZ + z * 128 + height > WorldMapRenderer.this.height) { 349 | height = WorldMapRenderer.this.height - (originZ + z * 128); 350 | } 351 | 352 | for (int x = 0; x < line.length; x++) { 353 | if (originX + x * 128 > WorldMapRenderer.this.width) 354 | break; 355 | 356 | float width = 128; 357 | 358 | if (originX + x * 128 + width > WorldMapRenderer.this.width) { 359 | width = WorldMapRenderer.this.width - (originX + x * 128); 360 | } 361 | 362 | line[x].render(graphics, vertexConsumers, Math.round(originX + x * 128), Math.round(originZ + z * 128), offsetX, offsetZ, width, height, light); 363 | offsetX = 0; 364 | } 365 | 366 | offsetZ = 0; 367 | } 368 | } 369 | } 370 | 371 | /** 372 | * Represents a chunk texture. 373 | * 374 | * @version 1.0.0 375 | * @since 1.0.0 376 | */ 377 | static class ChunkTexture { 378 | private final NativeImageBackedTexture texture = new NativeImageBackedTexture(128, 128, true); 379 | private final RenderLayer mapRenderLayer; 380 | 381 | private int cachedState = 0; 382 | 383 | ChunkTexture() { 384 | var id = MinecraftClient.getInstance().getTextureManager().registerDynamicTexture("world_map", this.texture); 385 | this.mapRenderLayer = RenderLayer.getText(id); 386 | 387 | TEXTURES.add(this); 388 | } 389 | 390 | public void resetCache() { 391 | this.cachedState = 0; 392 | } 393 | 394 | public void update(WorldMap map, int chunkStartX, int chunkStartZ, int scale) { 395 | var paramState = Objects.hash(chunkStartX, chunkStartZ, scale); 396 | if (this.cachedState == paramState) 397 | return; 398 | 399 | this.cachedState = paramState; 400 | 401 | for (int textureZ = 0; textureZ < 128; textureZ++) { 402 | int z = textureZ * scale; 403 | int chunkZ = chunkStartZ + z / 128; 404 | for (int textureX = 0; textureX < 128; textureX++) { 405 | int x = textureX * scale; 406 | int chunkX = chunkStartX + x / 128; 407 | 408 | var opacity = 0xff000000; 409 | 410 | // Checkerboard rendering if needed. 411 | /* var regionX = MapChunk.chunkToRegion(chunkX); 412 | var regionZ = MapChunk.chunkToRegion(chunkZ); 413 | if ((chunkX & 2) != (chunkZ & 2)) { 414 | opacity = 0xdd000000; 415 | }*/ 416 | 417 | int renderColor = map.getRenderColor((chunkX << 7) + (x & 127), (chunkZ << 7) + (z & 127), 418 | ChunkGetterMode.CREATE); 419 | 420 | renderColor = opacity | (renderColor & 0x00ffffff); 421 | 422 | this.texture.getImage().setPixelColor(textureX, textureZ, renderColor); 423 | } 424 | } 425 | 426 | this.texture.upload(); 427 | } 428 | 429 | public void render( 430 | GuiGraphics graphics, VertexConsumerProvider vertexConsumers, 431 | float originX, float originY, 432 | int offsetX, int offsetY, 433 | float width, float height, int light 434 | ) { 435 | var model = graphics.getMatrices().peek().getModel(); 436 | var vertices = vertexConsumers.getBuffer(this.mapRenderLayer); 437 | 438 | float uOffset = offsetX / 128.f; 439 | float vOffset = offsetY / 128.f; 440 | float uWidth = width / 128.f; 441 | float vHeight = height / 128.f; 442 | 443 | float startX = originX + offsetX; 444 | float startY = originY + offsetY; 445 | float endX = originX + width; 446 | float endY = originY + height; 447 | 448 | vertex(vertices, model, startX, endY, 449 | uOffset, vHeight, light); 450 | vertex(vertices, model, endX, originY + height, 451 | uWidth, vHeight, light); 452 | vertex(vertices, model, endX, originY + offsetY, 453 | uWidth, vOffset, light); 454 | vertex(vertices, model, startX, startY, 455 | uOffset, vOffset, light); 456 | } 457 | } 458 | } 459 | --------------------------------------------------------------------------------