From 27b242b1d0d40d5b107a09718833400a14395fe1 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 3 Jun 2024 21:18:55 +0100 Subject: add ping measure and improve mastery mastery now counts down to when to release the bow --- .../skyblocker/skyblock/crimson/dojo/DojoManager.java | 16 ++++++++++++++++ .../skyblock/crimson/dojo/MasteryTestHelper.java | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/crimson') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java index 3de425ec..8278f089 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -12,9 +12,11 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.fabricmc.fabric.api.event.player.AttackEntityCallback; import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.c2s.query.QueryPingC2SPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -64,6 +66,7 @@ public class DojoManager { protected static DojoChallenges currentChallenge = DojoChallenges.NONE; public static boolean inArena = false; + protected static long ping = -1; public static void init() { ClientReceiveMessageEvents.GAME.register(DojoManager::onMessage); @@ -98,6 +101,8 @@ public class DojoManager { } if (Objects.equals(Formatting.strip(text.getString()), START_MESSAGE)) { inArena = true; + //update the players ping + getPing(); return; } if (!inArena) { @@ -121,6 +126,16 @@ public class DojoManager { } } + private static void getPing() { + ClientPlayNetworkHandler networkHandler = CLIENT.getNetworkHandler(); + if (networkHandler != null) { + networkHandler.sendPacket(new QueryPingC2SPacket(System.currentTimeMillis())); + } + } + public static void onPingResult(long ping) { + DojoManager.ping = ping; + } + private static void update() { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; @@ -237,4 +252,5 @@ public class DojoManager { case TENACITY -> TenacityTestHelper.render(context); } } + } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java index 393e8f06..172de7f5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java @@ -7,6 +7,7 @@ import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.text.Text; +import net.minecraft.util.Util; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -16,9 +17,12 @@ import java.util.*; import java.util.List; public class MasteryTestHelper { - + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); private static final DecimalFormat FORMATTER = new DecimalFormat("0.00"); - private static final int BLOCK_LIFE_TIME = 6850; + /** + * How long it takes for a block to turn red + */ + private static final int BLOCK_LIFE_TIME = 6550; private static final List blockOrder = new ArrayList<>(); private static final Map endTimes = new HashMap<>(); @@ -29,9 +33,15 @@ public class MasteryTestHelper { } protected static void onBlockUpdate(BlockPos pos, BlockState state) { + if (CLIENT == null || CLIENT.player == null) { + return; + } if (state.isOf(Blocks.LIME_WOOL)) { blockOrder.add(pos); - endTimes.put(pos, System.currentTimeMillis() + BLOCK_LIFE_TIME); + //add lifetime of a block to the time to get time when block expires + // work out how long it will take between the player firing and arrow hitting the block and to subtract from time + long travelTime = (long) (CLIENT.player.getPos().distanceTo(pos.toCenterPos()) * (1000 / 60)); //an arrow speed is about 60 blocks a second from a full draw + endTimes.put(pos, System.currentTimeMillis() + BLOCK_LIFE_TIME - DojoManager.ping - travelTime); } if (state.isAir()) { blockOrder.remove(pos); -- cgit