diff options
| author | BuildTools <james.jenour@protonmail.com> | 2021-02-05 03:52:39 +0800 |
|---|---|---|
| committer | BuildTools <james.jenour@protonmail.com> | 2021-02-05 03:52:39 +0800 |
| commit | c40f8e737c62c8dadef294f8621716529d354796 (patch) | |
| tree | 3f0fb8be376d09e4fa1a7d95da0624359d8f67b1 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java | |
| parent | 5ea3130efceca3148334a613471cec7f22acdf8c (diff) | |
| download | notenoughupdates-c40f8e737c62c8dadef294f8621716529d354796.tar.gz notenoughupdates-c40f8e737c62c8dadef294f8621716529d354796.tar.bz2 notenoughupdates-c40f8e737c62c8dadef294f8621716529d354796.zip | |
PRE15
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java new file mode 100644 index 00000000..9ccaff31 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FlyFix.java @@ -0,0 +1,70 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.SBInfo; +import net.minecraft.client.Minecraft; +import net.minecraft.network.play.client.C13PacketPlayerAbilities; +import net.minecraft.network.play.server.S39PacketPlayerAbilities; + +public class FlyFix { + + private static boolean serverWantFly = false; + private static boolean clientWantFly = false; + private static long lastAbilitySend = 0; + + public static void onSendAbilities(C13PacketPlayerAbilities packet) { + if(!NotEnoughUpdates.INSTANCE.config.misc.flyFix) return; + if(Minecraft.getMinecraft().thePlayer == null) return; + if(!Minecraft.getMinecraft().thePlayer.capabilities.allowFlying) return; + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; + if(SBInfo.getInstance().getLocation() == null) return; + if(!SBInfo.getInstance().getLocation().equals("dynamic")) return; + + long currentTime = System.currentTimeMillis(); + + clientWantFly = packet.isFlying(); + if(clientWantFly != serverWantFly) lastAbilitySend = currentTime; + } + + public static void onReceiveAbilities(S39PacketPlayerAbilities packet) { + if(!NotEnoughUpdates.INSTANCE.config.misc.flyFix) return; + if(Minecraft.getMinecraft().thePlayer == null) return; + if(!Minecraft.getMinecraft().thePlayer.capabilities.allowFlying) return; + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; + if(SBInfo.getInstance().getLocation() == null) return; + if(!SBInfo.getInstance().getLocation().equals("dynamic")) return; + + long currentTime = System.currentTimeMillis(); + + serverWantFly = packet.isFlying(); + if(serverWantFly != clientWantFly) { + if(currentTime - lastAbilitySend > 0 && currentTime - lastAbilitySend < 500) { + packet.setFlying(clientWantFly); + } else { + clientWantFly = serverWantFly; + } + } + } + + public static void tick() { + if(!NotEnoughUpdates.INSTANCE.config.misc.flyFix) return; + if(Minecraft.getMinecraft().thePlayer == null) return; + if(!Minecraft.getMinecraft().thePlayer.capabilities.allowFlying) return; + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; + if(SBInfo.getInstance().getLocation() == null) return; + if(!SBInfo.getInstance().getLocation().equals("dynamic")) return; + + long currentTime = System.currentTimeMillis(); + + if(currentTime - lastAbilitySend > 1000 && currentTime - lastAbilitySend < 5000) { + if(clientWantFly != serverWantFly) { + Minecraft.getMinecraft().thePlayer.capabilities.isFlying = serverWantFly; + Minecraft.getMinecraft().thePlayer.sendPlayerAbilities(); + clientWantFly = serverWantFly; + } + } else { + clientWantFly = Minecraft.getMinecraft().thePlayer.capabilities.isFlying; + } + } + +} |
