This commit is contained in:
gnembon committed 2023-10-25 19:09:20 +02:00
1 parent 1a7e8b6875
commit 382706a6df
23 files changed
+58 -224

No files matched your search

+1 -2
View File
@@ -20,7 +20,6 @@ import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -599,7 +598,7 @@ public class CarpetSettings
extra = "works only in SP, and will slow down players",
category = {CREATIVE, SURVIVAL, CLIENT}
)
public static boolean smoothClientAnimations;
public static boolean smoothClientAnimations = true;
private static class PushLimitLimits extends Validator<Integer> {
@Override public Integer validate(CommandSourceStack source, CarpetRule<Integer> currentRule, Integer newValue, String string) {
@@ -1,10 +1,8 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.fakes.MinecraftServerInterface;
import carpet.fakes.SpawnGroupInterface;
import carpet.helpers.HopperCounter;
import carpet.helpers.ServerTickRateManager;
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
import carpet.utils.SpawnReporter;
@@ -24,6 +22,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.server.ServerTickRateManager;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.item.DyeColor;
@@ -179,7 +178,7 @@ public class SpawnCommand
// tick warp 0
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().tickRateManager();
// stop warp
// unnecessary
// start warp
@@ -1,6 +1,5 @@
package carpet.fakes;
import carpet.helpers.TickRateManager;
import net.minecraft.world.level.redstone.NeighborUpdater;
import org.jetbrains.annotations.Nullable;
@@ -23,6 +22,4 @@ public interface LevelInterface
List<Entity> getOtherEntitiesLimited(@Nullable Entity except, AABB box, Predicate<? super Entity> predicate, int limit);
NeighborUpdater getNeighborUpdater();
TickRateManager tickRateManager();
}
@@ -1,6 +0,0 @@
package carpet.fakes;
public interface MinecraftClientInferface
{
float getPausedTickDelta();
}
@@ -2,12 +2,9 @@ package carpet.fakes;
import java.util.Map;
import java.util.function.BooleanSupplier;
import carpet.helpers.ServerTickRateManager;
import carpet.script.CarpetScriptServer;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
//import net.minecraft.server.ServerResources;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
@@ -24,6 +21,4 @@ public interface MinecraftServerInterface
void addScriptServer(CarpetScriptServer scriptServer);
CarpetScriptServer getScriptServer();
ServerTickRateManager getTickRateManager();
}
@@ -1,20 +0,0 @@
package carpet.helpers;
import net.minecraft.server.MinecraftServer;
public class ServerTickRateManager extends TickRateManager
{
public ServerTickRateManager(MinecraftServer server) {
}
public boolean isInWarpSpeed()
{
return false;
}
public void requestGameToSprint(final int ticks)
{ // noop
}
}
@@ -1,19 +0,0 @@
package carpet.helpers;
public class TickRateManager
{
public boolean gameIsPaused()
{
return false;
}
public float mspt()
{
return 50.0f;
}
public boolean runsNormally()
{
return true;
}
}
@@ -1,9 +1,7 @@
package carpet.logging;
import carpet.CarpetServer;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.HopperCounter;
import carpet.helpers.ServerTickRateManager;
import carpet.logging.logHelpers.PacketCounter;
import carpet.utils.Messenger;
import carpet.utils.SpawnReporter;
@@ -11,16 +9,16 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundTabListPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTickRateManager;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.TimeUtil;
import net.minecraft.world.level.Level;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.Set;
import java.util.function.Consumer;
@@ -117,18 +115,14 @@ public class HUDController
}
private static Component [] send_tps_display(MinecraftServer server)
{
OptionalDouble averageTPS = Arrays.stream(server.tickTimes).average();
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
if (averageTPS.isEmpty())
{
return new Component[]{Component.literal("No TPS data available")};
}
double MSPT = Arrays.stream(server.tickTimes).average().getAsDouble() * 1.0E-6D;
double TPS = 1000.0D / Math.max(trm.isInWarpSpeed()?0.0:trm.mspt(), MSPT);
if (trm.gameIsPaused()) {
double MSPT = ((double)server.getAverageTickTimeNanos())/ TimeUtil.NANOSECONDS_PER_MILLISECOND;
ServerTickRateManager trm = server.tickRateManager();
double TPS = 1000.0D / Math.max(trm.isSprinting()?0.0:trm.millisecondsPerTick(), MSPT);
if (trm.isFrozen()) {
TPS = 0;
}
String color = Messenger.heatmap_color(MSPT,trm.mspt());
String color = Messenger.heatmap_color(MSPT,trm.millisecondsPerTick());
return new Component[]{Messenger.c(
"g TPS: ", String.format(Locale.US, "%s %.1f",color, TPS),
"g MSPT: ", String.format(Locale.US,"%s %.1f", color, MSPT))};
@@ -5,7 +5,7 @@ import carpet.logging.logHelpers.TrajectoryLogHelper;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
@@ -20,10 +20,10 @@ public abstract class AbstractArrowMixin extends Entity
private TrajectoryLogHelper logHelper;
public AbstractArrowMixin(EntityType<?> entityType_1, Level world_1) { super(entityType_1, world_1); }
@Inject(method = "<init>(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN"))
private void addLogger(EntityType<? extends Projectile> entityType_1, Level world_1, CallbackInfo ci)
@Inject(method = "<init>(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;)V", at = @At("RETURN"))
private void addLogger(final EntityType entityType, final Level level, final ItemStack itemStack, final CallbackInfo ci)
{
if (LoggerRegistry.__projectiles && !world_1.isClientSide)
if (LoggerRegistry.__projectiles && !level.isClientSide)
logHelper = new TrajectoryLogHelper("projectiles");
}
@@ -1,28 +0,0 @@
package carpet.mixins;
import carpet.fakes.LevelInterface;
import carpet.helpers.TickRateManager;
import net.minecraft.client.multiplayer.ClientLevel;
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;
@Mixin(ClientLevel.class)
public abstract class ClientLevel_tickSpeedMixin implements LevelInterface
{
private TickRateManager tickRateManager;
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci)
{
this.tickRateManager = new TickRateManager();
}
@Override
public TickRateManager tickRateManager()
{
return tickRateManager;
}
}
@@ -1,49 +0,0 @@
package carpet.mixins;
import carpet.fakes.LevelInterface;
import carpet.fakes.MinecraftClientInferface;
import carpet.helpers.TickRateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(value = LevelRenderer.class, priority = 69420)
public class LevelRenderer_pausedShakeMixin
{
@Shadow @Final private Minecraft minecraft;
@Shadow private ClientLevel level;
float initial = -1234.0f;
// require 0 is for optifine being a bitch as it usually is.
@ModifyVariable(method = "renderLevel", argsOnly = true, require = 0, ordinal = 0, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/ClientLevel;entitiesForRendering()Ljava/lang/Iterable;"
))
private float changeTickPhase(float previous)
{
initial = previous;
TickRateManager trm = ((LevelInterface)level).tickRateManager();
if (!trm.runsNormally())
return ((MinecraftClientInferface)minecraft).getPausedTickDelta();
return previous;
}
// require 0 is for optifine being a bitch as it usually is.
@ModifyVariable(method = "renderLevel", argsOnly = true, require = 0, ordinal = 0 ,at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/particle/ParticleEngine;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;Lnet/minecraft/client/renderer/LightTexture;Lnet/minecraft/client/Camera;F)V",
shift = At.Shift.BEFORE
))
private float changeTickPhaseBack(float previous)
{
// this may not set with optifine bitch
return initial==-1234.0f?previous:initial;
}
}
@@ -1,6 +1,5 @@
package carpet.mixins;
import carpet.fakes.LevelInterface;
import carpet.network.CarpetClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
@@ -25,7 +24,7 @@ public class MinecraftMixin
@Inject(at = @At("HEAD"), method = "tick")
private void onClientTick(CallbackInfo info) {
if (this.level != null) {
boolean runsNormally = ((LevelInterface)this.level).tickRateManager().runsNormally();
boolean runsNormally = level.tickRateManager().runsNormally();
// hope server doesn't need to tick - should be handled by the server on its own
if (!runsNormally)
CarpetClient.shapes.renewShapes();
@@ -7,6 +7,7 @@ import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerFunctionManager;
import net.minecraft.server.ServerTickRateManager;
import net.minecraft.server.TickTask;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.players.PlayerList;
@@ -40,12 +41,6 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
@Shadow protected abstract void tickServer(BooleanSupplier booleanSupplier_1);
@Shadow private long nextTickTime;
@Shadow private long lastOverloadWarning;
@Shadow public abstract boolean pollTask();
@Shadow @Final protected LevelStorageSource.LevelStorageAccess storageSource;
@Shadow @Final private Map<ResourceKey<Level>, ServerLevel> levels;
@@ -62,11 +57,18 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
@Shadow @Final private StructureTemplateManager structureTemplateManager;
@Shadow public abstract ServerTickRateManager tickRateManager();
@Shadow private long nextTickTimeNanos;
@Shadow private long lastOverloadWarningNanos;
@Override
public void forceTick(BooleanSupplier isAhead)
{
nextTickTime = lastOverloadWarning = Util.getMillis();
nextTickTimeNanos = lastOverloadWarningNanos = Util.getNanos();
tickServer(isAhead);
pollTask();
while(pollTask()) {Thread.yield();}
}
@@ -88,7 +90,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
))
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
if (!getTickRateManager().runsNormally())
if (!tickRateManager().runsNormally())
{
return;
}
@@ -1,7 +1,6 @@
package carpet.mixins;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.ServerTickRateManager;
import carpet.utils.CarpetProfiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.TickTask;
@@ -23,20 +22,6 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
CarpetProfiler.ProfilerToken currentSection;
private ServerTickRateManager serverTickRateManager;
@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(CallbackInfo ci)
{
serverTickRateManager = new ServerTickRateManager((MinecraftServer)(Object)this);
}
@Override
public ServerTickRateManager getTickRateManager()
{
return serverTickRateManager;
}
// Replaced the above cancelled while statement with this one
// could possibly just inject that mspt selection at the beginning of the loop, but then adding all mspt's to
// replace 50L will be a hassle
@@ -1,18 +0,0 @@
package carpet.mixins;
import carpet.fakes.MinecraftClientInferface;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(Minecraft.class)
public class Minecraft_pausedShakeMixin implements MinecraftClientInferface
{
@Shadow private float pausePartialTick;
@Override
public float getPausedTickDelta()
{
return pausePartialTick;
}
}
@@ -0,0 +1,22 @@
package carpet.mixins;
import carpet.CarpetSettings;
import net.minecraft.client.Minecraft;
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.CallbackInfoReturnable;
@Mixin(Minecraft.class)
public class Minecraft_tickMixin
{
@Inject(method = "getTickTargetMillis", at = @At("HEAD"), cancellable = true)
private void onGetTickTargetMillis(final float f, final CallbackInfoReturnable<Float> cir)
{
if (!CarpetSettings.smoothClientAnimations) {
cir.setReturnValue(f);
}
}
}
@@ -1,8 +1,6 @@
package carpet.mixins;
import carpet.fakes.LevelInterface;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.TickRateManager;
import carpet.utils.CarpetProfiler;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
@@ -28,12 +26,6 @@ public abstract class ServerLevel_tickMixin extends Level implements LevelInterf
super(writableLevelData, resourceKey, registryAccess, holder, supplier, bl, bl2, l, i);
}
@Override
public TickRateManager tickRateManager()
{
return ((MinecraftServerInterface)getServer()).getTickRateManager();
}
private CarpetProfiler.ProfilerToken currentSection;
@Inject(method = "tick", at = @At(
@@ -1,10 +1,10 @@
package carpet.patches;
import carpet.CarpetServer;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.ServerTickRateManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTickRateManager;
import net.minecraft.util.Mth;
import net.minecraft.util.TimeUtil;
import net.minecraft.world.level.border.BorderChangeListener;
import net.minecraft.world.level.border.BorderStatus;
import net.minecraft.world.level.border.WorldBorder;
@@ -13,8 +13,6 @@ import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
/**
* This class is essentially a copy of {@link net.minecraft.world.level.border.WorldBorder.MovingBorderExtent}
* but instead of using real time to lerp the border
@@ -95,11 +93,11 @@ public class TickSyncedBorderExtent implements WorldBorder.BorderExtent
}
else
{
ms = Arrays.stream(server.tickTimes).average().orElseThrow(IllegalStateException::new) * 1.0E-6D;
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
if (!trm.isInWarpSpeed())
ms = ((double)server.getAverageTickTimeNanos())/ TimeUtil.NANOSECONDS_PER_MILLISECOND;
ServerTickRateManager trm = server.tickRateManager();
if (!trm.isSprinting())
{
ms = Math.max(ms, trm.mspt());
ms = Math.max(ms, trm.millisecondsPerTick());
}
}
double tps = 1_000.0D / ms;
@@ -1369,7 +1369,7 @@ public class CarpetEventServer
public void tick()
{
if (Vanilla.isTickProcessingPaused(scriptServer.server))
if (!scriptServer.server.tickRateManager().runsNormally())
{
return;
}
-6
View File
@@ -366,10 +366,4 @@ public class Vanilla
return new BlockPredicatePayload(predicateData.getCMBlockState(), predicateData.getCMBlockTagKey(), predicateData.getCMProperties(), predicateData.getCMDataTag());
}
}
public static boolean isTickProcessingPaused(MinecraftServer server)
{
return !((MinecraftServerInterface)server).getTickRateManager().runsNormally();
}
}
@@ -134,7 +134,7 @@ public class SystemInfo
// might be off one tick when run in the off tasks or asynchronously.
int currentReportedTick = c.server().getTickCount() - 1;
List<Value> ticks = new ArrayList<>(100);
long[] tickArray = c.server().tickTimes;
long[] tickArray = c.server().getTickTimesNanos();
for (int i = currentReportedTick + 100; i > currentReportedTick; i--)
{
ticks.add(new NumericValue((tickArray[i % 100]) / 1000000.0));