From 211ade96f561075e3e0b3617bc3f66faabe7541c Mon Sep 17 00:00:00 2001 From: Aleksey Date: Wed, 8 Jul 2020 09:58:29 +0300 Subject: [PATCH 1/4] Update SkinLoader.java --- .../justmap/map/minimap/skin/SkinLoader.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/ru/bulldog/justmap/map/minimap/skin/SkinLoader.java b/src/main/java/ru/bulldog/justmap/map/minimap/skin/SkinLoader.java index fd13396c..f480e60e 100644 --- a/src/main/java/ru/bulldog/justmap/map/minimap/skin/SkinLoader.java +++ b/src/main/java/ru/bulldog/justmap/map/minimap/skin/SkinLoader.java @@ -31,47 +31,47 @@ public static void loadSkins() { if (folder.isFile()) continue; File skinFile = new File(folder, "skin_data.json"); if (!skinFile.exists()) continue; - loadSkin(folder, skinFile); + try { + loadSkin(folder, skinFile); + } catch (Exception ex) { + JustMap.LOGGER.logWarning("Can't load skin: " + skinFile.getPath()); + JustMap.LOGGER.logWarning(ex.getLocalizedMessage()); + } } } - private static void loadSkin(File dir, File skinFile) { + private static void loadSkin(File folder, File skinFile) throws Exception { JsonObject skinData = loadJson(skinFile); - try { - String name = JsonHelper.getString(skinData, "name"); - int width = JsonHelper.getInt(skinData, "width"); - int height = JsonHelper.getInt(skinData, "height"); - int border = JsonHelper.getInt(skinData, "border"); - SkinType shape = getSkinType(JsonHelper.getString(skinData, "shape", "universal")); - boolean resizable = JsonHelper.getBoolean(skinData, "resizable", false); - boolean repeating = JsonHelper.getBoolean(skinData, "repeating", false); - String textureType = JsonHelper.getString(skinData, "texture_type"); - if (textureType.equals("source")) { - Identifier texture = new Identifier(JsonHelper.getString(skinData, "texture")); - MapSkin.addUniversalSkin(name, texture, width, height, border); - } else if (textureType.equals("image")) { - String imageName = JsonHelper.getString(skinData, "image"); - File imageFile = new File(dir, imageName); - NativeImage skinImage = ImageUtil.loadImage(imageFile, width, height); - String prefix = String.format("%s_%s", JustMap.MODID, imageName); - Identifier textureId = textureManager.registerDynamicTexture(prefix, new NativeImageBackedTexture(skinImage)); - switch (shape) { - case ROUND: - MapSkin.addRoundSkin(name, textureId, skinImage, width, height, border); - break; - case SQUARE: - MapSkin.addSquareSkin(name, textureId, skinImage, width, height, border, resizable, repeating); - break; - case UNIVERSAL: - MapSkin.addUniversalSkin(imageName, textureId, skinImage, width, height, border); - break; - } - } else { - throw new JsonParseException("Invalid skin texture type: '" + textureType + "'"); + String name = JsonHelper.getString(skinData, "name"); + int width = JsonHelper.getInt(skinData, "width"); + int height = JsonHelper.getInt(skinData, "height"); + int border = JsonHelper.getInt(skinData, "border"); + SkinType shape = getSkinType(JsonHelper.getString(skinData, "shape", "universal")); + boolean resizable = JsonHelper.getBoolean(skinData, "resizable", false); + boolean repeating = JsonHelper.getBoolean(skinData, "repeating", false); + String textureType = JsonHelper.getString(skinData, "texture_type"); + if (textureType.equals("source")) { + Identifier texture = new Identifier(JsonHelper.getString(skinData, "texture")); + MapSkin.addUniversalSkin(name, texture, width, height, border); + } else if (textureType.equals("image")) { + String imageName = JsonHelper.getString(skinData, "image"); + File imageFile = new File(folder, imageName); + NativeImage skinImage = ImageUtil.loadImage(imageFile, width, height); + String prefix = String.format("%s_%s", JustMap.MODID, imageName); + Identifier textureId = textureManager.registerDynamicTexture(prefix, new NativeImageBackedTexture(skinImage)); + switch (shape) { + case ROUND: + MapSkin.addRoundSkin(name, textureId, skinImage, width, height, border); + break; + case SQUARE: + MapSkin.addSquareSkin(name, textureId, skinImage, width, height, border, resizable, repeating); + break; + case UNIVERSAL: + MapSkin.addUniversalSkin(imageName, textureId, skinImage, width, height, border); + break; } - } catch (Exception ex) { - JustMap.LOGGER.logWarning("Can't load skin: " + skinFile.getPath()); - JustMap.LOGGER.logWarning(ex.getLocalizedMessage()); + } else { + throw new JsonParseException("Invalid skin texture type: '" + textureType + "'"); } } From b6c47f8344217c20a54af4a375c860d330850fc6 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Wed, 8 Jul 2020 18:00:27 +0300 Subject: [PATCH 2/4] Fixed #67 --- .../justmap/server/config/ServerConfig.java | 8 +++-- .../ru/bulldog/justmap/util/StorageUtil.java | 29 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/bulldog/justmap/server/config/ServerConfig.java b/src/main/java/ru/bulldog/justmap/server/config/ServerConfig.java index 3ee8dc21..8fda0950 100644 --- a/src/main/java/ru/bulldog/justmap/server/config/ServerConfig.java +++ b/src/main/java/ru/bulldog/justmap/server/config/ServerConfig.java @@ -2,12 +2,16 @@ import com.google.gson.JsonObject; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import ru.bulldog.justmap.config.Config; import ru.bulldog.justmap.config.ConfigWriter; import ru.bulldog.justmap.config.ConfigKeeper.BooleanEntry; -public class ServerConfig extends Config{ -private static ServerConfig instance; +@Environment(EnvType.SERVER) +public class ServerConfig extends Config { + + private static ServerConfig instance; public static ServerConfig get() { if (instance == null) { diff --git a/src/main/java/ru/bulldog/justmap/util/StorageUtil.java b/src/main/java/ru/bulldog/justmap/util/StorageUtil.java index f9314242..1d71b86f 100644 --- a/src/main/java/ru/bulldog/justmap/util/StorageUtil.java +++ b/src/main/java/ru/bulldog/justmap/util/StorageUtil.java @@ -2,6 +2,8 @@ import java.io.File; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ServerInfo; @@ -10,15 +12,15 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.dimension.DimensionType; + import ru.bulldog.justmap.JustMap; import ru.bulldog.justmap.map.data.ChunkStorage; public class StorageUtil { - private static MinecraftClient minecraft = MinecraftClient.getInstance(); - private final static File MAP_DATA_DIR = new File(minecraft.runDirectory, JustMap.MODID + "/"); - private final static File GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDirectory(); - private final static File MAP_CONFIG_DIR = new File(GAME_CONFIG_DIR, String.format("/%s/", JustMap.MODID)); + private final static FabricLoader fabricLoader = FabricLoader.getInstance(); + private final static File MAP_DATA_DIR = new File(fabricLoader.getGameDirectory(), JustMap.MODID + "/"); + private final static File MAP_CONFIG_DIR = new File(fabricLoader.getConfigDirectory(), String.format("/%s/", JustMap.MODID)); private final static File MAP_SKINS_DIR = new File(MAP_CONFIG_DIR, "skins/"); private final static File MAP_ICONS_DIR = new File(MAP_CONFIG_DIR, "icons/"); @@ -27,6 +29,7 @@ public class StorageUtil { private static File filesDir = new File(MAP_DATA_DIR, "undefined/"); private static String currentDim = "unknown"; + @Environment(EnvType.CLIENT) public static synchronized CompoundTag getCache(ChunkPos pos) { if (storage == null) updateCacheStorage(); @@ -38,11 +41,13 @@ public static synchronized CompoundTag getCache(ChunkPos pos) { } } + @Environment(EnvType.CLIENT) public static synchronized void saveCache(ChunkPos pos, CompoundTag data) { if (storage == null) updateCacheStorage(); storage.setTagAt(storageDir, pos, data); } + @Environment(EnvType.CLIENT) public static void updateCacheStorage() { storageDir = new File(cacheDir(), "chunk-data/"); @@ -54,12 +59,15 @@ public static void updateCacheStorage() { } public static File configDir() { + System.out.println(FabricLoader.getInstance().getGameDirectory().getPath()); + if (!MAP_CONFIG_DIR.exists()) { MAP_CONFIG_DIR.mkdirs(); } return MAP_CONFIG_DIR; } + @Environment(EnvType.CLIENT) public static File skinsDir() { if (!MAP_SKINS_DIR.exists()) { MAP_SKINS_DIR.mkdirs(); @@ -67,6 +75,7 @@ public static File skinsDir() { return MAP_SKINS_DIR; } + @Environment(EnvType.CLIENT) public static File iconsDir() { if (!MAP_ICONS_DIR.exists()) { MAP_ICONS_DIR.mkdirs(); @@ -74,8 +83,10 @@ public static File iconsDir() { return MAP_ICONS_DIR; } + @Environment(EnvType.CLIENT) public static File cacheDir() { RegistryKey dimKey = null; + MinecraftClient minecraft = MinecraftClient.getInstance(); if (minecraft.world != null) { dimKey = minecraft.world.getDimensionRegistryKey(); String dimension = dimKey.getValue().getPath(); @@ -102,12 +113,12 @@ public static File cacheDir() { return cacheDir; } + @Environment(EnvType.CLIENT) public static File filesDir() { - MinecraftClient client = MinecraftClient.getInstance(); - - ServerInfo serverInfo = client.getCurrentServerEntry(); - if (client.isIntegratedServerRunning()) { - MinecraftServer server = client.getServer(); + MinecraftClient minecraft = MinecraftClient.getInstance(); + ServerInfo serverInfo = minecraft.getCurrentServerEntry(); + if (minecraft.isIntegratedServerRunning()) { + MinecraftServer server = minecraft.getServer(); String name = scrubNameFile(server.getSaveProperties().getLevelName()); filesDir = new File(MAP_DATA_DIR, String.format("local/%s/", name)); } else if (serverInfo != null) { From 00dfa9f3480e69f04d5acf5ade123a468abfecf3 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Wed, 8 Jul 2020 20:35:06 +0300 Subject: [PATCH 3/4] Made: map size depends on window size (#66) --- .classpath | 191 +++++++++--------- gradle.properties | 4 +- .../justmap/client/render/MapRenderer.java | 8 +- .../bulldog/justmap/map/minimap/Minimap.java | 32 ++- .../ru/bulldog/justmap/util/StorageUtil.java | 2 - 5 files changed, 124 insertions(+), 113 deletions(-) diff --git a/.classpath b/.classpath index 3be3cc85..44294640 100644 --- a/.classpath +++ b/.classpath @@ -1,478 +1,477 @@ - + - + - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + diff --git a/gradle.properties b/gradle.properties index 0a1c5cbd..280a3cb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs = -Xmx2G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version = 1.16.1 -yarn_mappings = 18 +yarn_mappings = 20 loader_version = 0.8.8+build.202 mod_version = 1.0.0 @@ -12,6 +12,6 @@ archives_base_name = justmap # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric -fabric_version = 0.14.0+build.371-1.16 +fabric_version = 0.14.1+build.372-1.16 cloth_version = 4.5.6 modmenu_version = 1.12.2+build.16 diff --git a/src/main/java/ru/bulldog/justmap/client/render/MapRenderer.java b/src/main/java/ru/bulldog/justmap/client/render/MapRenderer.java index 6e2f699c..f9933e27 100644 --- a/src/main/java/ru/bulldog/justmap/client/render/MapRenderer.java +++ b/src/main/java/ru/bulldog/justmap/client/render/MapRenderer.java @@ -31,6 +31,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -94,6 +95,8 @@ public int getY() { } public void updateParams() { + this.minimap.updateMapParams(); + this.isRound = !minimap.isBigMap() && Minimap.isRound(); int border = 0; if (ClientParams.useSkins) { @@ -113,8 +116,9 @@ public void updateParams() { } } - int winW = minecraft.getWindow().getScaledWidth(); - int winH = minecraft.getWindow().getScaledHeight(); + Window window = minecraft.getWindow(); + int winW = window.getScaledWidth(); + int winH = window.getScaledHeight(); int mapW = this.minimap.getWidth(); int mapH = this.minimap.getHeight(); int off = ClientParams.positionOffset; diff --git a/src/main/java/ru/bulldog/justmap/map/minimap/Minimap.java b/src/main/java/ru/bulldog/justmap/map/minimap/Minimap.java index d904ac23..7b55fbad 100644 --- a/src/main/java/ru/bulldog/justmap/map/minimap/Minimap.java +++ b/src/main/java/ru/bulldog/justmap/map/minimap/Minimap.java @@ -27,6 +27,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ChatScreen; +import net.minecraft.client.util.Window; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.HostileEntity; @@ -50,7 +51,7 @@ public static enum Shape { SQUARE } - private static final MinecraftClient minecraftClient = MinecraftClient.getInstance(); + private static final MinecraftClient minecraft = MinecraftClient.getInstance(); private final TextManager textManager; private InfoText txtCoords = new CoordsInfo(TextAlignment.CENTER, "0, 0, 0"); @@ -88,7 +89,7 @@ public Minimap() { public void update() { if (!this.isMapVisible()) { return; } - PlayerEntity player = minecraftClient.player; + PlayerEntity player = minecraft.player; if (player != null) { if (locPlayer == null) { locPlayer = player; @@ -108,9 +109,18 @@ public void updateMapParams() { boolean needRotate = config.getBoolean("rotate_map"); boolean bigMap = config.getBoolean("show_big_map"); + Window window = minecraft.getWindow(); + if (window != null) { + int winWidth = window.getScaledWidth(); + int guiScale = minecraft.options.guiScale; + double winScale = window.getScaleFactor(); + if (guiScale == 0 && winScale > 2) { + configSize *= configSize / (winWidth / winScale); + } + } + if (configSize != mapWidth || configScale != mapScale || - this.rotateMap != needRotate || this.bigMap != bigMap) { - + this.rotateMap != needRotate || this.bigMap != bigMap) { if (bigMap) { this.mapWidth = config.getInt("big_map_size"); this.mapHeight = (mapWidth * 10) / 16; @@ -158,7 +168,7 @@ private void updateInfo(PlayerEntity player) { private static boolean isAllowed(boolean param, GameRules.Key rule) { if (param) { - return minecraftClient.isInSingleplayer() || MapGameRules.isAllowed(rule); + return minecraft.isInSingleplayer() || MapGameRules.isAllowed(rule); } return false; @@ -252,7 +262,7 @@ public void prepareMap(PlayerEntity player) { int amount = 0; for (Entity entity : entities) { - float tick = minecraftClient.getTickDelta(); + float tick = minecraft.getTickDelta(); double entX = entity.prevX + (entity.getX() - entity.prevX) * tick; double entZ = entity.prevZ + (entity.getZ() - entity.prevZ) * tick; double iconX = MathUtil.screenPos(entX, startX, endX, mapWidth); @@ -310,11 +320,11 @@ public void createWaypoint(Identifier dimension, BlockPos pos) { waypoint.color = RandomUtil.getElement(Waypoint.WAYPOINT_COLORS); waypoint.pos = pos; - minecraftClient.openScreen(new WaypointEditor(waypoint, minecraftClient.currentScreen, WaypointKeeper.getInstance()::addNew)); + minecraft.openScreen(new WaypointEditor(waypoint, minecraft.currentScreen, WaypointKeeper.getInstance()::addNew)); } public void createWaypoint() { - World world = minecraftClient.world; + World world = minecraft.world; createWaypoint(world.getDimensionRegistryKey().getValue(), PosUtil.currentPos()); } @@ -347,9 +357,9 @@ public static boolean isRound() { } public boolean isMapVisible() { - if (minecraftClient.currentScreen != null) { - return this.isMapVisible && !minecraftClient.isPaused() && - ClientParams.showInChat && minecraftClient.currentScreen instanceof ChatScreen; + if (minecraft.currentScreen != null) { + return this.isMapVisible && !minecraft.isPaused() && + ClientParams.showInChat && minecraft.currentScreen instanceof ChatScreen; } return this.isMapVisible; diff --git a/src/main/java/ru/bulldog/justmap/util/StorageUtil.java b/src/main/java/ru/bulldog/justmap/util/StorageUtil.java index 1d71b86f..dde2df39 100644 --- a/src/main/java/ru/bulldog/justmap/util/StorageUtil.java +++ b/src/main/java/ru/bulldog/justmap/util/StorageUtil.java @@ -59,8 +59,6 @@ public static void updateCacheStorage() { } public static File configDir() { - System.out.println(FabricLoader.getInstance().getGameDirectory().getPath()); - if (!MAP_CONFIG_DIR.exists()) { MAP_CONFIG_DIR.mkdirs(); } From f10fc137a07e958bd36d03c09586753eccc8592f Mon Sep 17 00:00:00 2001 From: Aleksey Date: Wed, 8 Jul 2020 20:37:13 +0300 Subject: [PATCH 4/4] Bump version --- version.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.properties b/version.properties index 5bc0e3f7..de5a68b7 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ -#Tue Jul 07 17:01:22 GMT+03:00 2020 +#Wed Jul 08 20:36:46 MSK 2020 VERSION_MINOR=1 -VERSION_BUILD=91 +VERSION_BUILD=92 VERSION_MAJOR=1