From 7d1f51a8937e0a86486267437d444696e81e8aa0 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:04:28 +0200 Subject: Buildscript + Spotless (#318) * Convert AES.java to readable class * Buildscript * Spotless --- .../plugin/fixes/interfaces/IBugFix.java | 3 +- .../plugin/fixes/vanilla/Core_VanillaFixes.java | 150 +++++++-------- .../fixes/vanilla/VanillaBackgroundMusicFix.java | 102 +++++----- .../plugin/fixes/vanilla/VanillaBedHeightFix.java | 127 ++++++------- .../plugin/fixes/vanilla/music/MusicTocker.java | 210 ++++++++++----------- 5 files changed, 294 insertions(+), 298 deletions(-) (limited to 'src/main/java/gtPlusPlus/plugin/fixes') diff --git a/src/main/java/gtPlusPlus/plugin/fixes/interfaces/IBugFix.java b/src/main/java/gtPlusPlus/plugin/fixes/interfaces/IBugFix.java index d67ff24d7b..4d87a746f3 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/interfaces/IBugFix.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/interfaces/IBugFix.java @@ -2,6 +2,5 @@ package gtPlusPlus.plugin.fixes.interfaces; public interface IBugFix { - public boolean isFixValid(); - + public boolean isFixValid(); } diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java index 2bfd05e5be..82757a2434 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java @@ -9,87 +9,87 @@ import net.minecraft.item.ItemStack; public class Core_VanillaFixes implements IPlugin { - final static Core_VanillaFixes mInstance; - final static VanillaBedHeightFix mBedFixInstance; - final static VanillaBackgroundMusicFix mMusicFixInstance; + static final Core_VanillaFixes mInstance; + static final VanillaBedHeightFix mBedFixInstance; + static final VanillaBackgroundMusicFix mMusicFixInstance; - static { - mInstance = new Core_VanillaFixes(); - mBedFixInstance = new VanillaBedHeightFix(mInstance); - mMusicFixInstance = new VanillaBackgroundMusicFix(mInstance); - mInstance.log("Preparing "+mInstance.getPluginName()+" for use."); - } - - Core_VanillaFixes() { - Core_Manager.registerPlugin(this); - } - - @Override - public boolean preInit() { - return fixVanillaOD(); - } + static { + mInstance = new Core_VanillaFixes(); + mBedFixInstance = new VanillaBedHeightFix(mInstance); + mMusicFixInstance = new VanillaBackgroundMusicFix(mInstance); + mInstance.log("Preparing " + mInstance.getPluginName() + " for use."); + } - @Override - public boolean init() { - return true; - } + Core_VanillaFixes() { + Core_Manager.registerPlugin(this); + } - @Override - public boolean postInit() { - return true; - } + @Override + public boolean preInit() { + return fixVanillaOD(); + } - @Override - public boolean serverStart() { - mMusicFixInstance.manage(); - return true; - } + @Override + public boolean init() { + return true; + } - @Override - public boolean serverStop() { - return true; - } + @Override + public boolean postInit() { + return true; + } - @Override - public String getPluginName() { - return "GT++ Vanilla Fixes Module"; - } + @Override + public boolean serverStart() { + mMusicFixInstance.manage(); + return true; + } - @Override - public String getPluginAbbreviation() { - return "VFIX"; - } - - private boolean fixVanillaOD() { - registerToOreDict(ItemUtils.getSimpleStack(Items.blaze_rod), "rodBlaze"); - registerToOreDict(ItemUtils.getSimpleStack(Items.nether_wart), "cropNetherWart"); - registerToOreDict(ItemUtils.getSimpleStack(Items.reeds), "sugarcane"); - registerToOreDict(ItemUtils.getSimpleStack(Items.paper), "paper"); - registerToOreDict(ItemUtils.getSimpleStack(Items.ender_pearl), "enderpearl"); - registerToOreDict(ItemUtils.getSimpleStack(Items.bone), "bone"); - registerToOreDict(ItemUtils.getSimpleStack(Items.gunpowder), "gunpowder"); - registerToOreDict(ItemUtils.getSimpleStack(Items.string), "string"); - registerToOreDict(ItemUtils.getSimpleStack(Items.nether_star), "netherStar"); - registerToOreDict(ItemUtils.getSimpleStack(Items.leather), "leather"); - registerToOreDict(ItemUtils.getSimpleStack(Items.feather), "feather"); - registerToOreDict(ItemUtils.getSimpleStack(Items.egg), "egg"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.grass), "grass"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.obsidian), "obsidian"); - registerToOreDict(ItemUtils.getSimpleStack(Blocks.crafting_table), "workbench"); - return true; - } - - private void registerToOreDict(ItemStack aStack, String aString) { - if (aStack.getItem() == Items.blaze_rod) { - mInstance.log("Registering "+aStack.getDisplayName()+" to OreDictionary under the tag '"+aString+"'."); - } - else { - mInstance.log("Registering "+aStack.getDisplayName()+" to OreDictionary under the tag '"+aString+"'. (Added to Forge in 1.8.9)"); - } - ItemUtils.addItemToOreDictionary(aStack, aString); - } + @Override + public boolean serverStop() { + return true; + } + @Override + public String getPluginName() { + return "GT++ Vanilla Fixes Module"; + } + + @Override + public String getPluginAbbreviation() { + return "VFIX"; + } + + private boolean fixVanillaOD() { + registerToOreDict(ItemUtils.getSimpleStack(Items.blaze_rod), "rodBlaze"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_wart), "cropNetherWart"); + registerToOreDict(ItemUtils.getSimpleStack(Items.reeds), "sugarcane"); + registerToOreDict(ItemUtils.getSimpleStack(Items.paper), "paper"); + registerToOreDict(ItemUtils.getSimpleStack(Items.ender_pearl), "enderpearl"); + registerToOreDict(ItemUtils.getSimpleStack(Items.bone), "bone"); + registerToOreDict(ItemUtils.getSimpleStack(Items.gunpowder), "gunpowder"); + registerToOreDict(ItemUtils.getSimpleStack(Items.string), "string"); + registerToOreDict(ItemUtils.getSimpleStack(Items.nether_star), "netherStar"); + registerToOreDict(ItemUtils.getSimpleStack(Items.leather), "leather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.feather), "feather"); + registerToOreDict(ItemUtils.getSimpleStack(Items.egg), "egg"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.grass), "grass"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.obsidian), "obsidian"); + registerToOreDict(ItemUtils.getSimpleStack(Blocks.crafting_table), "workbench"); + return true; + } + + private void registerToOreDict(ItemStack aStack, String aString) { + if (aStack.getItem() == Items.blaze_rod) { + mInstance.log( + "Registering " + aStack.getDisplayName() + " to OreDictionary under the tag '" + aString + "'."); + } else { + mInstance.log("Registering " + aStack.getDisplayName() + " to OreDictionary under the tag '" + aString + + "'. (Added to Forge in 1.8.9)"); + } + ItemUtils.addItemToOreDictionary(aStack, aString); + } } diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java index bfd73407f7..ebf7729e92 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java @@ -1,63 +1,61 @@ package gtPlusPlus.plugin.fixes.vanilla; -import java.util.Timer; -import java.util.TimerTask; - import gtPlusPlus.api.interfaces.IPlugin; import gtPlusPlus.core.util.Utils; import gtPlusPlus.plugin.fixes.interfaces.IBugFix; import gtPlusPlus.plugin.fixes.vanilla.music.MusicTocker; import gtPlusPlus.preloader.CORE_Preloader; +import java.util.Timer; +import java.util.TimerTask; public class VanillaBackgroundMusicFix implements IBugFix { - private final IPlugin mParent; - private final boolean enabled; - private MusicTocker mFixInstance; - - public VanillaBackgroundMusicFix(IPlugin minstance) { - mParent = minstance; - if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { - mParent.log("[BGM] Registering BGM delay Fix."); - enabled = true; - mFixInstance = new MusicTocker(mParent); - } else if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isServer()) { - mParent.log("[BGM] Tried registering BGM delay Fix on Server, disabling."); - enabled = false; - } else { - mParent.log("[BGM] Not registering BGM delay Fix."); - enabled = false; - } - } - - public boolean isFixValid() { - return enabled; - } - - public void manage() { - if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { - TimerTask task = new ManageTask(this.mFixInstance); - Timer timer = new Timer("BGM-WatchDog"); - long delay = 1000 * 60; - timer.scheduleAtFixedRate(task, delay, 5000); - } - } - - private static class ManageTask extends TimerTask { - private final MusicTocker A; - - public ManageTask(MusicTocker a) { - A = a; - } - - @Override - public void run() { - if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { - if (!A.mVanillaManager) { - A.run(); - } - } - } - } - + private final IPlugin mParent; + private final boolean enabled; + private MusicTocker mFixInstance; + + public VanillaBackgroundMusicFix(IPlugin minstance) { + mParent = minstance; + if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { + mParent.log("[BGM] Registering BGM delay Fix."); + enabled = true; + mFixInstance = new MusicTocker(mParent); + } else if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isServer()) { + mParent.log("[BGM] Tried registering BGM delay Fix on Server, disabling."); + enabled = false; + } else { + mParent.log("[BGM] Not registering BGM delay Fix."); + enabled = false; + } + } + + public boolean isFixValid() { + return enabled; + } + + public void manage() { + if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { + TimerTask task = new ManageTask(this.mFixInstance); + Timer timer = new Timer("BGM-WatchDog"); + long delay = 1000 * 60; + timer.scheduleAtFixedRate(task, delay, 5000); + } + } + + private static class ManageTask extends TimerTask { + private final MusicTocker A; + + public ManageTask(MusicTocker a) { + A = a; + } + + @Override + public void run() { + if (CORE_Preloader.enableWatchdogBGM > 0 && Utils.isClient()) { + if (!A.mVanillaManager) { + A.run(); + } + } + } + } } diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java index f33cc71fc6..cadb47e50d 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java @@ -1,8 +1,5 @@ package gtPlusPlus.plugin.fixes.vanilla; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gtPlusPlus.api.interfaces.IPlugin; @@ -11,72 +8,76 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.plugin.fixes.interfaces.IBugFix; import gtPlusPlus.preloader.DevHelper; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; public class VanillaBedHeightFix implements IBugFix { - private final Method mSleepInBedAt; - private final IPlugin mParent; - - public VanillaBedHeightFix(IPlugin minstance) { - mParent = minstance; - if (DevHelper.isValidHelperObject()) { - Method m; - if (DevHelper.isObfuscatedEnvironment()) { - m = ReflectionUtils.getMethod(EntityPlayer.class, "func_71018_a", int.class, int.class, int.class); - } - else { - m = ReflectionUtils.getMethod(net.minecraft.entity.player.EntityPlayer.class, "sleepInBedAt", int.class, int.class, int.class); - } - if (m != null) { - mSleepInBedAt = m; - mParent.log("Registering Bed Height Fix."); - Utils.registerEvent(this); - } else { - mSleepInBedAt = null; - } - } else { - mSleepInBedAt = null; - } - } - - public boolean isFixValid() { - return mSleepInBedAt != null; - } + private final Method mSleepInBedAt; + private final IPlugin mParent; - /** - * Fix created by deNULL - - * https://github.com/deNULL/BugPatch/blob/master/src/main/java/ru/denull/BugPatch/mod/ClientEvents.java#L45 - * - * @param evt - * - The event where a player sleeps - */ + public VanillaBedHeightFix(IPlugin minstance) { + mParent = minstance; + if (DevHelper.isValidHelperObject()) { + Method m; + if (DevHelper.isObfuscatedEnvironment()) { + m = ReflectionUtils.getMethod(EntityPlayer.class, "func_71018_a", int.class, int.class, int.class); + } else { + m = ReflectionUtils.getMethod( + net.minecraft.entity.player.EntityPlayer.class, + "sleepInBedAt", + int.class, + int.class, + int.class); + } + if (m != null) { + mSleepInBedAt = m; + mParent.log("Registering Bed Height Fix."); + Utils.registerEvent(this); + } else { + mSleepInBedAt = null; + } + } else { + mSleepInBedAt = null; + } + } - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void playerSleepInBed(PlayerSleepInBedEvent evt) { - Logger.WARNING("Sleep Event Detected. Player is sleeping at Y: " + evt.y); - if (evt.y <= 0 && isFixValid()) { - int correctY = 256 + evt.y; - if (correctY <= 0) { - Logger.WARNING( - "You're trying to sleep at y=" + evt.y + ", which is impossibly low. However, fixed y value is " - + correctY + ", which is still below 0. Falling back to default behavior."); - } else { - Logger.WARNING("You're trying to sleep at y=" + evt.y - + ". This is probably caused by overflow, stopping original event; retrying with y=" + correctY - + "."); - evt.result = EntityPlayer.EnumStatus.OTHER_PROBLEM; - try { - mSleepInBedAt.invoke(evt.entityPlayer, evt.x, correctY, evt.z); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - Logger.WARNING("Encountered an error trying to sleep."); - } - } - } else if (!isFixValid()) { - Logger.WARNING( - "Method sleepInBedAt was not found in EntityPlayer (wrong MC and/or Forge version?), unable to fix"); - } - } + public boolean isFixValid() { + return mSleepInBedAt != null; + } + /** + * Fix created by deNULL - + * https://github.com/deNULL/BugPatch/blob/master/src/main/java/ru/denull/BugPatch/mod/ClientEvents.java#L45 + * + * @param evt + * - The event where a player sleeps + */ + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void playerSleepInBed(PlayerSleepInBedEvent evt) { + Logger.WARNING("Sleep Event Detected. Player is sleeping at Y: " + evt.y); + if (evt.y <= 0 && isFixValid()) { + int correctY = 256 + evt.y; + if (correctY <= 0) { + Logger.WARNING( + "You're trying to sleep at y=" + evt.y + ", which is impossibly low. However, fixed y value is " + + correctY + ", which is still below 0. Falling back to default behavior."); + } else { + Logger.WARNING("You're trying to sleep at y=" + evt.y + + ". This is probably caused by overflow, stopping original event; retrying with y=" + correctY + + "."); + evt.result = EntityPlayer.EnumStatus.OTHER_PROBLEM; + try { + mSleepInBedAt.invoke(evt.entityPlayer, evt.x, correctY, evt.z); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + Logger.WARNING("Encountered an error trying to sleep."); + } + } + } else if (!isFixValid()) { + Logger.WARNING( + "Method sleepInBedAt was not found in EntityPlayer (wrong MC and/or Forge version?), unable to fix"); + } + } } diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java index 452c902e05..17fbc9ae29 100644 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java +++ b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java @@ -1,8 +1,5 @@ package gtPlusPlus.plugin.fixes.vanilla.music; -import java.lang.reflect.Field; -import java.util.Random; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.api.interfaces.IPlugin; @@ -10,6 +7,8 @@ import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.random.XSTR; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.preloader.CORE_Preloader; +import java.lang.reflect.Field; +import java.util.Random; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.MusicTicker; @@ -19,112 +18,111 @@ import net.minecraft.util.MathHelper; @SideOnly(Side.CLIENT) public class MusicTocker extends MusicTicker implements Runnable { - private final Random mRandom = new XSTR(); - private final Minecraft mMinecraft; - private final IPlugin mPlugin; - private ISound mSound; - private int mTimeUntilNextTrack = 100; - - public boolean mVanillaManager = false; + private final Random mRandom = new XSTR(); + private final Minecraft mMinecraft; + private final IPlugin mPlugin; + private ISound mSound; + private int mTimeUntilNextTrack = 100; + + public boolean mVanillaManager = false; + + public MusicTocker(IPlugin aPlugin) { + super(Minecraft.getMinecraft()); + mPlugin = aPlugin; + mMinecraft = Minecraft.getMinecraft(); + mPlugin.log("[BGM] Created BGM Watchdog with a delay of " + getDelay() + " ticks."); + inject(); + } + + private static int getDelay() { + return CORE_Preloader.enableWatchdogBGM; + } + + private boolean inject() { + mPlugin.log("[BGM] Inject new Watchdog into Minecraft instance."); + ReflectionUtils.setField(Minecraft.getMinecraft(), "mcMusicTicker", this); + mPlugin.log("[BGM] Verifying..."); + Field f = ReflectionUtils.getField(Minecraft.class, "mcMusicTicker"); + try { + Object m = f.get(mMinecraft); + if (m != null) { + if (m instanceof MusicTocker || m.getClass().isAssignableFrom(getClass())) { + mPlugin.log("[BGM] Success."); + return true; + } else if (m instanceof MusicTicker || m.getClass().isAssignableFrom(MusicTicker.class)) { + mPlugin.log("[BGM] Found Vanilla MusicTicker, but may be instance of MusicTocker."); + return true; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + } + + mPlugin.log("[BGM] Failed."); + return false; + } - public MusicTocker(IPlugin aPlugin) { - super(Minecraft.getMinecraft()); - mPlugin = aPlugin; - mMinecraft = Minecraft.getMinecraft(); - mPlugin.log("[BGM] Created BGM Watchdog with a delay of "+getDelay()+" ticks."); - inject(); - } + private final void updateInternalNumber() { + if (ReflectionUtils.doesFieldExist(getClass(), "field_147676_d")) { + ReflectionUtils.setField(this, "field_147676_d", mTimeUntilNextTrack); + } + } - private static int getDelay() { - return CORE_Preloader.enableWatchdogBGM; - } + private final void updateInternalSound(ISound aSound) { + if (ReflectionUtils.doesFieldExist(getClass(), "field_147678_c")) { + ReflectionUtils.setField(this, "field_147678_c", aSound); + } + } - private boolean inject() { - mPlugin.log("[BGM] Inject new Watchdog into Minecraft instance."); - ReflectionUtils.setField(Minecraft.getMinecraft(), "mcMusicTicker", this); - mPlugin.log("[BGM] Verifying..."); - Field f = ReflectionUtils.getField(Minecraft.class, "mcMusicTicker"); - try { - Object m = f.get(mMinecraft); - if (m != null) { - if (m instanceof MusicTocker || m.getClass().isAssignableFrom(getClass())) { - mPlugin.log("[BGM] Success."); - return true; - } - else if (m instanceof MusicTicker || m.getClass().isAssignableFrom(MusicTicker.class)) { - mPlugin.log("[BGM] Found Vanilla MusicTicker, but may be instance of MusicTocker."); - return true; - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - } - - mPlugin.log("[BGM] Failed."); - return false; - } - - private final void updateInternalNumber() { - if (ReflectionUtils.doesFieldExist(getClass(), "field_147676_d")) { - ReflectionUtils.setField(this, "field_147676_d", mTimeUntilNextTrack); - } - } - - private final void updateInternalSound(ISound aSound) { - if (ReflectionUtils.doesFieldExist(getClass(), "field_147678_c")) { - ReflectionUtils.setField(this, "field_147678_c", aSound); - } - } + /** + * Updates the JList with a new model. + */ + @Override + public void update() { + run(); + mVanillaManager = true; + } - /** - * Updates the JList with a new model. - */ - @Override - public void update() { - run(); - mVanillaManager = true; - } + @Override + public void run() { + MusicType musictype = this.mMinecraft.func_147109_W(); - @Override - public void run() { - MusicType musictype = this.mMinecraft.func_147109_W(); - - if (this.mSound != null) { - if (!musictype.getMusicTickerLocation().equals(this.mSound.getPositionedSoundLocation())) { - this.mMinecraft.getSoundHandler().stopSound(this.mSound); - this.mTimeUntilNextTrack = MathHelper.getRandomIntegerInRange(this.mRandom, 0, getDelay() / 2); - updateInternalNumber(); - Logger.INFO("[BGM] Adjusted BGM delay 1"); - } - if (!this.mMinecraft.getSoundHandler().isSoundPlaying(this.mSound)) { - this.mSound = null; - updateInternalSound(null); - this.mTimeUntilNextTrack = Math.min(MathHelper.getRandomIntegerInRange(this.mRandom, getDelay(), getDelay() * 2), this.mTimeUntilNextTrack); - updateInternalNumber(); - Logger.INFO("[BGM] Adjusted BGM delay 2"); - } - } - else if (this.mSound == null && this.mTimeUntilNextTrack-- <= 0) { - this.mSound = PositionedSoundRecord.func_147673_a(musictype.getMusicTickerLocation()); - updateInternalSound(mSound); - this.mMinecraft.getSoundHandler().playSound(this.mSound); - this.mTimeUntilNextTrack = getDelay(); - updateInternalNumber(); - Logger.INFO("[BGM] Adjusted BGM 3"); - } - - /* - * try { // Get Value stored in underlying object. Integer aRealDelay = - * (Integer) ReflectionUtils.getField(getClass(), "field_147676_d").get(this); - * - * if (aRealDelay == null) { return; } else { if (aRealDelay > getDelay() || - * aRealDelay <= 0) { this.mTimeUntilNextTrack = getDelay(); - * updateInternalNumber(); } else { this.mTimeUntilNextTrack -= 5 * 20; - * updateInternalNumber(); } aRealDelay = (Integer) - * ReflectionUtils.getField(getClass(), "field_147676_d").get(this); - * Logger.INFO("[BGM] Adjusted BGM - "+aRealDelay); } - * - * } catch (IllegalArgumentException | IllegalAccessException e) { } - */ - } + if (this.mSound != null) { + if (!musictype.getMusicTickerLocation().equals(this.mSound.getPositionedSoundLocation())) { + this.mMinecraft.getSoundHandler().stopSound(this.mSound); + this.mTimeUntilNextTrack = MathHelper.getRandomIntegerInRange(this.mRandom, 0, getDelay() / 2); + updateInternalNumber(); + Logger.INFO("[BGM] Adjusted BGM delay 1"); + } + if (!this.mMinecraft.getSoundHandler().isSoundPlaying(this.mSound)) { + this.mSound = null; + updateInternalSound(null); + this.mTimeUntilNextTrack = Math.min( + MathHelper.getRandomIntegerInRange(this.mRandom, getDelay(), getDelay() * 2), + this.mTimeUntilNextTrack); + updateInternalNumber(); + Logger.INFO("[BGM] Adjusted BGM delay 2"); + } + } else if (this.mSound == null && this.mTimeUntilNextTrack-- <= 0) { + this.mSound = PositionedSoundRecord.func_147673_a(musictype.getMusicTickerLocation()); + updateInternalSound(mSound); + this.mMinecraft.getSoundHandler().playSound(this.mSound); + this.mTimeUntilNextTrack = getDelay(); + updateInternalNumber(); + Logger.INFO("[BGM] Adjusted BGM 3"); + } -} \ No newline at end of file + /* + * try { // Get Value stored in underlying object. Integer aRealDelay = + * (Integer) ReflectionUtils.getField(getClass(), "field_147676_d").get(this); + * + * if (aRealDelay == null) { return; } else { if (aRealDelay > getDelay() || + * aRealDelay <= 0) { this.mTimeUntilNextTrack = getDelay(); + * updateInternalNumber(); } else { this.mTimeUntilNextTrack -= 5 * 20; + * updateInternalNumber(); } aRealDelay = (Integer) + * ReflectionUtils.getField(getClass(), "field_147676_d").get(this); + * Logger.INFO("[BGM] Adjusted BGM - "+aRealDelay); } + * + * } catch (IllegalArgumentException | IllegalAccessException e) { } + */ + } +} -- cgit