aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/plugin
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-07-17 18:09:25 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-07-17 18:09:25 +1000
commit91485c3ddbf57b9698d339576a410c51e58d7e16 (patch)
tree91ca0b5cc0cff2973c7ef2041653ef429d8152e3 /src/Java/gtPlusPlus/plugin
parent8a6ecc74bcdf930d22ca51af745c31183d982c7f (diff)
downloadGT5-Unofficial-91485c3ddbf57b9698d339576a410c51e58d7e16.tar.gz
GT5-Unofficial-91485c3ddbf57b9698d339576a410c51e58d7e16.tar.bz2
GT5-Unofficial-91485c3ddbf57b9698d339576a410c51e58d7e16.zip
+ Added a fix for beds when sleeping above Y >= 127.
% More functionality to Forge Srg handling.
Diffstat (limited to 'src/Java/gtPlusPlus/plugin')
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java44
-rw-r--r--src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java67
2 files changed, 111 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java
new file mode 100644
index 0000000000..49cdc26c38
--- /dev/null
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/Core_VanillaFixes.java
@@ -0,0 +1,44 @@
+package gtPlusPlus.plugin.fixes.vanilla;
+
+import gtPlusPlus.api.interfaces.IPlugin;
+import gtPlusPlus.plugin.manager.Core_Manager;
+
+public class Core_VanillaFixes implements IPlugin {
+
+ final static Core_VanillaFixes mInstance;
+
+ static {
+ mInstance = new Core_VanillaFixes();
+ mInstance.log("Preparing "+mInstance.getPluginName()+" for use.");
+ }
+
+ Core_VanillaFixes() {
+ Core_Manager.registerPlugin(this);
+ }
+
+ @Override
+ public boolean preInit() {
+ return false;
+ }
+
+ @Override
+ public boolean init() {
+ return false;
+ }
+
+ @Override
+ public boolean postInit() {
+ return false;
+ }
+
+ @Override
+ public String getPluginName() {
+ return "GT++ Vanilla Fixes Module";
+ }
+
+ @Override
+ public String getPluginAbbreviation() {
+ return "VFIX";
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java
new file mode 100644
index 0000000000..a6811b5a15
--- /dev/null
+++ b/src/Java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java
@@ -0,0 +1,67 @@
+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 cpw.mods.fml.relauncher.ReflectionHelper;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.preloader.DevHelper;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
+
+public class VanillaBedHeightFix {
+
+ private static final VanillaBedHeightFix mInstance;
+ private final Method mSleepInBedAt;
+
+ static {
+ mInstance = new VanillaBedHeightFix();
+ }
+
+ public VanillaBedHeightFix() {
+ if (DevHelper.isValidHelperObject()) {
+ Method m = DevHelper.getInstance().getForgeMethod(EntityPlayer.class, "sleepInBedAt", int.class, int.class, int.class);
+ if (m != null) {
+ mSleepInBedAt = m;
+ Utils.registerEvent(this);
+ }
+ else {
+ mSleepInBedAt = null;
+ }
+ }
+ else {
+ 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) {
+ if (evt.y <= 0) {
+ int correctY = 256 + evt.y;
+ if (correctY <= 0) {
+ Logger.INFO("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.INFO("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;
+ if (mSleepInBedAt != null) {
+ try {
+ mSleepInBedAt.invoke(evt.entityPlayer, evt.x, correctY, evt.z);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ Logger.INFO("Encountered an error trying to sleep.");
+ }
+ } else {
+ Logger.INFO("Method sleepInBedAt was not found in EntityPlayer (wrong MC and/or Forge version?), unable to fix");
+ }
+ }
+ }
+ }
+
+}