aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/plugin/fixes/vanilla
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-12-30 01:48:09 +0000
committerGitHub <noreply@github.com>2019-12-30 01:48:09 +0000
commit5af823e80a611090216375fecd3794d345446830 (patch)
treec54a19977b4a25cb86f54394eb9711aaf268efe3 /src/Java/gtPlusPlus/plugin/fixes/vanilla
parenta731e939c6b9a70ac9fd444dbf06243f63f29c06 (diff)
parentcc825179dce70a5f2c4a13730639e3300243e21a (diff)
downloadGT5-Unofficial-5af823e80a611090216375fecd3794d345446830.tar.gz
GT5-Unofficial-5af823e80a611090216375fecd3794d345446830.tar.bz2
GT5-Unofficial-5af823e80a611090216375fecd3794d345446830.zip
Merge pull request #525 from alkcorp/DevTop
+ 6 Months of work, let's get the ball rolling.
Diffstat (limited to 'src/Java/gtPlusPlus/plugin/fixes/vanilla')
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java23
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java63
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java2
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java130
4 files changed, 215 insertions, 3 deletions
diff --git a/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java
index cf9676635d..2bfd05e5be 100644
--- a/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java
@@ -11,10 +11,12 @@ public class Core_VanillaFixes implements IPlugin {
final static Core_VanillaFixes mInstance;
final static VanillaBedHeightFix mBedFixInstance;
+ final static VanillaBackgroundMusicFix mMusicFixInstance;
static {
mInstance = new Core_VanillaFixes();
mBedFixInstance = new VanillaBedHeightFix(mInstance);
+ mMusicFixInstance = new VanillaBackgroundMusicFix(mInstance);
mInstance.log("Preparing "+mInstance.getPluginName()+" for use.");
}
@@ -38,6 +40,17 @@ public class Core_VanillaFixes implements IPlugin {
}
@Override
+ public boolean serverStart() {
+ mMusicFixInstance.manage();
+ return true;
+ }
+
+ @Override
+ public boolean serverStop() {
+ return true;
+ }
+
+ @Override
public String getPluginName() {
return "GT++ Vanilla Fixes Module";
}
@@ -48,6 +61,7 @@ public class Core_VanillaFixes implements IPlugin {
}
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");
@@ -58,7 +72,7 @@ public class Core_VanillaFixes implements IPlugin {
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(Items.egg), "egg");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.end_stone), "endstone");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.vine), "vine");
registerToOreDict(ItemUtils.getSimpleStack(Blocks.cactus), "blockCactus");
@@ -69,7 +83,12 @@ public class Core_VanillaFixes implements IPlugin {
}
private void registerToOreDict(ItemStack aStack, String aString) {
- mInstance.log("Registering "+aStack.getDisplayName()+" to OreDictionary under the tag '"+aString+"'. (Added to Forge in 1.8.9)");
+ 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/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java
new file mode 100644
index 0000000000..bfd73407f7
--- /dev/null
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBackgroundMusicFix.java
@@ -0,0 +1,63 @@
+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;
+
+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();
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java
index 5f3b1d8abd..f33cc71fc6 100644
--- a/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java
@@ -23,7 +23,7 @@ public class VanillaBedHeightFix implements IBugFix {
mParent = minstance;
if (DevHelper.isValidHelperObject()) {
Method m;
- if (DevHelper.IsObfuscatedEnvironment()) {
+ if (DevHelper.isObfuscatedEnvironment()) {
m = ReflectionUtils.getMethod(EntityPlayer.class, "func_71018_a", int.class, int.class, int.class);
}
else {
diff --git a/src/Java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java
new file mode 100644
index 0000000000..452c902e05
--- /dev/null
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/music/MusicTocker.java
@@ -0,0 +1,130 @@
+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;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.random.XSTR;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
+import gtPlusPlus.preloader.CORE_Preloader;
+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;
+
+@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 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;
+ }
+
+ 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;
+ }
+
+ @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) { }
+ */
+ }
+
+} \ No newline at end of file