Skip to content

Instantly share code, notes, and snippets.

@Densamisten
Created September 25, 2024 18:08
Show Gist options
  • Save Densamisten/f4363ca58835a66344a7a2b5bf842a0a to your computer and use it in GitHub Desktop.
Save Densamisten/f4363ca58835a66344a7a2b5bf842a0a to your computer and use it in GitHub Desktop.
package exonihility.client.module.movement;
import exonihility.client.config.Config;
import exonihility.client.module.Extension;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.MovementType;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.world.GameMode;
public class AutoLadder extends Extension {
private final MinecraftClient client = MinecraftClient.getInstance();
private boolean ladderPlaced = false;
private int tickCounter = 0;
// Constructor to initialize the module with a name, summary, and category
public AutoLadder() {
super("AutoLadder", "Automatically places and breaks a ladder beneath the player to climb up infinitely.", Category.MOVEMENT);
}
@Override
public void tick() {
// Check if the module is enabled
if (!isEnabled() || client.player == null || client.world == null) {
return;
}
// Check if the player has ladders in inventory and is not in Creative mode
if (hasLaddersInInventory() && client.interactionManager.getCurrentGameMode() != GameMode.CREATIVE) {
handleLadderClimb();
}
}
// Method to check if the player has at least one ladder in their inventory
private boolean hasLaddersInInventory() {
return client.player.getInventory().count(Items.LADDER) > 0;
}
// Method to handle ladder placement, jumping, and breaking the ladder
private void handleLadderClimb() {
BlockPos currentPos = client.player.getBlockPos();
BlockPos ladderPos = currentPos.down();
if (ladderPlaced) {
// If a ladder is currently placed, wait a few ticks before breaking it
tickCounter++;
if (tickCounter >= 10) { // Adjust timing as necessary
breakLadder(ladderPos);
tickCounter = 0; // Reset counter after breaking
}
} else {
// Jump and place the ladder
jumpAndPlaceLadder(ladderPos);
}
}
// Method to break the ladder beneath the player
private void breakLadder(BlockPos ladderPos) {
// Simulate breaking the ladder block
client.interactionManager.attackBlock(ladderPos, Direction.UP);
ladderPlaced = false;
}
// Method to make the player jump and place the ladder beneath them
private void jumpAndPlaceLadder(BlockPos ladderPos) {
// Make the player jump
if (client.player.isOnGround()) {
client.player.jump();
}
// Place the ladder beneath the player
if (client.world.getBlockState(ladderPos).isAir()) {
client.interactionManager.interactBlock(
client.player,
Hand.MAIN_HAND,
new BlockHitResult(new Vec3d(ladderPos.getX(), ladderPos.getY(), ladderPos.getZ()), Direction.UP, ladderPos, false)
);
ladderPlaced = true;
}
}
@Override
public void onEnabled() {
super.onEnabled();
ladderPlaced = false;
tickCounter = 0;
}
@Override
public void onDisabled() {
super.onDisabled();
ladderPlaced = false;
tickCounter = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment