From 1ebb8d94ccd841f51cea7cb69154c9e7d0cfee37 Mon Sep 17 00:00:00 2001 From: Lily Kensa Date: Thu, 8 Aug 2024 17:28:23 +0800 Subject: [PATCH] Add AutoPlaceHack --- .../java/net/wurstclient/hack/HackList.java | 1 + .../net/wurstclient/hacks/AutoPlaceHack.java | 105 ++++++++++++++++++ .../assets/wurst/translations/en_us.json | 1 + .../assets/wurst/translations/zh_tw.json | 1 + 4 files changed, 108 insertions(+) create mode 100644 src/main/java/net/wurstclient/hacks/AutoPlaceHack.java diff --git a/src/main/java/net/wurstclient/hack/HackList.java b/src/main/java/net/wurstclient/hack/HackList.java index 2cb14067c5..d5355d7d6e 100644 --- a/src/main/java/net/wurstclient/hack/HackList.java +++ b/src/main/java/net/wurstclient/hack/HackList.java @@ -49,6 +49,7 @@ public final class HackList implements UpdateListener public final AutoLeaveHack autoLeaveHack = new AutoLeaveHack(); public final AutoLibrarianHack autoLibrarianHack = new AutoLibrarianHack(); public final AutoEatHack autoEatHack = new AutoEatHack(); + public final AutoPlaceHack autoPlaceHack = new AutoPlaceHack(); public final AutoFarmHack autoFarmHack = new AutoFarmHack(); public final AutoFishHack autoFishHack = new AutoFishHack(); public final AutoMineHack autoMineHack = new AutoMineHack(); diff --git a/src/main/java/net/wurstclient/hacks/AutoPlaceHack.java b/src/main/java/net/wurstclient/hacks/AutoPlaceHack.java new file mode 100644 index 0000000000..93f8e5eb71 --- /dev/null +++ b/src/main/java/net/wurstclient/hacks/AutoPlaceHack.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2014-2024 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.hacks; + +import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.wurstclient.Category; +import net.wurstclient.SearchTags; +import net.wurstclient.events.UpdateListener; +import net.wurstclient.hack.Hack; +import net.wurstclient.settings.CheckboxSetting; +import net.wurstclient.util.BlockUtils; + +@SearchTags({"bridge", "auto place"}) +public final class AutoPlaceHack extends Hack implements UpdateListener +{ + private final CheckboxSetting onlyBelowFeet = + new CheckboxSetting("Only Below Feet", + "Only place blocks when target block is 1 block below your feet.", + false); + private final CheckboxSetting fastPlace = + new CheckboxSetting("Always FastPlace", + "Builds as if FastPlace was enabled, even if it's not.", true); + + public AutoPlaceHack() + { + super("AutoPlace"); + setCategory(Category.BLOCKS); + addSetting(onlyBelowFeet); + addSetting(fastPlace); + } + + @Override + public void onEnable() + { + EVENTS.add(UpdateListener.class, this); + } + + @Override + public void onDisable() + { + EVENTS.remove(UpdateListener.class, this); + } + + @Override + public void onUpdate() + { + if(MC.currentScreen instanceof HandledScreen) + return; + + if(MC.itemUseCooldown != 0 && !fastPlace.isChecked()) + return; + + ClientPlayerEntity player = MC.player; + assert player != null; + + // Item in hand is not a block + if(!(player.getInventory().getStack(player.getInventory().selectedSlot) + .getItem() instanceof BlockItem)) + return; + + HitResult hitResult = MC.crosshairTarget; + if(hitResult == null || hitResult.getType() != HitResult.Type.BLOCK) + return; + + BlockHitResult blockHitResult = (BlockHitResult)hitResult; + if(blockHitResult.getSide() == Direction.UP + || blockHitResult.getSide() == Direction.DOWN) + return; + + if(!BlockUtils.canBeClicked(blockHitResult.getBlockPos())) + return; + + BlockPos blockToPlacePos = + blockHitResult.getBlockPos().offset(blockHitResult.getSide()); + if(!BlockUtils.getState(blockToPlacePos).isReplaceable()) + return; + + // Option: only below feet + if(blockToPlacePos.getY() != BlockPos.ofFloored(MC.player.getPos()) + .down().getY() && onlyBelowFeet.isChecked()) + return; + + assert MC.interactionManager != null; + MC.interactionManager.interactItem(player, Hand.MAIN_HAND); + ActionResult actionResult = MC.interactionManager.interactBlock(player, + Hand.MAIN_HAND, blockHitResult); + if(actionResult.isAccepted()) + MC.player.swingHand(Hand.MAIN_HAND); + + MC.itemUseCooldown = 4; + } +} diff --git a/src/main/resources/assets/wurst/translations/en_us.json b/src/main/resources/assets/wurst/translations/en_us.json index 677edaa2b4..a915f9462e 100644 --- a/src/main/resources/assets/wurst/translations/en_us.json +++ b/src/main/resources/assets/wurst/translations/en_us.json @@ -37,6 +37,7 @@ "description.wurst.hack.autoleave": "Automatically leaves the server when your health is low.", "description.wurst.hack.autolibrarian": "Automatically trains a villager to become a librarian that sells a specific enchanted book. You can set up an entire trading hall in no time by using this hack.", "description.wurst.hack.autoeat": "Automatically eats food when necessary.", + "description.wurst.hack.autoplace": "Right click when your crosshair is pointing to a side face of a block.", "description.wurst.setting.autoeat.target_hunger": "Tries to keep the hunger bar at or above this level, but only if it doesn't waste any hunger points.", "description.wurst.setting.autoeat.min_hunger": "Always keeps the hunger bar at or above this level, even if it wastes some hunger points.\n6.5 - Cannot cause any waste with vanilla food items.\n10.0 - Completely ignores waste and just keeps the hunger bar full.", "description.wurst.setting.autoeat.injured_hunger": "Fills the hunger bar to at least this level when you are injured, even if it wastes some hunger points.\n10.0 - fastest healing\n9.0 - slowest healing\n<9.0 - no healing\n<3.5 - no sprinting", diff --git a/src/main/resources/assets/wurst/translations/zh_tw.json b/src/main/resources/assets/wurst/translations/zh_tw.json index 2f1c9b1bf3..c4686c22c0 100644 --- a/src/main/resources/assets/wurst/translations/zh_tw.json +++ b/src/main/resources/assets/wurst/translations/zh_tw.json @@ -16,6 +16,7 @@ "description.wurst.hack.autodrop": "自動丟棄你不想要的物品(有預設)。", "description.wurst.hack.autoleave": "如果你的血量低於設定值,將會自動退出伺服器。", "description.wurst.hack.autoeat": "當必要的時候將會自動進食。", + "description.wurst.hack.bridgeclick": "當你的準心對準方塊側面時自動按右鍵。", "description.wurst.setting.autoeat.target_hunger": "嘗試將飢餓值保持在或高於此水平,但前提是它不會浪費任何飢餓值。", "description.wurst.setting.autoeat.min_hunger": "始終將飢餓條保持在此水平或以上,即使它會浪費一些飢餓點。\n6.5 - 不會對香草食品造成任何浪費。\n10.0 - 完全忽略浪費並保持飢餓條充滿。", "description.wurst.setting.autoeat.injured_hunger": "當你受傷時,將飢餓條填充到至少這個水平,即使它會浪費一些飢餓點。\n10.0 - 最快的治療\n9.0 - 最慢的治療\n<9.0 - 沒有治療\n<3.5 - 沒有衝刺",