Skip to content

Commit

Permalink
Make the button optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 11, 2023
1 parent c8b1c95 commit 5e22f6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
13 changes: 13 additions & 0 deletions src/main/java/net/wurstclient/hacks/AutoRespawnHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@

import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.WurstClient;
import net.wurstclient.events.DeathListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.CheckboxSetting;

@SearchTags({"auto respawn", "AutoRevive", "auto revive"})
public final class AutoRespawnHack extends Hack implements DeathListener
{
private final CheckboxSetting button =
new CheckboxSetting("Death screen button", "Shows a button on the death"
+ " screen that lets you quickly enable AutoRespawn.", true);

public AutoRespawnHack()
{
super("AutoRespawn");
setCategory(Category.COMBAT);
addSetting(button);
}

@Override
Expand All @@ -39,4 +46,10 @@ public void onDeath()
MC.player.requestRespawn();
MC.setScreen(null);
}

public boolean shouldShowButton()
{
return WurstClient.INSTANCE.isEnabled() && !isEnabled()
&& button.isChecked();
}
}
26 changes: 9 additions & 17 deletions src/main/java/net/wurstclient/mixin/DeathScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,19 @@ private void onTick(CallbackInfo ci)
@Inject(at = @At("TAIL"), method = "init()V")
private void onInit(CallbackInfo ci)
{
if(!WurstClient.INSTANCE.isEnabled())
AutoRespawnHack autoRespawn =
WurstClient.INSTANCE.getHax().autoRespawnHack;

if(!autoRespawn.shouldShowButton())
return;

addAutoRespawnButton();
}

private void addAutoRespawnButton()
{
int backButtonX = width / 2 - 100;
int backButtonY = height / 4;

addDrawableChild(ButtonWidget
.builder(Text.literal("AutoRespawn"), b -> pressAutoRespawn())
.dimensions(backButtonX, backButtonY + 48, 200, 20).build());
}

private void pressAutoRespawn()
{
AutoRespawnHack autoRespawn =
WurstClient.INSTANCE.getHax().autoRespawnHack;

autoRespawn.setEnabled(!autoRespawn.isEnabled());
addDrawableChild(
ButtonWidget.builder(Text.literal("AutoRespawn: OFF"), b -> {
autoRespawn.setEnabled(true);
autoRespawn.onDeath();
}).dimensions(backButtonX, backButtonY + 48, 200, 20).build());
}
}

0 comments on commit 5e22f6b

Please sign in to comment.