diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java | |
parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java')
-rw-r--r-- | src/main/java/gtPlusPlus/plugin/fixes/vanilla/VanillaBedHeightFix.java | 127 |
1 files changed, 64 insertions, 63 deletions
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"); + } + } } |