]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Many fixes
authorStephen Seo <seo.disparate@gmail.com>
Fri, 29 Nov 2019 09:52:28 +0000 (18:52 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 29 Nov 2019 09:52:28 +0000 (18:52 +0900)
Switch back to using shadowjar for dependencies.
Fix saving new entity entries in config.
Fix possible BattleMusic failures.
Fix getEntity method not being side-aware.

build.gradle
libs/javamp3-1.0.3.jar [moved from src/main/resources/META-INF/libraries/javamp3-1.0.3.jar with 100% similarity]
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleMusic.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/EntityIDDimPair.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Utility.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattleMessage.java
src/main/resources/META-INF/libraries/javamp3-1.0.3.jar.meta [deleted file]

index 4eb15c99f47f29abe890db080d4802aaad6503c9..871a65bf4fcce82377e3956ff6396beaa52babfe 100644 (file)
@@ -6,11 +6,13 @@ buildscript {
     }\r
     dependencies {\r
         classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true\r
+        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'\r
     }\r
 }\r
 apply plugin: 'net.minecraftforge.gradle'\r
 apply plugin: 'eclipse'\r
 //apply plugin: 'maven-publish'\r
+apply plugin: 'com.github.johnrengelman.shadow'\r
 \r
 version = "1.9"\r
 group = "com.burnedkirby.TurnBasedMinecraft"\r
@@ -108,7 +110,20 @@ dependencies {
     // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html\r
     // http://www.gradle.org/docs/current/userguide/dependency_management.html\r
 \r
-    compile files('src/main/resources/META-INF/libraries/javamp3-1.0.3.jar')\r
+    compile files('libs/javamp3-1.0.3.jar')\r
+\r
+    shadow files('libs/javamp3-1.0.3.jar')\r
+}\r
+\r
+shadowJar {\r
+    project.configurations.shadow.setTransitive(true);\r
+    configurations = [project.configurations.shadow]\r
+    relocate 'fr.delthas', 'com.burnedkirby.tbm_repack.fr.delthas'\r
+    classifier '' // replace the default jar\r
+}\r
+\r
+reobf {\r
+    shadowJar {} // reobfuscate the shadowed jar\r
 }\r
 \r
 // Example for how to get properties into the manifest for reading by the runtime..\r
@@ -122,7 +137,7 @@ jar {
             "Implementation-Version": "${version}",\r
             "Implementation-Vendor" :"TurnBasedMinecraftMod_BK",\r
             "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),\r
-            "ContainedDeps": "javamp3-1.0.3.jar"\r
+//            "ContainedDeps": "javamp3-1.0.3.jar"\r
         ])\r
     }\r
 }\r
