Skip to content

Commit

Permalink
fix not working when clicking dirt with shovel
Browse files Browse the repository at this point in the history
  • Loading branch information
olim88 committed Sep 4, 2024
1 parent 3e63440 commit 316ee27
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/main/java/de/hysky/skyblocker/skyblock/SmoothAOTE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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<ItemStack> 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<ItemStack> 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
Expand All @@ -112,15 +127,15 @@ private static TypedActionResult<ItemStack> onItemInteract(PlayerEntity playerEn
distance = 3;
break;
}
return TypedActionResult.pass(stack);
return;

}
case "ASPECT_OF_THE_LEECH_2" -> {
if (SkyblockerConfigManager.get().uiAndVisuals.smoothAOTE.enableWeirdTransmission) {
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) {
Expand All @@ -132,38 +147,38 @@ private static TypedActionResult<ItemStack> 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;
}
}

Expand Down Expand Up @@ -193,7 +208,7 @@ private static TypedActionResult<ItemStack> onItemInteract(PlayerEntity playerEn
teleportVector = raycast(distance, look, startPos);
if (teleportVector == null) {
startPos = null;
return TypedActionResult.pass(stack);
return;
}
//round the vector values to 1dp

Expand All @@ -203,8 +218,6 @@ private static TypedActionResult<ItemStack> onItemInteract(PlayerEntity playerEn
teleportVector = teleportVector.subtract(offsetVec);
//add 1 to teleports ahead
teleportsAhead += 1;

return TypedActionResult.pass(stack);
}

private static double roundToCenter(double input) {
Expand Down

0 comments on commit 316ee27

Please sign in to comment.