mirror of
https://github.com/Shiewk/BedrockDeathScreen.git
synced 2026-04-27 22:44:17 +02:00
Fix lag
This commit is contained in:
@@ -10,6 +10,7 @@ import net.minecraft.text.MutableText;
|
|||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.Util;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@@ -17,6 +18,7 @@ import java.awt.*;
|
|||||||
public class BedrockDeathScreen extends DeathScreen {
|
public class BedrockDeathScreen extends DeathScreen {
|
||||||
|
|
||||||
private int ticksSinceDeath = 0;
|
private int ticksSinceDeath = 0;
|
||||||
|
private long screenTime = 0;
|
||||||
private final Text message;
|
private final Text message;
|
||||||
private Text scoreText = Text.empty();
|
private Text scoreText = Text.empty();
|
||||||
private static final Text menuMessage = Text.translatable("deathScreen.titleScreen");
|
private static final Text menuMessage = Text.translatable("deathScreen.titleScreen");
|
||||||
@@ -31,6 +33,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
super(message, isHardcore);
|
super(message, isHardcore);
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.hardcore = isHardcore;
|
this.hardcore = isHardcore;
|
||||||
|
screenTime = Util.getMeasuringTimeNano();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hoversRespawn(int mouseX, int mouseY){
|
private boolean hoversRespawn(int mouseX, int mouseY){
|
||||||
@@ -38,7 +41,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
int startY = height - height / 3 - 9;
|
int startY = height - height / 3 - 9;
|
||||||
int endX = width/2 + 75;
|
int endX = width/2 + 75;
|
||||||
int endY = height - height / 3 + 13;
|
int endY = height - height / 3 + 13;
|
||||||
return getTotalDelta(0) > 1050 &&
|
return getTotalDelta() > 1050 &&
|
||||||
mouseX > startX &&
|
mouseX > startX &&
|
||||||
mouseX < endX &&
|
mouseX < endX &&
|
||||||
mouseY > startY &&
|
mouseY > startY &&
|
||||||
@@ -50,7 +53,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
final int startY = height - height / 3 - 9 + 30;
|
final int startY = height - height / 3 - 9 + 30;
|
||||||
final int endX = width/2 + 75;
|
final int endX = width/2 + 75;
|
||||||
final int endY = height - height / 3 + 13 + 30;
|
final int endY = height - height / 3 + 13 + 30;
|
||||||
return getTotalDelta(0) > 1050 &&
|
return getTotalDelta() > 1050 &&
|
||||||
mouseX > startX &&
|
mouseX > startX &&
|
||||||
mouseX < endX &&
|
mouseX < endX &&
|
||||||
mouseY > startY &&
|
mouseY > startY &&
|
||||||
@@ -149,13 +152,13 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
context.drawText(textRenderer, menuMessage, (width/2) - (textRenderer.getWidth(menuMessage)/2), height - height/3 - 1, textColor, false);
|
context.drawText(textRenderer, menuMessage, (width/2) - (textRenderer.getWidth(menuMessage)/2), height - height/3 - 1, textColor, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getTotalDelta(float delta){
|
public float getTotalDelta(){
|
||||||
return ticksSinceDeath * 50f + delta;
|
return (Util.getMeasuringTimeNano() - screenTime) / 1000000f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||||
final float totalDelta = getTotalDelta(delta);
|
final float totalDelta = getTotalDelta();
|
||||||
context.fill(0, 0, width, height, new Color(0, 0, 0, (int) Math.min(80, totalDelta/4f)).getRGB());
|
context.fill(0, 0, width, height, new Color(0, 0, 0, (int) Math.min(80, totalDelta/4f)).getRGB());
|
||||||
if (totalDelta > 750.0f){
|
if (totalDelta > 750.0f){
|
||||||
final int backOpacity = (int) Math.min(255, (totalDelta - 750f) / 10f);
|
final int backOpacity = (int) Math.min(255, (totalDelta - 750f) / 10f);
|
||||||
@@ -263,7 +266,7 @@ public class BedrockDeathScreen extends DeathScreen {
|
|||||||
|
|
||||||
public float calcCameraOffset(float delta){
|
public float calcCameraOffset(float delta){
|
||||||
final double e = Math.E;
|
final double e = Math.E;
|
||||||
final double del = getTotalDelta(delta) / 600d;
|
final double del = getTotalDelta() / 600d;
|
||||||
final double ep = Math.pow(e, del);
|
final double ep = Math.pow(e, del);
|
||||||
return (float) (ep / (1d + ep) * 7d + 2d);
|
return (float) (ep / (1d + ep) * 7d + 2d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public abstract class MixinGameRenderer {
|
|||||||
@Inject(at = @At("TAIL"), method = "getFov", cancellable = true)
|
@Inject(at = @At("TAIL"), method = "getFov", cancellable = true)
|
||||||
public void onFovGet(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Double> cir){
|
public void onFovGet(Camera camera, float tickDelta, boolean changingFov, CallbackInfoReturnable<Double> cir){
|
||||||
if (client.currentScreen instanceof BedrockDeathScreen bedrockDeathScreen){
|
if (client.currentScreen instanceof BedrockDeathScreen bedrockDeathScreen){
|
||||||
cir.setReturnValue(Math.min(60 + bedrockDeathScreen.getTotalDelta(client.getRenderTickCounter().getTickDelta(true)) / (405d), 80));
|
cir.setReturnValue(Math.min(60 + bedrockDeathScreen.getTotalDelta() / (405d), 80));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user