diff --git a/src/main/java/de/hysky/skyblocker/skyblock/SmoothAOTE.java b/src/main/java/de/hysky/skyblocker/skyblock/SmoothAOTE.java index 9f533382d9..989a7990c4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/SmoothAOTE.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/SmoothAOTE.java @@ -7,14 +7,17 @@ import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.Perspective; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -40,6 +43,7 @@ public class SmoothAOTE { public static void init() { UseItemCallback.EVENT.register(SmoothAOTE::onItemInteract); + UseBlockCallback.EVENT.register(SmoothAOTE::onBlockInteract); } public static void playerTeleported() { @@ -68,36 +72,47 @@ private static int extractTunedCustomData(NbtCompound customData, int baseRange) return customData != null && customData.contains("tuned_transmission") ? baseRange + customData.getInt("tuned_transmission") : baseRange; } + + private static TypedActionResult onItemInteract(PlayerEntity playerEntity, World world, Hand hand) { + if (CLIENT.player == null) { + return null; + } + calculateTeleportUse(hand); + return TypedActionResult.pass(CLIENT.player.getStackInHand(hand)); + } + + private static ActionResult onBlockInteract(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) { + calculateTeleportUse(hand); + return ActionResult.PASS; + } + /** * Finds if a player uses a teleport and then saves the start position and time. then works out final position and saves that too * - * @param playerEntity the player - * @param world the world - * @param hand what the player is holding - * @return if the right click should go though + * @param hand what the player is holding */ - private static TypedActionResult onItemInteract(PlayerEntity playerEntity, World world, Hand hand) { + private static void calculateTeleportUse(Hand hand) { //stop checking if player does not exist if (CLIENT.player == null || CLIENT.world == null) { - return null; + return; } //get return item ItemStack stack = CLIENT.player.getStackInHand(hand); //make sure it's not disabled if (teleportDisabled) { - return TypedActionResult.pass(stack); + return; } // make sure the camera is not in 3rd person if (CLIENT.options.getPerspective() != Perspective.FIRST_PERSON) { - return TypedActionResult.pass(stack); + return; } //make sure the player is in an area teleporting is allowed not allowed in glacite mineshafts and floor 7 boss if (!isAllowedLocation()) { - return TypedActionResult.pass(stack); + return; } //work out if the player is holding a teleporting item that is enabled and if so how far the item will take them @@ -112,7 +127,7 @@ private static TypedActionResult onItemInteract(PlayerEntity playerEn distance = 3; break; } - return TypedActionResult.pass(stack); + return; } case "ASPECT_OF_THE_LEECH_2" -> { @@ -120,7 +135,7 @@ private static TypedActionResult onItemInteract(PlayerEntity playerEn distance = 4; break; } - return TypedActionResult.pass(stack); + return; } case "ASPECT_OF_THE_END", "ASPECT_OF_THE_VOID" -> { if (CLIENT.options.sneakKey.isPressed() && customData.getInt("ethermerge") == 1) { @@ -132,38 +147,38 @@ private static TypedActionResult onItemInteract(PlayerEntity playerEn distance = extractTunedCustomData(customData, 8); break; } - return TypedActionResult.pass(stack); + return; } case "ETHERWARP_CONDUIT" -> { if (SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.enableEtherTransmission) { distance = extractTunedCustomData(customData, 57); break; } - return TypedActionResult.pass(stack); + return; } case "SINSEEKER_SCYTHE" -> { if (SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.enableSinrecallTransmission) { distance = extractTunedCustomData(customData, 4); break; } - return TypedActionResult.pass(stack); + return; } case "NECRON_BLADE", "ASTRAEA", "HYPERION", "SCYLLA", "VALKYRIE" -> { if (SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.enableWitherImpact) { distance = 10; break; } - return TypedActionResult.pass(stack); + return; } default -> { - return TypedActionResult.pass(stack); + return; } } //make sure the player has enough mana to do the teleport Matcher manaNeeded = ItemUtils.getLoreLineIfMatch(heldItem, MANA_LORE); if (manaNeeded != null && manaNeeded.matches()) { if (SkyblockerMod.getInstance().statusBarTracker.getMana().value() < Integer.parseInt(manaNeeded.group(1))) { // todo the players mana can lag behind as it is updated server side. client side mana calculations would help with this - return TypedActionResult.pass(stack); + return; } } @@ -193,7 +208,7 @@ private static TypedActionResult onItemInteract(PlayerEntity playerEn teleportVector = raycast(distance, look, startPos); if (teleportVector == null) { startPos = null; - return TypedActionResult.pass(stack); + return; } //round the vector values to 1dp @@ -203,8 +218,6 @@ private static TypedActionResult onItemInteract(PlayerEntity playerEn teleportVector = teleportVector.subtract(offsetVec); //add 1 to teleports ahead teleportsAhead += 1; - - return TypedActionResult.pass(stack); } private static double roundToCenter(double input) {