Many fixes

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.
This commit is contained in:
Stephen Seo 2019-11-29 18:52:28 +09:00
parent 202f918f79
commit cb328f3dbb
10 changed files with 107 additions and 37 deletions

View file

@ -6,11 +6,13 @@ buildscript {
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
}
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
//apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
version = "1.9"
group = "com.burnedkirby.TurnBasedMinecraft"
@ -108,7 +110,20 @@ dependencies {
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compile files('src/main/resources/META-INF/libraries/javamp3-1.0.3.jar')
compile files('libs/javamp3-1.0.3.jar')
shadow files('libs/javamp3-1.0.3.jar')
}
shadowJar {
project.configurations.shadow.setTransitive(true);
configurations = [project.configurations.shadow]
relocate 'fr.delthas', 'com.burnedkirby.tbm_repack.fr.delthas'
classifier '' // replace the default jar
}
reobf {
shadowJar {} // reobfuscate the shadowed jar
}
// Example for how to get properties into the manifest for reading by the runtime..
@ -122,7 +137,7 @@ jar {
"Implementation-Version": "${version}",
"Implementation-Vendor" :"TurnBasedMinecraftMod_BK",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"ContainedDeps": "javamp3-1.0.3.jar"
// "ContainedDeps": "javamp3-1.0.3.jar"
])
}
}
@ -131,11 +146,11 @@ jar {
// we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published
// Note you'll need to add a repository here
def reobfFile = file("$buildDir/reobfJar/output.jar")
def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
builtBy 'reobfJar'
}
//def reobfFile = file("$buildDir/reobfJar/output.jar")
//def reobfArtifact = artifacts.add('default', reobfFile) {
// type 'jar'
// builtBy 'reobfJar'
//}
//publishing {
// publications {
// mavenJava(MavenPublication) {

View 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()

View 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);
}
}

View 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);
}
}

View 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,8 +808,56 @@ 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;
}

View file

@ -25,7 +25,7 @@ public class EntityIDDimPair {
}
public Entity getEntity() {
return Utility.getEntity(id, dim);
return TurnBasedMinecraftMod.proxy.getEntity(id, dim);
}
@Override

View 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);
}
}

View 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)
{

View file

@ -1 +0,0 @@
Maven-Artifact: fr.delthas:javamp3:1.0.3