-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Attribute Swap module #5727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
noramibu
wants to merge
2
commits into
MeteorDevelopment:master
Choose a base branch
from
noramibu:attribute-swap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AttributeSwap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). | ||
| * Copyright (c) Meteor Development. | ||
| */ | ||
|
|
||
| package meteordevelopment.meteorclient.systems.modules.combat; | ||
|
|
||
| import meteordevelopment.meteorclient.events.entity.player.AttackEntityEvent; | ||
| import meteordevelopment.meteorclient.events.world.TickEvent; | ||
| import meteordevelopment.meteorclient.settings.*; | ||
| import meteordevelopment.meteorclient.systems.modules.Categories; | ||
| import meteordevelopment.meteorclient.systems.modules.Module; | ||
| import meteordevelopment.meteorclient.utils.player.InvUtils; | ||
| import meteordevelopment.orbit.EventHandler; | ||
| import net.minecraft.item.MaceItem; | ||
| import net.minecraft.registry.tag.ItemTags; | ||
|
|
||
| public class AttributeSwap extends Module { | ||
| private final SettingGroup sgGeneral = settings.getDefaultGroup(); | ||
| private final SettingGroup sgWeapon = settings.createGroup("Weapon Options"); | ||
|
|
||
| private final Setting<Integer> targetSlot = sgGeneral.add(new IntSetting.Builder() | ||
| .name("target-slot") | ||
| .description("Hotbar slot to swap to (1-9).") | ||
| .defaultValue(1) | ||
| .min(1) | ||
| .sliderRange(1, 9) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> swapBack = sgGeneral.add(new BoolSetting.Builder() | ||
| .name("swap-back") | ||
| .description("Swap back to the original slot after a delay.") | ||
| .defaultValue(true) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Integer> swapBackDelay = sgGeneral.add(new IntSetting.Builder() | ||
| .name("swap-back-delay") | ||
| .description("Delay in ticks before swapping back.") | ||
| .defaultValue(2) | ||
| .min(0) | ||
| .sliderRange(0, 20) | ||
| .visible(swapBack::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> onlyOnWeapon = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("only-on-weapon") | ||
| .description("Only swaps when holding a selected weapon in hand.") | ||
| .defaultValue(false) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> sword = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("sword") | ||
| .description("Works while holding a sword.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> axe = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("axe") | ||
| .description("Works while holding an axe.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> pickaxe = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("pickaxe") | ||
| .description("Works while holding a pickaxe.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> shovel = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("shovel") | ||
| .description("Works while holding a shovel.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> hoe = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("hoe") | ||
| .description("Works while holding a hoe.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private final Setting<Boolean> mace = sgWeapon.add(new BoolSetting.Builder() | ||
| .name("mace") | ||
| .description("Works while holding a mace.") | ||
| .defaultValue(true) | ||
| .visible(onlyOnWeapon::get) | ||
| .build() | ||
| ); | ||
|
|
||
| private int backTimer; | ||
| private boolean awaitingBack; | ||
|
|
||
| public AttributeSwap() { | ||
| super(Categories.Combat, "attribute-swap", "Swaps to a target slot when you attack."); | ||
| } | ||
|
|
||
| @Override | ||
| public void onDeactivate() { | ||
| backTimer = 0; | ||
| awaitingBack = false; | ||
| } | ||
|
|
||
| @EventHandler | ||
| private void onAttack(AttackEntityEvent event) { | ||
| if (!canSwapByWeapon() || awaitingBack) return; | ||
|
|
||
| int slotIndex = targetSlot.get() - 1; | ||
| if (slotIndex < 0 || slotIndex > 8) return; | ||
| if (!InvUtils.swap(slotIndex, swapBack.get())) return; | ||
|
|
||
| awaitingBack = swapBack.get(); | ||
| if (awaitingBack) backTimer = swapBackDelay.get(); | ||
| } | ||
|
|
||
| @EventHandler | ||
| private void onTick(TickEvent.Post event) { | ||
| if (!awaitingBack) return; | ||
| if (backTimer-- > 0) return; | ||
| InvUtils.swapBack(); | ||
| awaitingBack = false; | ||
| } | ||
|
|
||
| private boolean canSwapByWeapon() { | ||
| if (!onlyOnWeapon.get()) return true; | ||
| return InvUtils.testInMainHand(itemStack -> { | ||
| if (sword.get() && itemStack.isIn(ItemTags.SWORDS)) return true; | ||
| if (axe.get() && itemStack.isIn(ItemTags.AXES)) return true; | ||
| if (pickaxe.get() && itemStack.isIn(ItemTags.PICKAXES)) return true; | ||
| if (shovel.get() && itemStack.isIn(ItemTags.SHOVELS)) return true; | ||
| if (hoe.get() && itemStack.isIn(ItemTags.HOES)) return true; | ||
| if (mace.get() && itemStack.getItem() instanceof MaceItem) return true; | ||
| return false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.