add timer autoadjust

This commit is contained in:
Daniella / Tove 2024-06-02 01:45:01 +02:00
parent 5e80dfa18e
commit 602d17bd8c
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
9 changed files with 57 additions and 12 deletions

View file

@ -21,8 +21,8 @@ public abstract class PacketEvent extends CancellableEvent {
}
}
public static class Read extends PacketEvent {
public Read(Packet<?> packet) {
public static class Receive extends PacketEvent {
public Receive(Packet<?> packet) {
super(packet);
}
}

View file

@ -131,7 +131,7 @@ public class ChatCrypt extends Feature {
String sentOriginal = null;
String sentEncrypted = null;
public void onPacketRead(PacketEvent.Read e) {
public void onPacketRead(PacketEvent.Receive e) {
if (e.getPacket() instanceof SPacketChat) {
String message = ((SPacketChat) e.getPacket()).getChatComponent().getUnformattedText();

View file

@ -67,7 +67,7 @@ public class ChatExtras extends Feature {
}
public void onChat(PacketEvent.Read event) {
public void onChat(PacketEvent.Receive event) {
if (event.getPacket() instanceof SPacketChat && antiPopLag) {
String message = ((SPacketChat) event.getPacket()).getChatComponent().getUnformattedText();
Pattern pattern = Pattern.compile("[^\t\r\n\\x20-\\x7E]+", Pattern.CASE_INSENSITIVE);

View file

@ -49,7 +49,7 @@ public class ChatFilter extends Feature {
return "ChatFilter";
}
public void onPacketRead(PacketEvent.Read event) {
public void onPacketRead(PacketEvent.Receive event) {
if(event.getPacket() instanceof SPacketChat) {
SPacketChat packet = ((SPacketChat) event.getPacket());
String message = packet.getChatComponent().getFormattedText();

View file

@ -110,7 +110,7 @@ public class Client extends Feature {
ServerDataManager.onPlayerDestroy();
}
public void onPacket(PacketEvent.Read packetEvent) {
public void onPacket(PacketEvent.Receive packetEvent) {
Packet<?> packet = packetEvent.getPacket();
if (packet instanceof SPacketTimeUpdate) {
ServerDataManager.onTimePacket();

View file

@ -1,5 +1,6 @@
package com.baseband.client.feature.client;
import com.baseband.client.event.events.PacketEvent;
import com.baseband.client.event.events.PlayerDestroyEvent;
import com.baseband.client.feature.Feature;
import com.baseband.client.feature.category.ClientCategory;
@ -11,6 +12,7 @@ import com.baseband.client.util.adapt.FieldFinder;
import com.baseband.client.util.adapt.Marker;
import com.baseband.client.util.interact.ServerDataManager;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.server.SPacketPlayerPosLook;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -27,7 +29,14 @@ public class Timer extends Feature {
public boolean destroy;
@Config("Multiplier")
@Range("0.05..7.5")
public float m = 0.5f;
public float multiplier = 0.5f;
float m = multiplier;
@Config("Adjust slower")
@Description("Adjusts the timer to be slower when being lagged back.")
public boolean adjSlower = false;
@Config("Adjust faster")
@Description("Adjusts the timer to be faster when not being lagged back.")
public boolean adjFaster = false;
@Config("Adjust to server")
@Description("Adjusts the client's TPS to the server's. Enable either Fasten or Slowdown for this to do anything.\n" +
"The client TPS is §lALSO§r still going to be adjusted by the Multiplier.")
@ -41,7 +50,12 @@ public class Timer extends Feature {
@Description("Allows client to run slower than 20TPS if the server runs at that speed. This usually doesn't cause any lag-backs, and even prevents them in very low TPS.")
@Gate(1)
public boolean slowdown = true;
@Override
public void onEnable() {
m = multiplier;
}
@Override
public void onDisable() {
setGameTimer(20);
@ -57,11 +71,36 @@ public class Timer extends Feature {
@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
onTick();
tickTimer();
}
int lbCounter = 0;
int noLbCounter = 0;
@Override
public void onTick() {
if(!adjFaster && !adjSlower) {
m = multiplier;
}
else {
if (lbCounter > 0)
lbCounter--;
if (lbCounter > 40 && adjSlower) {
m = Math.max(m - 0.05f, 0.5f);
lbCounter -= 40;
}
if (lbCounter == 0) {
noLbCounter++;
} else noLbCounter = 0;
if (noLbCounter > 80 && adjFaster) {
m = Math.min(m + 0.05f, multiplier);
noLbCounter = 40;
}
}
tickTimer();
}
private void tickTimer() {
if (timerLock) {
text = "Timer" + (enabled ? " §7[LOCKED]" : "");
if(multiplierLock != null) {
@ -94,4 +133,10 @@ public class Timer extends Feature {
throw new RuntimeException(e);
}
}
public void onPacket(PacketEvent.Receive event) {
if(event.getPacket() instanceof SPacketPlayerPosLook) {
lbCounter += 40;
}
}
}

View file

@ -91,7 +91,7 @@ public class Speed extends Feature {
//Time will tell.
//higher priority than default, so we can get explosion packets before velocity fucks with them
@Priority(value = 2)
public void onPacketReceive(PacketEvent.Read event) {
public void onPacketReceive(PacketEvent.Receive event) {
if(notIngame()) {
return;
}

View file

@ -29,7 +29,7 @@ public class Velocity extends Feature {
event.setCanceled(true);
}
public void packetRead(PacketEvent.Read event) {
public void packetRead(PacketEvent.Receive event) {
if (event.getPacket() instanceof SPacketEntityVelocity) {
SPacketEntityVelocity velocity = (SPacketEntityVelocity) event.getPacket();
if (velocity.getEntityID() == mc.player.getEntityId()) {

View file

@ -15,7 +15,7 @@ public class MixinNetworkManager {
@Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
public void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) {
if (BaseBand.publish(new PacketEvent.Read(p_channelRead0_2_)).isCancelled())
if (BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled())
ci.cancel();
}