Skip to content

Commit

Permalink
Merge branch 'master' into unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulldog83 committed Jul 8, 2020
2 parents 54244dd + f10fc13 commit fcf541a
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 158 deletions.
191 changes: 95 additions & 96 deletions .classpath

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/ru/bulldog/justmap/map/minimap/Minimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -158,7 +168,7 @@ private void updateInfo(PlayerEntity player) {

private static boolean isAllowed(boolean param, GameRules.Key<GameRules.BooleanRule> rule) {
if (param) {
return minecraftClient.isInSingleplayer() || MapGameRules.isAllowed(rule);
return minecraft.isInSingleplayer() || MapGameRules.isAllowed(rule);
}

return false;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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;
Expand Down
72 changes: 36 additions & 36 deletions src/main/java/ru/bulldog/justmap/map/minimap/skin/SkinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/ru/bulldog/justmap/util/StorageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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/");

Expand All @@ -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();

Expand All @@ -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/");

Expand All @@ -60,22 +65,26 @@ public static File configDir() {
return MAP_CONFIG_DIR;
}

@Environment(EnvType.CLIENT)
public static File skinsDir() {
if (!MAP_SKINS_DIR.exists()) {
MAP_SKINS_DIR.mkdirs();
}
return MAP_SKINS_DIR;
}

@Environment(EnvType.CLIENT)
public static File iconsDir() {
if (!MAP_ICONS_DIR.exists()) {
MAP_ICONS_DIR.mkdirs();
}
return MAP_ICONS_DIR;
}

@Environment(EnvType.CLIENT)
public static File cacheDir() {
RegistryKey<DimensionType> dimKey = null;
MinecraftClient minecraft = MinecraftClient.getInstance();
if (minecraft.world != null) {
dimKey = minecraft.world.getDimensionRegistryKey();
String dimension = dimKey.getValue().getPath();
Expand All @@ -102,12 +111,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) {
Expand Down

0 comments on commit fcf541a

Please sign in to comment.