From 19c4f45d1f3d07aa1a137f53206276bb4406444a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 24 Feb 2024 22:58:20 +0100 Subject: [PATCH] Fix crash because of sided field assignment --- apron-stapi-compat/build.gradle | 1 + apron-stapi/build.gradle | 1 + apron/src/main/java/modloader/ModLoader.java | 26 ++++++++++++++----- .../main/java/modloadermp/ModLoaderMp.java | 25 +++++++++++++----- .../java/modloadermp/ModLoaderPacket.java | 9 ++++++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/apron-stapi-compat/build.gradle b/apron-stapi-compat/build.gradle index 55514b80..e1d84b52 100644 --- a/apron-stapi-compat/build.gradle +++ b/apron-stapi-compat/build.gradle @@ -11,6 +11,7 @@ loom { dependencies { implementation "org.slf4j:slf4j-api:1.8.0-beta4" implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2' + implementation "blue.endless:jankson:1.2.1" modImplementation "net.modificationstation:StationAPI:${project.stapi_version}" diff --git a/apron-stapi/build.gradle b/apron-stapi/build.gradle index 024ba311..78d6ad31 100644 --- a/apron-stapi/build.gradle +++ b/apron-stapi/build.gradle @@ -7,6 +7,7 @@ tasks.withType(JavaCompile).configureEach { dependencies { implementation "org.slf4j:slf4j-api:1.8.0-beta4" implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2' + implementation "blue.endless:jankson:1.2.1" modImplementation "net.modificationstation:StationAPI:${project.stapi_version}" diff --git a/apron/src/main/java/modloader/ModLoader.java b/apron/src/main/java/modloader/ModLoader.java index 51c6e3fa..b840c2b6 100644 --- a/apron/src/main/java/modloader/ModLoader.java +++ b/apron/src/main/java/modloader/ModLoader.java @@ -104,11 +104,11 @@ public class ModLoader { static final ApronApi APRON = ApronApi.getInstance(); @Environment(EnvType.CLIENT) - private static final List ANIM_LIST = new LinkedList<>(); + private static List ANIM_LIST; @Environment(EnvType.CLIENT) - private static final Map BLOCK_MODELS = new HashMap<>(); + private static Map BLOCK_MODELS; @Environment(EnvType.CLIENT) - private static final Map BLOCK_SPECIAL_INV = new HashMap<>(); + private static Map BLOCK_SPECIAL_INV; private static final File CONFIG_DIR = FabricLoader.getInstance().getConfigDir().toFile(); private static final File CONFIG_FILE = new File(CONFIG_DIR, "ModLoader.cfg"); public static Level cfgLoggingLevel = Level.FINER; @@ -118,11 +118,11 @@ public class ModLoader { private static int highestEntityId = 3000; private static final Map inGameHooks = new HashMap<>(); @Environment(EnvType.CLIENT) - private static final Map inGUIHooks = new HashMap<>(); + private static Map inGUIHooks; private static int itemSpriteIndex = 0; private static int itemSpritesLeft = 0; @Environment(EnvType.CLIENT) - private static final Map> keyList = new HashMap<>(); + private static Map> keyList; private static final File LOG_FILE = new File(FabricLoader.getInstance().getGameDir().toFile(), "ModLoader.txt"); private static final java.util.logging.Logger MOD_LOGGER = java.util.logging.Logger.getLogger("ModLoader"); public static final Logger LOGGER = Apron.getLogger("ModLoader"); @@ -134,13 +134,25 @@ public class ModLoader { private static int terrainSpriteIndex = 0; private static int terrainSpritesLeft = 0; @Environment(EnvType.CLIENT) - private static String texPack = null; + private static String texPack; @Environment(EnvType.CLIENT) - private static boolean texturesAdded = false; + private static boolean texturesAdded; private static final boolean[] USED_ITEM_SPRITES = new boolean[256]; private static final boolean[] USED_TERRAIN_SPRITES = new boolean[256]; public static final String VERSION = APRON.getModLoaderVersion(); + static { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { + ANIM_LIST = new LinkedList<>(); + BLOCK_MODELS = new HashMap<>(); + BLOCK_SPECIAL_INV = new HashMap<>(); + inGUIHooks = new HashMap<>(); + keyList = new HashMap<>(); + texPack = null; + texturesAdded = false; + } + } + /** * Used to give your achievement a readable name and description. * diff --git a/apron/src/main/java/modloadermp/ModLoaderMp.java b/apron/src/main/java/modloadermp/ModLoaderMp.java index 3b67d927..a0b1f650 100644 --- a/apron/src/main/java/modloadermp/ModLoaderMp.java +++ b/apron/src/main/java/modloadermp/ModLoaderMp.java @@ -15,6 +15,7 @@ import modloader.ModLoader; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; import org.jetbrains.annotations.NotNull; import net.minecraft.client.Minecraft; @@ -46,17 +47,29 @@ public class ModLoaderMp { public static final String VERSION = APRON.getModLoaderMPVersion(); private static boolean hasInit = false; @Environment(EnvType.CLIENT) - private static boolean packet230Received = false; + private static boolean packet230Received; @Environment(EnvType.CLIENT) - private static final Map NET_CLIENT_HANDLER_MAP = new HashMap<>(); + private static Map NET_CLIENT_HANDLER_MAP; @Environment(EnvType.CLIENT) - private static final Map GUI_MOD_MAP = new HashMap<>(); + private static Map GUI_MOD_MAP; @Environment(EnvType.SERVER) - private static final Map, AbstractMap.SimpleEntry> entityTrackerMap = new HashMap<>(); + private static Map, AbstractMap.SimpleEntry> entityTrackerMap; @Environment(EnvType.SERVER) - private static final Map, EntityTrackerEntry> entityTrackerEntryMap = new HashMap<>(); + private static Map, EntityTrackerEntry> entityTrackerEntryMap; @Environment(EnvType.SERVER) - private static final List bannedMods = new ArrayList<>(); + private static List bannedMods; + + static { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { + packet230Received = false; + NET_CLIENT_HANDLER_MAP = new HashMap<>(); + GUI_MOD_MAP = new HashMap<>(); + } else { + entityTrackerMap = new HashMap<>(); + entityTrackerEntryMap = new HashMap<>(); + bannedMods = new ArrayList<>(); + } + } @Environment(EnvType.CLIENT) public static void Init() { diff --git a/apron/src/main/java/modloadermp/ModLoaderPacket.java b/apron/src/main/java/modloadermp/ModLoaderPacket.java index 6775fb42..7125be22 100644 --- a/apron/src/main/java/modloadermp/ModLoaderPacket.java +++ b/apron/src/main/java/modloadermp/ModLoaderPacket.java @@ -9,6 +9,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.PacketHandler; import net.minecraft.packet.AbstractPacket; import net.minecraft.server.entity.player.ServerPlayerEntity; @@ -28,7 +29,13 @@ public class ModLoaderPacket extends AbstractPacket { public float[] dataFloat = new float[0]; public String[] dataString = new String[0]; @Environment(EnvType.SERVER) - private static final Map playerMap = new HashMap<>(); + private static Map playerMap; + + static { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { + playerMap = new HashMap<>(); + } + } public ModLoaderPacket() { }