diff options
| author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-09-28 13:25:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-28 11:25:01 +0000 |
| commit | 86f1765b171f4cc6f163b8027d1330f4e5094e2d (patch) | |
| tree | b6e293bd3c976558fc4e4b7190e4d342c2ddc555 /src/main/java/gtPlusPlus/plugin/fixes/vanilla/music | |
| parent | 6b1f145f5028f1bc92cf478e5963224e7d94b5cd (diff) | |
| download | GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.tar.gz GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.tar.bz2 GT5-Unofficial-86f1765b171f4cc6f163b8027d1330f4e5094e2d.zip | |
Remove more reflection + reorganize mixin accessors packages (#3260)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
Diffstat (limited to 'src/main/java/gtPlusPlus/plugin/fixes/vanilla/music')
| -rw-r--r-- | src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java b/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java deleted file mode 100644 index 46dec56124..0000000000 --- a/src/main/java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java +++ /dev/null @@ -1,131 +0,0 @@ -package gtPlusPlus.plugin.fixes.vanilla.music; - -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; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.util.MathHelper; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.objects.XSTR; -import gtPlusPlus.api.interfaces.IPlugin; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.config.ASMConfiguration; -import gtPlusPlus.core.util.reflect.ReflectionUtils; - -@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; - - 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 ASMConfiguration.general.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; - } - - private void updateInternalNumber() { - if (ReflectionUtils.doesFieldExist(getClass(), "field_147676_d")) { - ReflectionUtils.setField(this, "field_147676_d", mTimeUntilNextTrack); - } - } - - private 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; - } - - @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) { } - */ - } -} |
