mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
fix: use player latency instead of fixed 50ms
This commit is contained in:
parent
27757485d1
commit
8ab48747c3
5 changed files with 69 additions and 9 deletions
|
|
@ -10,6 +10,7 @@ import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import land.chipmunk.chipmunkmod.modules.*;
|
import land.chipmunk.chipmunkmod.modules.*;
|
||||||
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.hud.DebugHud;
|
||||||
import net.minecraft.client.gui.hud.InGameHud;
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
|
@ -43,7 +44,8 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
private CommandDispatcher<CommandSource> commandDispatcher;
|
private CommandDispatcher<CommandSource> commandDispatcher;
|
||||||
|
|
||||||
@Shadow public abstract ClientWorld getWorld ();
|
@Shadow
|
||||||
|
public abstract ClientWorld getWorld ();
|
||||||
|
|
||||||
@Inject(method = "onGameJoin", at = @At("TAIL"))
|
@Inject(method = "onGameJoin", at = @At("TAIL"))
|
||||||
private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) {
|
private void onGameJoin (final GameJoinS2CPacket packet, final CallbackInfo ci) {
|
||||||
|
|
@ -138,18 +140,18 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
@Inject(method = "onPlayerPositionLook", at = @At("TAIL"))
|
@Inject(method = "onPlayerPositionLook", at = @At("TAIL"))
|
||||||
private void setPosition (final PlayerPositionLookS2CPacket packet, final CallbackInfo ci) {
|
private void setPosition (final PlayerPositionLookS2CPacket packet, final CallbackInfo ci) {
|
||||||
final Vec3d position = packet.change().position();
|
final Vec3d position = packet.change().position();
|
||||||
|
|
||||||
final BlockPos origin = CommandCore.INSTANCE.origin;
|
final BlockPos origin = CommandCore.INSTANCE.origin;
|
||||||
if (origin == null) {
|
if (origin == null) {
|
||||||
CommandCore.INSTANCE.move(position);
|
CommandCore.INSTANCE.move(position);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
final ClientPlayerEntity player = client.player;
|
final ClientPlayerEntity player = client.player;
|
||||||
|
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
final int distanceSquared = player.getChunkPos().getSquaredDistance(new ChunkPos(origin));
|
final int distanceSquared = player.getChunkPos().getSquaredDistance(new ChunkPos(origin));
|
||||||
final int distance = (int) Math.sqrt(distanceSquared);
|
final int distance = (int) Math.sqrt(distanceSquared);
|
||||||
|
|
||||||
|
|
@ -163,4 +165,15 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
private void onWorldTimeUpdate (final WorldTimeUpdateS2CPacket packet, final CallbackInfo ci) {
|
private void onWorldTimeUpdate (final WorldTimeUpdateS2CPacket packet, final CallbackInfo ci) {
|
||||||
for (final Listener listener : ListenerManager.listeners) listener.timeUpdate();
|
for (final Listener listener : ListenerManager.listeners) listener.timeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WrapOperation(
|
||||||
|
method = "tick",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/client/gui/hud/DebugHud;shouldShowPacketSizeAndPingCharts()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean shouldShowPacketSizeAndPingCharts (final DebugHud instance, final Operation<Boolean> original) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.hud.debug.chart.DebugChart;
|
||||||
|
import net.minecraft.util.profiler.log.MultiValueDebugSampleLog;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(DebugChart.class)
|
||||||
|
public interface DebugChartAccessor {
|
||||||
|
@Accessor(value = "log")
|
||||||
|
MultiValueDebugSampleLog getLog ();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.hud.DebugHud;
|
||||||
|
import net.minecraft.client.gui.hud.debug.chart.PingChart;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(DebugHud.class)
|
||||||
|
public interface DebugHudAccessor {
|
||||||
|
@Accessor(value = "pingChart")
|
||||||
|
PingChart getPingChart ();
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,8 @@ import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.listeners.Listener;
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
import land.chipmunk.chipmunkmod.mixin.ClientWorldAccessor;
|
import land.chipmunk.chipmunkmod.mixin.ClientWorldAccessor;
|
||||||
|
import land.chipmunk.chipmunkmod.mixin.DebugChartAccessor;
|
||||||
|
import land.chipmunk.chipmunkmod.mixin.DebugHudAccessor;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.CommandBlock;
|
import net.minecraft.block.CommandBlock;
|
||||||
|
|
@ -12,6 +14,7 @@ import net.minecraft.block.FallingBlock;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.hud.debug.chart.PingChart;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||||
|
|
@ -34,10 +37,14 @@ import net.minecraft.util.Pair;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
|
import net.minecraft.util.profiler.log.MultiValueDebugSampleLog;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class CommandCore implements Listener {
|
public class CommandCore implements Listener {
|
||||||
|
|
@ -403,7 +410,7 @@ public class CommandCore implements Listener {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
timer.schedule(queryTask, 50);
|
timer.schedule(queryTask, 50 + getNextTickWaitTime());
|
||||||
|
|
||||||
incrementCurrentBlock();
|
incrementCurrentBlock();
|
||||||
|
|
||||||
|
|
@ -519,7 +526,7 @@ public class CommandCore implements Listener {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 50 * 2);
|
}, 50 + getNextTickWaitTime());
|
||||||
} else {
|
} else {
|
||||||
final StringBuilder oldBlockString = new StringBuilder(Registries.BLOCK.getId(oldBlockState.getBlock()).toString());
|
final StringBuilder oldBlockString = new StringBuilder(Registries.BLOCK.getId(oldBlockState.getBlock()).toString());
|
||||||
if (!oldBlockState.getProperties().isEmpty()) {
|
if (!oldBlockState.getProperties().isEmpty()) {
|
||||||
|
|
@ -558,7 +565,8 @@ public class CommandCore implements Listener {
|
||||||
// we don't want to place a block inside ourselves
|
// we don't want to place a block inside ourselves
|
||||||
if (boundingBox.intersects(new Vec3d(blockPos), new Vec3d(blockPos))) continue;
|
if (boundingBox.intersects(new Vec3d(blockPos), new Vec3d(blockPos))) continue;
|
||||||
final BlockState blockState = player.getEntityWorld().getBlockState(blockPos);
|
final BlockState blockState = player.getEntityWorld().getBlockState(blockPos);
|
||||||
if (blockState.getBlock() instanceof FallingBlock) continue;
|
if (blockState.getBlock() instanceof FallingBlock || blockState.getBlock() instanceof CommandBlock)
|
||||||
|
continue;
|
||||||
final boolean replaceable = blockState.isIn(BlockTags.REPLACEABLE);
|
final boolean replaceable = blockState.isIn(BlockTags.REPLACEABLE);
|
||||||
if (
|
if (
|
||||||
!replaceable
|
!replaceable
|
||||||
|
|
@ -577,6 +585,19 @@ public class CommandCore implements Listener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getNextTickWaitTime () {
|
||||||
|
final PingChart pingChart = ((DebugHudAccessor) client.getDebugHud()).getPingChart();
|
||||||
|
final MultiValueDebugSampleLog log = ((DebugChartAccessor) pingChart).getLog();
|
||||||
|
|
||||||
|
long sum = 0L;
|
||||||
|
|
||||||
|
for (int i = 0; i < log.getLength(); ++i) {
|
||||||
|
sum += log.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.min(Math.round((float) sum / log.getLength()), 5 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
public void cleanup () {
|
public void cleanup () {
|
||||||
if (timer == null) return;
|
if (timer == null) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@
|
||||||
"ClientPlayerEntityMixin",
|
"ClientPlayerEntityMixin",
|
||||||
"ClientPlayNetworkHandlerMixin",
|
"ClientPlayNetworkHandlerMixin",
|
||||||
"ClientWorldAccessor",
|
"ClientWorldAccessor",
|
||||||
|
"DebugChartAccessor",
|
||||||
|
"DebugHudAccessor",
|
||||||
"MinecraftClientAccessor",
|
"MinecraftClientAccessor",
|
||||||
"StringHelperMixin",
|
"StringHelperMixin",
|
||||||
"ElderGuardianAppearanceParticleMixin",
|
"ElderGuardianAppearanceParticleMixin",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue