]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Refactor entity-in-battle checking, v1.21.2 1.21.2
authorStephen Seo <seo.disparate@gmail.com>
Tue, 23 Aug 2022 06:01:14 +0000 (15:01 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 23 Aug 2022 06:01:14 +0000 (15:01 +0900)
Changelog.md
build.gradle
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/HurtEventHandler.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java
src/main/resources/META-INF/mods.toml
src/main/resources/mcmod.info

index ace7f4ae5851b7d335333a326f349d254fa186c6..6a838d9d4bb63540cd26ab01a9ab8a1b43436b32 100644 (file)
@@ -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.
index 05f0321be42c15a2e0a3dae4627b494f3f021011..15c0aeb571a397bd13d28cd6dc7ef39f93d1dbf8 100644 (file)
@@ -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"
 
index 688d841b924874dedd83f2907c9f1a58d2b159d3..a9cac7f1cf78b1b808d8a109097bde149f4ed34e 100644 (file)
@@ -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
index 5a39f946f0c171eeb95998479cb1ea1494beb18d..f268d3eb75dbe9881b2b48cdc1174af7feb93a53 100644 (file)
@@ -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);
         }
     }
index 53cf919a87d492dbf741f55867c58bea4f5c1612..305a0cc24943f32af09012d9a59e9888601188d1 100644 (file)
@@ -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/";
index b1720666e50ff0260007a5a6165cfc461fede052..3780f3e4f19a252b5b7a4d7769f13f48affe7cd4 100644 (file)
@@ -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 <here>
index bafbd8158b8d25fa8aa5a7e1505f4a2d1b0270bc..5b9cfd0f76fe6dc206557eb95a08b4d429dec340 100644 (file)
@@ -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": "",