@@ -131,11 +146,11 @@ jar {
 // we define a custom artifact that is sourced from the reobfJar output task\r
 // and then declare that to be published\r
 // Note you'll need to add a repository here\r
-def reobfFile = file("$buildDir/reobfJar/output.jar")\r
-def reobfArtifact = artifacts.add('default', reobfFile) {\r
-    type 'jar'\r
-    builtBy 'reobfJar'\r
-}\r
+//def reobfFile = file("$buildDir/reobfJar/output.jar")\r
+//def reobfArtifact = artifacts.add('default', reobfFile) {\r
+//    type 'jar'\r
+//    builtBy 'reobfJar'\r
+//}\r
 //publishing {\r
 //    publications {\r
 //        mavenJava(MavenPublication) {\r
index 72f38357eb9989984e8524794fd7d1cdbbde4cbb..96995188ca85368dba26de07e86b5bc2d0888347 100644 (file)
@@ -43,19 +43,16 @@ public class BattleMusic
         try {
             sequencer = MidiSystem.getSequencer();
             sequencer.open();
-        } catch (Throwable t)
-        {
+        } catch (Throwable t) {
             logger.error("Failed to load midi sequencer");
-            return;
+            sequencer = null;
         }
         
-        try
-        {
+        try {
             clip = AudioSystem.getClip();
-        } catch(LineUnavailableException e)
-        {
+        } catch(Throwable t) {
             logger.error("Failed to load clip (for wav)");
-            return;
+            clip = null;
         }
         
         File battleMusicFolder = new File(TurnBasedMinecraftMod.MUSIC_BATTLE);
@@ -114,7 +111,7 @@ public class BattleMusic
         {
             sillyMusic.add(f);
         }
-        logger.info("Got " + sillyMusic.size() + " battle music files");
+        logger.info("Got " + sillyMusic.size() + " silly music files");
 
         initialized = true;
         
@@ -185,13 +182,13 @@ public class BattleMusic
             logger.debug("play called with file " + next.getName() + " and vol " + volume);
                Minecraft.getInstance().getSoundHandler().pause();
             String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
-            if(suffix.equals("mid"))
+            if(suffix.equals("mid") && sequencer != null)
             {
                 if(sequencer.isRunning())
                 {
                     sequencer.stop();
                 }
-                if(clip.isActive())
+                if(clip != null && clip.isActive())
                 {
                     clip.stop();
                     clip.close();
@@ -213,9 +210,9 @@ public class BattleMusic
                 sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY);
                 sequencer.start();
             }
-            else if(suffix.equals("wav"))
+            else if(suffix.equals("wav") && clip != null)
             {
-                if(sequencer.isRunning())
+                if(sequencer != null && sequencer.isRunning())
                 {
                     sequencer.stop();
                 }
@@ -248,11 +245,11 @@ public class BattleMusic
             }
             else if(suffix.equals("mp3"))
             {
-                if(sequencer.isRunning())
+                if(sequencer != null && sequencer.isRunning())
                 {
                     sequencer.stop();
                 }
-                if(clip.isActive())
+                if(clip != null && clip.isActive())
                 {
                     clip.stop();
                     clip.close();
@@ -290,9 +287,13 @@ public class BattleMusic
     
     public void stopMusic(boolean resumeMCSounds)
     {
-        sequencer.stop();
-        clip.stop();
-        clip.close();
+        if(sequencer != null) {
+            sequencer.stop();
+        }
+        if(clip != null) {
+            clip.stop();
+            clip.close();
+        }
         if(mp3StreamThread != null && mp3StreamThread.isAlive())
         {
             mp3StreamRunnable.setKeepPlaying(false);
@@ -312,7 +313,7 @@ public class BattleMusic
     
     public boolean isPlaying()
     {
-        return isPlaying || sequencer.isRunning() || clip.isActive();
+        return isPlaying || (sequencer != null && sequencer.isRunning()) || (clip != null && clip.isActive());
     }
     
     public boolean hasBattleMusic()
index eef6abf37ef47be07ff28a06d06c335a2afd2dc7..3919133b189e9fe29d8c20aaaebf71230105a3ab 100644 (file)
@@ -10,6 +10,7 @@ import net.minecraft.util.SoundCategory;
 import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.StringTextComponent;
 import net.minecraft.util.text.TextFormatting;
+import net.minecraft.world.dimension.DimensionType;
 
 public class ClientProxy extends CommonProxy
 {
@@ -27,6 +28,7 @@ public class ClientProxy extends CommonProxy
         battleMusicCount = 0;
         sillyMusicCount = 0;
         localBattle = null;
+        logger.debug("Init client");
     }
 
     @Override
@@ -228,4 +230,9 @@ public class ClientProxy extends CommonProxy
     {
         localBattle = new Battle(null, id, null, null, false, Minecraft.getInstance().world.dimension.getType());
     }
+
+    @Override
+    public Entity getEntity(int id, DimensionType dim) {
+        return Minecraft.getInstance().world.getEntityByID(id);
+    }
 }
index 1ef488ab4717428b77800ca3609a2adc51472784..f940e13b6173e7c83396a1bf2d3fef8e81872282 100644 (file)
@@ -17,7 +17,7 @@ public class CommonProxy
     private Entity attackingEntity = null;
     private int attackingDamage = 0;
     private Config config = null;
-    private Logger logger = null;
+    protected Logger logger = null;
     private Map<Integer, EditingInfo> editingPlayers;
     
     public final void initialize()
@@ -159,4 +159,8 @@ public class CommonProxy
     {
         return editingPlayers.remove(id);
     }
+
+    public Entity getEntity(int id, DimensionType dim) {
+        return ServerLifecycleHooks.getCurrentServer().getWorld(dim).getEntityByID(id);
+    }
 }
index 64519e5cda1259dc99f9323eb24f6b323841c20b..d2270a0eb2aa4c75409747bc5f3957bf82f61c35 100644 (file)
@@ -790,8 +790,8 @@ public class Config
         try {
             if (eInfo.classType != null || !eInfo.customName.isEmpty()) {
                 for (com.electronwill.nightconfig.core.Config entity : entities) {
-                    if ((eInfo.classType != null && entity.get("name").equals(eInfo.classType.getName()))
-                            || (!eInfo.customName.isEmpty() && entity.get("custom_name").equals(eInfo.customName))) {
+                    String entityName = entity.get("name");
+                    if ((eInfo.classType != null && entityName != null && entityName.equals(eInfo.classType.getName()))) {
                         entity.set("attack_power", eInfo.attackPower);
                         entity.set("attack_probability", eInfo.attackProbability);
                         entity.set("attack_variance", eInfo.attackVariance);
@@ -808,7 +808,55 @@ public class Config
                         entity.set("decision_flee_probability", eInfo.decisionFlee);
                         saved = true;
                         break;
+                    } else {
+                        String customName = entity.get("custom_name");
+                        if(!eInfo.customName.isEmpty() && customName != null && customName.equals(eInfo.customName)) {
+                            entity.set("attack_power", eInfo.attackPower);
+                            entity.set("attack_probability", eInfo.attackProbability);
+                            entity.set("attack_variance", eInfo.attackVariance);
+                            entity.set("attack_effect", eInfo.attackEffect.toString());
+                            entity.set("attack_effect_probability", eInfo.attackEffectProbability);
+                            entity.set("defense_damage", eInfo.defenseDamage);
+                            entity.set("defense_damage_probability", eInfo.defenseDamageProbability);
+                            entity.set("evasion", eInfo.evasion);
+                            entity.set("speed", eInfo.speed);
+                            entity.set("ignore_battle", eInfo.ignoreBattle);
+                            entity.set("category", eInfo.category);
+                            entity.set("decision_attack_probability", eInfo.decisionAttack);
+                            entity.set("decision_defend_probability", eInfo.decisionDefend);
+                            entity.set("decision_flee_probability", eInfo.decisionFlee);
+                            saved = true;
+                            break;
+                        }
+                    }
+                }
+                if(!saved) {
+                    com.electronwill.nightconfig.core.Config newEntry = conf.createSubConfig();
+                    if(eInfo.classType != null) {
+                        newEntry.set("name", eInfo.classType.getName());
+                    } else if(!eInfo.customName.isEmpty()) {
+                        newEntry.set("custom_name", eInfo.customName);
+                    } else {
+                        logger.error("Failed to save new entity entry into config, no name or custom_name");
+                        conf.close();
+                        return false;
                     }
+                    newEntry.set("attack_power", eInfo.attackPower);
+                    newEntry.set("attack_probability", eInfo.attackProbability);
+                    newEntry.set("attack_variance", eInfo.attackVariance);
+                    newEntry.set("attack_effect", eInfo.attackEffect.toString());
+                    newEntry.set("attack_effect_probability", eInfo.attackEffectProbability);
+                    newEntry.set("defense_damage", eInfo.defenseDamage);
+                    newEntry.set("defense_damage_probability", eInfo.defenseDamageProbability);
+                    newEntry.set("evasion", eInfo.evasion);
+                    newEntry.set("speed", eInfo.speed);
+                    newEntry.set("ignore_battle", eInfo.ignoreBattle);
+                    newEntry.set("category", eInfo.category);
+                    newEntry.set("decision_attack_probability", eInfo.decisionAttack);
+                    newEntry.set("decision_defend_probability", eInfo.decisionDefend);
+                    newEntry.set("decision_flee_probability", eInfo.decisionFlee);
+                    entities.add(newEntry);
+                    saved = true;
                 }
             } else {
                 return false;
index 82a6f1115b573ad46cc3a55203e4f7c4898beaaf..4b094ff41e9e82ac43cbf283228cc8a96dc57335 100644 (file)
@@ -25,7 +25,7 @@ public class EntityIDDimPair {
     }
 
     public Entity getEntity() {
-        return Utility.getEntity(id, dim);
+        return TurnBasedMinecraftMod.proxy.getEntity(id, dim);
     }
 
     @Override
index 66778062e9f42890f102aa1d530f3a4e753c1899..6162a549d734f61eb0c8a1d7506f3abc6eced7d1 100644 (file)
@@ -51,8 +51,4 @@ public class Utility
     {
         return Math.sqrt(Math.pow(a.posX - b.posX, 2.0) + Math.pow(a.posY - b.posY, 2.0) + Math.pow(a.posZ - b.posZ, 2.0));
     }
-
-    public static Entity getEntity(int id, DimensionType dimension) {
-        return ServerLifecycleHooks.getCurrentServer().getWorld(dimension).getEntityByID(id);
-    }
 }
index 9ef2a84e318119a1319421c1e0a939ff2b930a7d..5666159c54a45af5b0b8c1082cdfe1d209b142c6 100644 (file)
@@ -150,7 +150,7 @@ public class PacketBattleMessage
     public static class Handler {
        public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) {
                ctx.get().enqueueWork(() -> {
-                Entity fromEntity = Utility.getEntity(pkt.entityIDFrom, pkt.dimension);
+                Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntity(pkt.entityIDFrom, pkt.dimension);
                 String from = "Unknown";
                 if(fromEntity != null)
                 {
@@ -164,7 +164,7 @@ public class PacketBattleMessage
                        from = fromEntity.getDisplayName().getFormattedText();
                     }
                 }
-                Entity toEntity = Utility.getEntity(pkt.entityIDTo, pkt.dimension);
+                Entity toEntity = TurnBasedMinecraftMod.proxy.getEntity(pkt.entityIDTo, pkt.dimension);
                 String to = "Unknown";
                 if(toEntity != null)
                 {
diff --git a/src/main/resources/META-INF/libraries/javamp3-1.0.3.jar.meta b/src/main/resources/META-INF/libraries/javamp3-1.0.3.jar.meta
deleted file mode 100644 (file)
index 482c01f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Maven-Artifact: fr.delthas:javamp3:1.0.3