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.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
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.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
@@ -24,20 +23,18 @@ public class RespawnBackoffClient implements ClientModInitializer {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
HudRenderCallback.EVENT.register((guiGraphics, tickDelta) -> {
|
|
||||||
if (!overlayActive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Minecraft client = Minecraft.getInstance();
|
|
||||||
if (client.player == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long remainingMs = Math.max(0L, cooldownEndEpochMs - System.currentTimeMillis());
|
|
||||||
renderOverlay(guiGraphics, client, remainingMs);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderOverlay(GuiGraphics graphics, Minecraft client, long remainingMs) {
|
/** 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;
|
||||||
|
}
|
||||||
|
Minecraft client = Minecraft.getInstance();
|
||||||
|
if (client.player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long remainingMs = Math.max(0L, cooldownEndEpochMs - System.currentTimeMillis());
|
||||||
int w = client.getWindow().getGuiScaledWidth();
|
int w = client.getWindow().getGuiScaledWidth();
|
||||||
int h = client.getWindow().getGuiScaledHeight();
|
int h = client.getWindow().getGuiScaledHeight();
|
||||||
graphics.fill(0, 0, w, h, 0xFF000000);
|
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);
|
Component line = Component.translatable("respawn_backoff.hud.countdown", time);
|
||||||
|
|
||||||
int textWidth = client.font.width(line);
|
int textWidth = client.font.width(line);
|
||||||
graphics.drawString(
|
graphics.drawString(client.font, line, (w - textWidth) / 2, h / 2, 0xFFFFFF, false);
|
||||||
client.font,
|
|
||||||
line,
|
|
||||||
(w - textWidth) / 2,
|
|
||||||
h / 2,
|
|
||||||
0xFFFFFF,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearForDisconnect() {
|
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": [
|
"mixins": [
|
||||||
"ServerPlayerGameModeMixin"
|
"ServerPlayerGameModeMixin"
|
||||||
],
|
],
|
||||||
|
"client": [
|
||||||
|
"ToastManagerMixin"
|
||||||
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user