diff --git a/Changelog.md b/Changelog.md index ace7f4a..6a838d9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,12 @@ # Upcoming changes +# Version 1.21.2 + +Refactored checking-if-in-battle code from `O(n)` to `O(1)` complexity. +(In other words, utilizes the HashMap's constant time lookup of a key instead of +checking every key's id if the entity's id is the same. This speeds up the +lookup from linear to constant time.) + # Version 1.21.1 Refactored checking-if-in-battle code to be more efficient. diff --git a/build.gradle b/build.gradle index 05f0321..15c0aeb 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle' //apply plugin: 'eclipse' //apply plugin: 'maven-publish' -version = "1.21.1" +version = "1.21.2" group = "com.burnedkirby.TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft" diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java index 688d841..a9cac7f 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java @@ -351,7 +351,7 @@ public class BattleManager return result; } - public boolean isInBattle(int entityID) { - return entityToBattleMap.keySet().parallelStream().anyMatch(pair -> pair.id == entityID); + public boolean isInBattle(Entity entity) { + return entityToBattleMap.keySet().contains(new EntityIDDimPair(entity)); } } \ No newline at end of file diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/HurtEventHandler.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/HurtEventHandler.java index 5a39f94..f268d3e 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/HurtEventHandler.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/HurtEventHandler.java @@ -9,7 +9,7 @@ public class HurtEventHandler { CommonProxy proxy = TurnBasedMinecraftMod.proxy; if (event.getEntity().level.isClientSide || proxy.getBattleManager() == null) { return; - } else if (proxy.getConfig().getIgnoreHurtDamageSources().contains(event.getSource().msgId) && proxy.getBattleManager().isInBattle(event.getEntity().getId())) { + } else if (proxy.getConfig().getIgnoreHurtDamageSources().contains(event.getSource().msgId) && proxy.getBattleManager().isInBattle(event.getEntity())) { event.setCanceled(true); } } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index 53cf919..305a0cc 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger; public class TurnBasedMinecraftMod { public static final String MODID = "com_burnedkirby_turnbasedminecraft"; public static final String NAME = "Turn Based Minecraft Mod"; - public static final String VERSION = "1.21.1"; + public static final String VERSION = "1.21.2"; public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b172066..3780f3e 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -15,7 +15,7 @@ license="MIT" # The modid of the mod modId="com_burnedkirby_turnbasedminecraft" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it -version="1.21.1" #mandatory +version="1.21.2" #mandatory # A display name for the mod displayName="TurnBasedMinecraftMod" #mandatory # A URL to query for updates for this mod. See the JSON update specification diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index bafbd81..5b9cfd0 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,7 +3,7 @@ "modid": "com_burnedkirby_turnbasedminecraft", "name": "Turn Based Minecraft", "description": "Changes battles to be turn-based.", - "version": "1.21.1", + "version": "1.21.2", "mcversion": "1.18.2", "url": "", "updateUrl": "",