Add rule to make the World Border update with ticks instead of real time (#1550)

This commit is contained in:
senseiwells authored and GitHub committed 2023-01-25 17:40:18 +01:00
1 parent 0e2f6df4d3
commit 009d971584
5 files changed
+242

No files matched your search

+44
View File
@@ -27,6 +27,8 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.StructureBlockEntity;
import net.minecraft.world.level.block.piston.PistonStructureResolver;
import net.minecraft.world.level.border.BorderStatus;
import net.minecraft.world.level.border.WorldBorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1068,6 +1070,48 @@ public class CarpetSettings
)
public static int sculkSensorRange = 8;
/**
* Listener, we need to update world borders to change whether
* they are currently moving in real time or in game time.
*/
private static class WorldBorderValidator extends Validator<Boolean>
{
@Override
public Boolean validate(CommandSourceStack source, CarpetRule<Boolean> changingRule, Boolean newValue, String userInput)
{
if (changingRule.value() ^ newValue)
{
// Needed for the update
tickSyncedWorldBorders = newValue;
MinecraftServer server = CarpetServer.minecraft_server;
if (server == null)
{
return newValue;
}
for (ServerLevel level : server.getAllLevels())
{
WorldBorder worldBorder = level.getWorldBorder();
if (worldBorder.getStatus() != BorderStatus.STATIONARY)
{
double from = worldBorder.getSize();
double to = worldBorder.getLerpTarget();
long time = worldBorder.getLerpRemainingTime();
worldBorder.lerpSizeBetween(from, to, time);
}
}
}
return newValue;
}
}
@Rule(
desc = "Makes world borders move based on in game time instead of real time",
extra = "This has the effect that when the tick rate changes the world border speed also changes proportional to it",
category = FEATURE,
validate = WorldBorderValidator.class
)
public static boolean tickSyncedWorldBorders = false;
public enum FungusFixMode {
FALSE, RANDOM, ALL;
}