Spawn player back after timer runs out
This commit is contained in:
@@ -3,7 +3,6 @@ package net.respawnbackoff.client;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -24,7 +23,10 @@ public class RespawnBackoffClient implements ClientModInitializer {
|
||||
});
|
||||
});
|
||||
|
||||
HudRenderCallback.EVENT.register((guiGraphics, tickDelta) -> {
|
||||
}
|
||||
|
||||
/** Invoked from a mixin after the toast manager draws (post-chat HUD), so opaque blackout sits above vanilla UI. */
|
||||
public static void renderPenaltyOverlay(GuiGraphics graphics) {
|
||||
if (!overlayActive) {
|
||||
return;
|
||||
}
|
||||
@@ -33,11 +35,6 @@ public class RespawnBackoffClient implements ClientModInitializer {
|
||||
return;
|
||||
}
|
||||
long remainingMs = Math.max(0L, cooldownEndEpochMs - System.currentTimeMillis());
|
||||
renderOverlay(guiGraphics, client, remainingMs);
|
||||
});
|
||||
}
|
||||
|
||||
private static void renderOverlay(GuiGraphics graphics, Minecraft client, long remainingMs) {
|
||||
int w = client.getWindow().getGuiScaledWidth();
|
||||
int h = client.getWindow().getGuiScaledHeight();
|
||||
graphics.fill(0, 0, w, h, 0xFF000000);
|
||||
@@ -49,14 +46,7 @@ public class RespawnBackoffClient implements ClientModInitializer {
|
||||
Component line = Component.translatable("respawn_backoff.hud.countdown", time);
|
||||
|
||||
int textWidth = client.font.width(line);
|
||||
graphics.drawString(
|
||||
client.font,
|
||||
line,
|
||||
(w - textWidth) / 2,
|
||||
h / 2,
|
||||
0xFFFFFF,
|
||||
false
|
||||
);
|
||||
graphics.drawString(client.font, line, (w - textWidth) / 2, h / 2, 0xFFFFFF, false);
|
||||
}
|
||||
|
||||
public static void clearForDisconnect() {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.respawnbackoff.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.respawnbackoff.client.RespawnBackoffClient;
|
||||
|
||||
/**
|
||||
* Intermediary name for {@code net.minecraft.client.toast.ToastManager} (Mojang mappings hide this on compile classpath).
|
||||
*/
|
||||
@Mixin(targets = "net.minecraft.class_374")
|
||||
public class ToastManagerMixin {
|
||||
@Inject(method = "method_1996", at = @At("RETURN"))
|
||||
private void respawn_backoff$afterToasts(GuiGraphics graphics, CallbackInfo ci) {
|
||||
RespawnBackoffClient.renderPenaltyOverlay(graphics);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
"mixins": [
|
||||
"ServerPlayerGameModeMixin"
|
||||
],
|
||||
"client": [
|
||||
"ToastManagerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user