From c4c2c43798db96316694c9ca6a1efd3063e83acb Mon Sep 17 00:00:00 2001 From: TechPizza <23627133+TechPizzaDev@users.noreply.github.com> Date: Tue, 22 Aug 2023 01:18:42 +0200 Subject: [PATCH] Cleaned up EntityDescriptions --- .../awakening/mixin/world/MixinWorld.java | 38 ++++----- .../awakening/script/EntityDescriptions.java | 85 +++++++++++-------- 2 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/main/java/dev/adventurecraft/awakening/mixin/world/MixinWorld.java b/src/main/java/dev/adventurecraft/awakening/mixin/world/MixinWorld.java index f0fdf31a..4095f624 100644 --- a/src/main/java/dev/adventurecraft/awakening/mixin/world/MixinWorld.java +++ b/src/main/java/dev/adventurecraft/awakening/mixin/world/MixinWorld.java @@ -284,12 +284,12 @@ public void initWorld( this.collisionDebugLists = new ArrayList<>(); this.rayCheckedBlocks = new ArrayList<>(); this.rayDebugLists = new ArrayList<>(); - File var7 = Minecraft.getGameDirectory(); - File var8 = new File(var7, "../maps"); - File var9 = new File(var8, mapName); - ((ExTranslationStorage) TranslationStorage.getInstance()).loadMapTranslation(var9); - this.mapHandler = new McRegionDimensionFile(var8, mapName, false); - this.levelDir = var9; + File gameDir = Minecraft.getGameDirectory(); + File mapDir = new File(gameDir, "../maps"); + File levelDir = new File(mapDir, mapName); + ((ExTranslationStorage) TranslationStorage.getInstance()).loadMapTranslation(levelDir); + this.mapHandler = new McRegionDimensionFile(mapDir, mapName, false); + this.levelDir = levelDir; this.lightingUpdates = new ArrayList<>(); this.entities = new ArrayList<>(); this.unloadedEntities = new ArrayList<>(); @@ -323,8 +323,8 @@ public void initWorld( this.properties = this.mapHandler.getLevelProperties(); } - if (!AC_TerrainImage.loadMap(var9)) { - AC_TerrainImage.loadMap(new File(new File(var7, "saves"), saveName)); + if (!AC_TerrainImage.loadMap(levelDir)) { + AC_TerrainImage.loadMap(new File(new File(gameDir, "saves"), saveName)); } this.field_215 = this.properties == null; @@ -380,10 +380,10 @@ public void initWorld( ScopeTag.loadScopeFromTag(this.script.globalScope, props.getGlobalScope()); } - this.scriptHandler = new AC_JScriptHandler((World) (Object) this, var9); + this.scriptHandler = new AC_JScriptHandler((World) (Object) this, levelDir); this.scriptHandler.loadScripts(progressListener); - this.musicScripts = new AC_MusicScripts(this.script, var9, this.scriptHandler); + this.musicScripts = new AC_MusicScripts(this.script, levelDir, this.scriptHandler); if (props.getMusicScope() != null) { ScopeTag.loadScopeFromTag(this.musicScripts.scope, props.getMusicScope()); } @@ -394,8 +394,8 @@ public void initWorld( } this.loadSoundOverrides(); - EntityDescriptions.loadDescriptions(new File(var9, "entitys")); - AC_ItemCustom.loadItems(new File(var9, "items")); + EntityDescriptions.loadDescriptions(new File(levelDir, "entitys")); + AC_ItemCustom.loadItems(new File(levelDir, "items")); AC_TileEntityNpcPath.lastEntity = null; } @@ -404,14 +404,14 @@ public void loadMapTextures() { var texManager = ((ExTextureManager) Minecraft.instance.textureManager); Minecraft.instance.textureManager.reloadTexturesFromTexturePack(); - for (Object entry : Minecraft.instance.textureManager.textures.entrySet()) { - Map.Entry var3 = (Map.Entry) entry; - String var4 = var3.getKey(); - int var5 = var3.getValue(); - + for (Object oEntry : Minecraft.instance.textureManager.textures.entrySet()) { + var entry = (Map.Entry) oEntry; + String name = entry.getKey(); + int id = entry.getValue(); try { - texManager.loadTexture(var5, var4); - } catch (IllegalArgumentException var7) { + texManager.loadTexture(id, name); + } catch (IllegalArgumentException ex) { + ACMod.LOGGER.error("Failed to load texture \"{}\".", name, ex); } } diff --git a/src/main/java/dev/adventurecraft/awakening/script/EntityDescriptions.java b/src/main/java/dev/adventurecraft/awakening/script/EntityDescriptions.java index cd58c308..f0a2f08e 100644 --- a/src/main/java/dev/adventurecraft/awakening/script/EntityDescriptions.java +++ b/src/main/java/dev/adventurecraft/awakening/script/EntityDescriptions.java @@ -1,83 +1,94 @@ package dev.adventurecraft.awakening.script; +import dev.adventurecraft.awakening.ACMod; + import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Properties; import java.util.Set; -@SuppressWarnings("unused") public class EntityDescriptions { - static final HashMap descriptions = new HashMap(); + static final HashMap descriptions = new HashMap<>(); - public static ScriptEntityDescription getDescription(String var0) { - return descriptions.get(var0); + public static ScriptEntityDescription getDescription(String name) { + return descriptions.get(name); } - static void addDescription(String var0, ScriptEntityDescription var1) { - descriptions.put(var0, var1); + static void addDescription(String name, ScriptEntityDescription desc) { + descriptions.put(name, desc); } public static void clearDescriptions() { descriptions.clear(); } - public static void loadDescriptions(File var0) { + public static void loadDescriptions(File directory) { clearDescriptions(); - if (var0 != null && var0.exists() && var0.isDirectory()) { - File[] var1 = var0.listFiles(); - for (File var4 : var1) { - if (var4.isFile() && var4.getName().endsWith(".txt")) { - loadDescription(var4); + if (directory != null && directory.isDirectory()) { + File[] files = directory.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isFile() && file.getName().endsWith(".txt")) { + loadDescription(file); + } } } } } - private static void loadDescription(File var0) { - Properties var1 = new Properties(); - + private static void loadDescription(File file) { + var bag = new Properties(); try { - var1.load(new FileInputStream(var0)); - ScriptEntityDescription var2 = new ScriptEntityDescription(var0.getName().split("\\.")[0]); + bag.load(new FileInputStream(file)); + var desc = new ScriptEntityDescription(file.getName().split("\\.")[0]); try { - var2.health = Integer.parseInt(var1.getProperty("health", "10")); - } catch (NumberFormatException var7) { + desc.health = Integer.parseInt(bag.getProperty("health", "10")); + } catch (NumberFormatException ex) { + logException(file, "health", ex); } try { - var2.width = Float.parseFloat(var1.getProperty("width", "0.6")); - } catch (NumberFormatException var6) { + desc.width = Float.parseFloat(bag.getProperty("width", "0.6")); + } catch (NumberFormatException ex) { + logException(file, "width", ex); } try { - var2.height = Float.parseFloat(var1.getProperty("height", "1.8")); - } catch (NumberFormatException var5) { + desc.height = Float.parseFloat(bag.getProperty("height", "1.8")); + } catch (NumberFormatException ex) { + logException(file, "height", ex); } try { - var2.moveSpeed = Float.parseFloat(var1.getProperty("moveSpeed", "0.7")); - } catch (NumberFormatException var4) { + desc.moveSpeed = Float.parseFloat(bag.getProperty("moveSpeed", "0.7")); + } catch (NumberFormatException ex) { + logException(file, "moveSpeed", ex); } - var2.texture = var1.getProperty("texture", "/mob/char.png"); - var2.onCreated = var1.getProperty("onCreated", ""); - var2.onUpdate = var1.getProperty("onUpdate", ""); - var2.onDeath = var1.getProperty("onDeath", ""); - var2.onPathReached = var1.getProperty("onPathReached", ""); - var2.onAttacked = var1.getProperty("onAttacked", ""); - var2.onInteraction = var1.getProperty("onInteraction", ""); - } catch (FileNotFoundException var8) { - var8.printStackTrace(); - } catch (IOException var9) { - var9.printStackTrace(); + desc.texture = bag.getProperty("texture", "/mob/char.png"); + desc.onCreated = bag.getProperty("onCreated", ""); + desc.onUpdate = bag.getProperty("onUpdate", ""); + desc.onDeath = bag.getProperty("onDeath", ""); + desc.onPathReached = bag.getProperty("onPathReached", ""); + desc.onAttacked = bag.getProperty("onAttacked", ""); + desc.onInteraction = bag.getProperty("onInteraction", ""); + } catch (IOException ex) { + logException(file, ex); } } + private static void logException(File file, String property, NumberFormatException ex) { + ACMod.LOGGER.error("Failed to parse property \"{}\" of entity description \"{}\".", property, file.getPath(), ex); + } + + private static void logException(File file, Throwable ex) { + ACMod.LOGGER.error("Failed to load entity description \"{}\".", file.getPath(), ex); + } + public static Set getDescriptions() { return descriptions.keySet(); }