Skip to content

Commit

Permalink
Require attack to always be held
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryhon0 committed Dec 11, 2024
1 parent ed60270 commit 4fa017e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ protected AutoswitchSettingsScreen(Screen parent) {
}

SwitchButton enabledButton;
SwitchButton requiresAttackHeldButton;
SwitchButton returnToPreviousSlotButton;
SwitchButton sneakToggleButton;
ButtonWidget doneButton;
Expand Down Expand Up @@ -47,26 +46,9 @@ public void setToggled(boolean toggled) {
enabledButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

requiresAttackHeldButton = new SwitchButton(
returnToPreviousSlotButton = new SwitchButton(
enabledButton.getX(), enabledButton.getY() + enabledButton.getHeight(),
enabledButton.getWidth(), enabledButton.getHeight(),
SimpleAutoswitch.requiresAttackHeld) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
SimpleAutoswitch.requiresAttackHeld = toggled;
}
};
addDrawableChild(requiresAttackHeldButton);
addSelectableChild(requiresAttackHeldButton);
t = new TextWidget(Text.translatable("simpleautoswitch.menuscreen.requiresAttackHeld"), textRenderer);
t.setPosition((width / 2) - (panelWidth / 2),
requiresAttackHeldButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

returnToPreviousSlotButton = new SwitchButton(
requiresAttackHeldButton.getX(), requiresAttackHeldButton.getY() + requiresAttackHeldButton.getHeight(),
requiresAttackHeldButton.getWidth(), requiresAttackHeldButton.getHeight(),
SimpleAutoswitch.returnToPreviousSlot) {
@Override
public void setToggled(boolean toggled) {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/xyz/ryhon/simpleautoswitch/SimpleAutoswitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
Expand All @@ -30,7 +29,6 @@ public class SimpleAutoswitch implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("simple-autoswitch");

static public boolean enabled = true;
static public boolean requiresAttackHeld = true;
static public boolean returnToPreviousSlot = true;
static public boolean sneakToggle = true;

Expand Down Expand Up @@ -109,10 +107,7 @@ boolean shouldSwitch(MinecraftClient client) {
if (sneakToggle && client.player.isSneaking())
return false;

if (requiresAttackHeld)
return client.options.attackKey.isPressed();
else
return true;
return client.options.attackKey.isPressed();
}

void switchToBestSlot(MinecraftClient client) {
Expand Down Expand Up @@ -164,8 +159,6 @@ static void loadConfig() {

if (jo.has("enabled"))
enabled = jo.get("enabled").getAsBoolean();
if (jo.has("requiresAttackHeld"))
requiresAttackHeld = jo.get("requiresAttackHeld").getAsBoolean();
if (jo.has("returnToPreviousSlot"))
returnToPreviousSlot = jo.get("returnToPreviousSlot").getAsBoolean();
if (jo.has("sneakToggle"))
Expand All @@ -180,7 +173,6 @@ static void saveConfig() {
JsonObject jo = new JsonObject();

jo.add("enabled", new JsonPrimitive(enabled));
jo.add("requiresAttackHeld", new JsonPrimitive(requiresAttackHeld));
jo.add("returnToPreviousSlot", new JsonPrimitive(returnToPreviousSlot));
jo.add("sneakToggle", new JsonPrimitive(sneakToggle));

Expand Down

0 comments on commit 4fa017e

Please sign in to comment.