Skip to content

Commit

Permalink
Merge #792 (AutoRespawn button on death screen) into v7.39
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 11, 2023
2 parents 537e6a7 + 5e22f6b commit 132ab78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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();
}
}
23 changes: 22 additions & 1 deletion src/main/java/net/wurstclient/mixin/DeathScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import net.wurstclient.WurstClient;
import net.wurstclient.event.EventManager;
import net.wurstclient.events.DeathListener.DeathEvent;
import net.wurstclient.hacks.AutoRespawnHack;

@Mixin(DeathScreen.class)
public abstract class DeathScreenMixin extends Screen
Expand All @@ -27,9 +29,28 @@ private DeathScreenMixin(WurstClient wurst, Text title)
super(title);
}

@Inject(at = @At(value = "TAIL"), method = "tick()V")
@Inject(at = @At("TAIL"), method = "tick()V")
private void onTick(CallbackInfo ci)
{
EventManager.fire(DeathEvent.INSTANCE);
}

@Inject(at = @At("TAIL"), method = "init()V")
private void onInit(CallbackInfo ci)
{
AutoRespawnHack autoRespawn =
WurstClient.INSTANCE.getHax().autoRespawnHack;

if(!autoRespawn.shouldShowButton())
return;

int backButtonX = width / 2 - 100;
int backButtonY = height / 4;

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

0 comments on commit 132ab78

Please sign in to comment.