split time into 3 categories

This commit is contained in:
Sen 2025-08-03 21:58:30 +02:00
parent 2f9e7ba728
commit 1d19cddcef
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
21 changed files with 362 additions and 167 deletions

View file

@ -177,6 +177,7 @@ import common.vars.Vars;
import common.world.Chunk; import common.world.Chunk;
import common.world.LightType; import common.world.LightType;
import common.world.State; import common.world.State;
import common.world.Weather;
import common.world.World; import common.world.World;
/* /*
@ -285,7 +286,8 @@ public class Client implements IThreadListener {
private final class WorldClient extends World { private final class WorldClient extends World {
public WorldClient(Dimension dim) { public WorldClient(Dimension dim) {
super(dim, true); super(dim, true);
this.daytime = dim.getTimeOffset(); this.orbit = dim.getOrbit();
this.rotation = dim.getRotation();
this.calculateInitialSkylight(); this.calculateInitialSkylight();
this.calculateInitialWeather(); this.calculateInitialWeather();
this.updatePhysics(); this.updatePhysics();
@ -1895,16 +1897,17 @@ public class Client implements IThreadListener {
+ chunk.getLight(LightType.BLOCK, pos) + " Blöcke, " + String.format( + chunk.getLight(LightType.BLOCK, pos) + " Blöcke, " + String.format(
"%.1f", this.entityRenderer.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " "%.1f", this.entityRenderer.getSunBrightness(1.0f) * 15.0f) + " Welt), A: "
+ String.format("%.1f °", this.world.getCelestialAngle(1.0f)) + "\n" + + String.format("%.1f °", this.world.getCelestialAngle(1.0f)) + "\n" +
String.format("Zeit: %d T, R %d / %d T, U %d / %d T", String.format("Zeit: %s" + (this.world.dimension.hasRotation() ? ", R %d / %d T" : "") + (this.world.dimension.hasOrbit() ? ", U %d / %d T" : ""),
this.world.getDayTime(), this.world.formatEpochSimple(),
this.world.getDayTime() % this.world.dimension.getRotationalPeriod(), this.world.getRotation(),
this.world.dimension.getRotationalPeriod(), this.world.dimension.getRotationalPeriod(),
this.world.getDayTime() % this.world.dimension.getOrbitalPeriod(), this.world.getOrbit(),
this.world.dimension.getOrbitalPeriod() this.world.dimension.getOrbitalPeriod()
) + "\n" + ) + "\n" +
String.format("Laub: %s, T: %.2f K / %.2f °C, %s (R %.1f, %.1f)", String.format("Laub: %s, T: %.2f K / %.2f °C, %s%s (R %.1f, %.1f)",
!this.world.dimension.hasSeasons() ? "*" : this.world.getLeavesType().getDisplayName(), !this.world.dimension.hasSeasons() ? "*" : this.world.getLeavesType().getDisplay(),
this.world.getTemperatureK(pos), this.world.getTemperatureC(pos), this.world.getTemperatureK(pos), this.world.getTemperatureC(pos),
this.world.dimension.hasWeather() ? "" : "*", !this.world.dimension.hasWeather() && this.world.getWeather() == Weather.CLEAR ? "" :
this.world.getWeather().getDisplay(), this.world.getRainStrength(), this.world.getWeather().getDisplay(), this.world.getRainStrength(),
this.world.getDarkness() this.world.getDarkness()
) + "\n" + ) + "\n" +
@ -3468,9 +3471,13 @@ public class Client implements IThreadListener {
this.world.updatePhysics(); this.world.updatePhysics();
this.markReload(); this.markReload();
if (Vars.dayCycle) if (Vars.timeFlow > 0)
{ {
this.world.setDayTime(this.world.getDayTime() + (long)Vars.timeFlow); if(this.world.dimension.hasOrbit())
this.world.setOrbit((this.world.getOrbit() + (long)Vars.timeFlow) % this.world.dimension.getOrbitalPeriod());
if(this.world.dimension.hasRotation())
this.world.setRotation((this.world.getRotation() + (long)Vars.timeFlow) % this.world.dimension.getRotationalPeriod());
this.world.dimension.setEpoch(this.world.dimension.getEpoch() + (long)Vars.timeFlow);
} }
for (int i = 0; i < 10 && !this.spawnQueue.isEmpty(); ++i) for (int i = 0; i < 10 && !this.spawnQueue.isEmpty(); ++i)

View file

@ -959,8 +959,10 @@ public class ClientPlayer implements IClientPlayer
public void handleTimeUpdate(SPacketTimeUpdate packetIn) public void handleTimeUpdate(SPacketTimeUpdate packetIn)
{ {
NetHandler.checkThread(packetIn, this, this.gm, this.world); NetHandler.checkThread(packetIn, this, this.gm, this.world);
// this.gameController.theWorld.getWorldInfo().setTime(packetIn.getTotalWorldTime()); if(this.gm.world.dimension.hasOrbit())
this.gm.world.setDayTime(packetIn.getWorldTime()); this.gm.world.setOrbit(packetIn.getOrbit());
if(this.gm.world.dimension.hasRotation())
this.gm.world.setRotation(packetIn.getRotation());
this.gm.setTicked(packetIn.getServerinfo()); this.gm.setTicked(packetIn.getServerinfo());
Items.navigator.setLocalTime(packetIn.getLocalTime()); Items.navigator.setLocalTime(packetIn.getLocalTime());
} }

View file

@ -1254,7 +1254,7 @@ public class RenderGlobal
float f15 = this.gm.entityRenderer.getStarBrightness(partialTicks) * f16; float f15 = this.gm.entityRenderer.getStarBrightness(partialTicks) * f16;
if (f15 > 0.0F) if (f15 > 0.0F)
{ {
int stars = this.theWorld.dimension.getStarColor(this.theWorld.getDayTime()); int stars = this.theWorld.dimension.getStarColor(this.theWorld.getRotation());
if(stars == 0xffffffff) { if(stars == 0xffffffff) {
GlState.color(f15, f15, f15, f15); GlState.color(f15, f15, f15, f15);
} }
@ -1281,7 +1281,7 @@ public class RenderGlobal
f15 = this.gm.entityRenderer.getDeepStarBrightness(partialTicks) * f16; f15 = this.gm.entityRenderer.getDeepStarBrightness(partialTicks) * f16;
if (f15 > 0.0F) if (f15 > 0.0F)
{ {
int stars = this.theWorld.dimension.getDeepStarColor(this.theWorld.getDayTime()); int stars = this.theWorld.dimension.getDeepStarColor(this.theWorld.getRotation());
if(stars == 0xffffffff) { if(stars == 0xffffffff) {
GlState.color(f15, f15, f15, f15); GlState.color(f15, f15, f15, f15);
} }

View file

@ -1,8 +1,9 @@
package common.block.foliage; package common.block.foliage;
import common.util.Displayable;
import common.util.Identifyable; import common.util.Identifyable;
public enum LeavesType implements Identifyable { public enum LeavesType implements Identifyable, Displayable {
SPRING("spring", "Frühling"), SPRING("spring", "Frühling"),
SUMMER("summer", "Sommer"), SUMMER("summer", "Sommer"),
AUTUMN("autumn", "Herbst"), AUTUMN("autumn", "Herbst"),
@ -21,7 +22,7 @@ public enum LeavesType implements Identifyable {
return this.name; return this.name;
} }
public String getDisplayName() { public String getDisplay() {
return this.display; return this.display;
} }

View file

@ -92,7 +92,10 @@ public abstract class Dimension extends Section {
private long seed = 0L; private long seed = 0L;
private boolean exterminated = false; private boolean exterminated = false;
private long timeExisted = 0L; private long timeExisted = 0L;
private long timeOffset = 0L; private long lastTicked = 0L;
private long orbit = 0L;
private long rotation = 0L;
private long epoch = 0L;
private Weather weather = this.defaultWeather; private Weather weather = this.defaultWeather;
protected Dimension(boolean custom) { protected Dimension(boolean custom) {
@ -114,14 +117,26 @@ public abstract class Dimension extends Section {
this.timeExisted = time; this.timeExisted = time;
} }
public final void setTimeOffset(long time) { public final void setLastTicked(long time) {
this.timeOffset = time; this.lastTicked = time;
} }
public final void setCurrentWeather(Weather weather) { public final void setOrbit(long time) {
this.orbit = time;
}
public final void setRotation(long time) {
this.rotation = time;
}
public final void setWeather(Weather weather) {
this.weather = weather; this.weather = weather;
} }
public final void setEpoch(long time) {
this.epoch = time;
}
public final long getSeed() { public final long getSeed() {
return this.seed; return this.seed;
@ -135,14 +150,26 @@ public abstract class Dimension extends Section {
return this.timeExisted; return this.timeExisted;
} }
public final long getTimeOffset() { public final long getLastTicked() {
return this.timeOffset; return this.lastTicked;
} }
public final Weather getCurrentWeather() { public final long getOrbit() {
return this.orbit;
}
public final long getRotation() {
return this.rotation;
}
public final Weather getWeather() {
return this.weather; return this.weather;
} }
public final long getEpoch() {
return this.epoch;
}
protected final void setComposition(State filler, State liquid, int seaLevel) { protected final void setComposition(State filler, State liquid, int seaLevel) {
this.filler = filler; this.filler = filler;
@ -378,7 +405,11 @@ public abstract class Dimension extends Section {
return false; return false;
} }
public boolean isCelestial() { public boolean hasRotation() {
return false;
}
public boolean hasOrbit() {
return false; return false;
} }
@ -444,11 +475,16 @@ public abstract class Dimension extends Section {
return dim; return dim;
} }
public final TagObject writeData(boolean send, long offset) { public final TagObject writeData(boolean send, long dtime) {
dtime -= this.lastTicked;
TagObject tag = new TagObject(); TagObject tag = new TagObject();
tag.setLong("Seed", this.seed); tag.setLong("Seed", this.seed);
tag.setLong("Time", this.timeExisted); tag.setLong("Time", this.timeExisted);
tag.setLong("Offset", offset); if(this.hasOrbit())
tag.setLong("Orbit", (this.orbit + dtime) % this.orbitalPeriod);
if(this.hasRotation())
tag.setLong("Rotation", (this.rotation + dtime) % this.rotationPeriod);
tag.setLong("Epoch", this.epoch + dtime);
if(this == Space.INSTANCE) if(this == Space.INSTANCE)
return tag; return tag;
tag.setBool("Exterminated", this.exterminated); tag.setBool("Exterminated", this.exterminated);
@ -462,7 +498,11 @@ public abstract class Dimension extends Section {
public final void readData(TagObject tag) { public final void readData(TagObject tag) {
this.seed = tag.getLong("Seed"); this.seed = tag.getLong("Seed");
this.timeExisted = tag.getLong("Time"); this.timeExisted = tag.getLong("Time");
this.timeOffset = tag.getLong("Offset"); if(this.hasOrbit())
this.orbit = tag.getLong("Orbit");
if(this.hasRotation())
this.rotation = tag.getLong("Rotation");
this.epoch = tag.getLong("Epoch");
if(this == Space.INSTANCE) if(this == Space.INSTANCE)
return; return;
this.exterminated = tag.getBool("Exterminated"); this.exterminated = tag.getBool("Exterminated");

View file

@ -40,7 +40,11 @@ public final class Moon extends Dimension {
return true; return true;
} }
public boolean isCelestial() { public boolean hasRotation() {
return true;
}
public boolean hasOrbit() {
return true; return true;
} }
} }

View file

@ -67,7 +67,11 @@ public final class Planet extends Dimension {
return true; return true;
} }
public boolean isCelestial() { public boolean hasRotation() {
return true;
}
public boolean hasOrbit() {
return true; return true;
} }

View file

@ -23,7 +23,7 @@ public final class Star extends Dimension {
return DimType.STAR; return DimType.STAR;
} }
public boolean isCelestial() { public boolean hasRotation() {
return true; return true;
} }
} }

View file

@ -395,7 +395,7 @@ public abstract class BlockRegistry {
for(WoodType wood : WoodType.values()) { for(WoodType wood : WoodType.values()) {
register(wood.getName() + "_log", (new BlockLog()).setDisplay(wood.getDisplay() + "holz")); register(wood.getName() + "_log", (new BlockLog()).setDisplay(wood.getDisplay() + "holz"));
for(LeavesType type : LeavesType.values()) { for(LeavesType type : LeavesType.values()) {
register(wood.getName() + "_leaves_" + type.getName(), (new BlockLeaves(wood, type)).setDisplay(wood.getDisplay() + "laub (" + type.getDisplayName() + ")")); register(wood.getName() + "_leaves_" + type.getName(), (new BlockLeaves(wood, type)).setDisplay(wood.getDisplay() + "laub (" + type.getDisplay() + ")"));
} }
register(wood.getName() + "_sapling", (new BlockSapling(wood)).setHardness(0.0F).setSound(SoundType.GRASS) register(wood.getName() + "_sapling", (new BlockSapling(wood)).setHardness(0.0F).setSound(SoundType.GRASS)
.setDisplay(wood.getDisplay() + "setzling")); .setDisplay(wood.getDisplay() + "setzling"));

View file

@ -4,14 +4,18 @@ import java.util.List;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.item.Item; import common.item.Item;
import common.item.ItemControl;
import common.item.ItemStack; import common.item.ItemStack;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Clientside; import common.util.Clientside;
import common.util.Color; import common.util.Color;
import common.world.World;
public class ItemSpaceNavigator extends Item { public class ItemSpaceNavigator extends Item {
@Clientside @Clientside
private String localTime = ""; private String localTime = "";
@Clientside
private boolean local = true;
public ItemSpaceNavigator() { public ItemSpaceNavigator() {
this.setUnstackable(); this.setUnstackable();
@ -27,10 +31,16 @@ public class ItemSpaceNavigator extends Item {
return this.localTime; return this.localTime;
} }
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
if(world.client && control == ItemControl.QUARTERNARY)
this.local ^= true;
return false;
}
@Clientside @Clientside
public String getHotbarText(EntityNPC player, ItemStack stack) { public String getHotbarText(EntityNPC player, ItemStack stack) {
BlockPos pos = player.getPosition(); BlockPos pos = player.getPosition();
return Color.ORANGE + this.localTime + " / " + return Color.ORANGE + (this.local ? this.localTime : player.worldObj.formatEpoch()) + " / " +
String.format("%s bei %d, %d, %d", player.worldObj.dimension.getDisplay() + Color.ORANGE, String.format("%s bei %d, %d, %d", player.worldObj.dimension.getDisplay() + Color.ORANGE,
pos.getX(), pos.getY(), pos.getZ()); pos.getX(), pos.getY(), pos.getZ());
} }
@ -38,6 +48,7 @@ public class ItemSpaceNavigator extends Item {
@Clientside @Clientside
public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) { public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) {
tooltip.add(Color.ORANGE + this.localTime); tooltip.add(Color.ORANGE + this.localTime);
tooltip.add(Color.ORANGE + player.worldObj.formatEpoch() + " T" + player.worldObj.formatTime());
String[] dims = player.worldObj.dimension.getBaseNames(); String[] dims = player.worldObj.dimension.getBaseNames();
for(int z = dims.length - 1; z >= 0; z--) { for(int z = dims.length - 1; z >= 0; z--) {
tooltip.add(Color.ORANGE + dims[z]); tooltip.add(Color.ORANGE + dims[z]);

View file

@ -7,27 +7,31 @@ import common.network.Packet;
import common.network.PacketBuffer; import common.network.PacketBuffer;
public class SPacketTimeUpdate implements Packet<IClientPlayer> { public class SPacketTimeUpdate implements Packet<IClientPlayer> {
private long worldTime; private long orbit;
private long rotation;
private String localTime; private String localTime;
private String serverInfo; private String serverInfo;
public SPacketTimeUpdate() { public SPacketTimeUpdate() {
} }
public SPacketTimeUpdate(long time, String local, String info) { public SPacketTimeUpdate(long orbit, long rotation, String local, String info) {
this.worldTime = time; this.orbit = orbit;
this.rotation = rotation;
this.localTime = local; this.localTime = local;
this.serverInfo = info; this.serverInfo = info;
} }
public void readPacketData(PacketBuffer buf) throws IOException { public void readPacketData(PacketBuffer buf) throws IOException {
this.worldTime = buf.readLong(); this.orbit = buf.readLong();
this.rotation = buf.readLong();
this.localTime = buf.readString(64); this.localTime = buf.readString(64);
this.serverInfo = buf.readString(512); this.serverInfo = buf.readString(512);
} }
public void writePacketData(PacketBuffer buf) throws IOException { public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeLong(this.worldTime); buf.writeLong(this.orbit);
buf.writeLong(this.rotation);
buf.writeString(this.localTime); buf.writeString(this.localTime);
buf.writeString(this.serverInfo); buf.writeString(this.serverInfo);
} }
@ -36,8 +40,12 @@ public class SPacketTimeUpdate implements Packet<IClientPlayer> {
handler.handleTimeUpdate(this); handler.handleTimeUpdate(this);
} }
public long getWorldTime() { public long getOrbit() {
return this.worldTime; return this.orbit;
}
public long getRotation() {
return this.rotation;
} }
public String getLocalTime() { public String getLocalTime() {

View file

@ -193,8 +193,6 @@ public abstract class Vars {
public static boolean itemExplosion = true; public static boolean itemExplosion = true;
@Var(name = "signEditing") @Var(name = "signEditing")
public static boolean editSigns = true; public static boolean editSigns = true;
@Var(name = "daylightCycle")
public static boolean dayCycle = true;
@Var(name = "dropPlayerSkulls") @Var(name = "dropPlayerSkulls")
public static boolean skullDrop = true; public static boolean skullDrop = true;
@ -267,7 +265,7 @@ public abstract class Vars {
public static int maxExplosionIters = 1024; public static int maxExplosionIters = 1024;
@Var(name = "viewDistance", min = 2, max = 16) @Var(name = "viewDistance", min = 2, max = 16)
public static int distance = 8; public static int distance = 8;
@Var(name = "timeFlow", min = 1) @Var(name = "timeFlow", min = 0)
public static int timeFlow = 1; public static int timeFlow = 1;
@Var(name = "torchBurnoutChance") @Var(name = "torchBurnoutChance")
public static int torchBurnout = 30; public static int torchBurnout = 30;

View file

@ -45,7 +45,6 @@ public abstract class World implements IWorldAccess {
public static final float[] MOON_PHASES = new float[] {1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F}; public static final float[] MOON_PHASES = new float[] {1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F};
public static final int MAX_SIZE = 67108864; public static final int MAX_SIZE = 67108864;
public static final int MAX_SIZE_Y = 4096; public static final int MAX_SIZE_Y = 4096;
public static final long START_TIME = 4385238000L;
public static final float ABSOLUTE_ZERO = -273.15f; public static final float ABSOLUTE_ZERO = -273.15f;
public final boolean client; public final boolean client;
@ -71,7 +70,8 @@ public abstract class World implements IWorldAccess {
protected float fog; protected float fog;
protected float temp; protected float temp;
protected Weather weather; protected Weather weather;
protected long daytime; protected long orbit;
protected long rotation;
public boolean isBlockSolid(BlockPos pos) { public boolean isBlockSolid(BlockPos pos) {
return isSolidSurface(this.getState(pos)); return isSolidSurface(this.getState(pos));
@ -103,7 +103,7 @@ public abstract class World implements IWorldAccess {
this.dimension = dim; this.dimension = dim;
// this.storage = storage; // this.storage = storage;
this.client = client; this.client = client;
this.weather = dim.getCurrentWeather(); this.weather = dim.getWeather();
} }
public void updatePhysics() { public void updatePhysics() {
@ -801,7 +801,7 @@ public abstract class World implements IWorldAccess {
} }
public int calcSkylightSubtracted(boolean current) { public int calcSkylightSubtracted(boolean current) {
float f = !this.dimension.hasDaylight() || (current && this.dimension.isBaseDestroyed()) ? 0.5f : this.calcRotationPhase(current ? this.daytime : float f = !this.dimension.hasDaylight() || (current && this.dimension.isBaseDestroyed()) ? 0.5f : this.calcRotationPhase(current ? this.rotation :
(this.dimension.getRotationalPeriod() / 4L), 1.0f); (this.dimension.getRotationalPeriod() / 4L), 1.0f);
float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F); float f1 = 1.0F - (ExtMath.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F);
f1 = ExtMath.clampf(f1, 0.0F, 1.0F); f1 = ExtMath.clampf(f1, 0.0F, 1.0F);
@ -813,12 +813,12 @@ public abstract class World implements IWorldAccess {
} }
public float getCelestialAngle(float partial) { public float getCelestialAngle(float partial) {
return !this.dimension.isCelestial() ? 180.0f : (this.calcRotationPhase(this.daytime, Vars.dayCycle ? partial : 0.0f) * 360.0F); return !this.dimension.hasRotation() ? 180.0f : (this.calcRotationPhase(this.rotation, Vars.timeFlow > 0 ? partial : 0.0f) * 360.0F);
} }
public int getMoonPhase(int moon) { public int getMoonPhase(int moon) {
this.rand.setSeed((this.dimension.getSeed() + moon) ^ (moon << 12)); this.rand.setSeed((this.dimension.getSeed() + moon) ^ (moon << 12));
return (int)(this.daytime / this.dimension.getRotationalPeriod() % 8L + 8L + this.rand.zrange(8)) % 8; return (int)(this.rotation / this.dimension.getRotationalPeriod() % 8L + 8L + this.rand.zrange(8)) % 8;
} }
public float getMoonPhase() { public float getMoonPhase() {
@ -826,7 +826,7 @@ public abstract class World implements IWorldAccess {
} }
public float getDayPhase(float partial) { public float getDayPhase(float partial) {
return !this.dimension.hasDaylight() || this.dimension.isBaseDestroyed() ? (float)Math.PI : (this.calcRotationPhase(this.daytime, Vars.dayCycle ? partial : 0.0f) * (float)Math.PI * 2.0F); return !this.dimension.hasDaylight() || this.dimension.isBaseDestroyed() ? (float)Math.PI : (this.calcRotationPhase(this.rotation, Vars.timeFlow > 0 ? partial : 0.0f) * (float)Math.PI * 2.0F);
} }
public BlockPos getPrecipitationHeight(BlockPos pos) { public BlockPos getPrecipitationHeight(BlockPos pos) {
@ -1447,13 +1447,13 @@ public abstract class World implements IWorldAccess {
protected float getBaseTemperature() { protected float getBaseTemperature() {
return this.dimension.getTemperature() + this.dimension.getOrbitOffset() * return this.dimension.getTemperature() + this.dimension.getOrbitOffset() *
ExtMath.sin((((float)(this.daytime % this.dimension.getOrbitalPeriod()) / (float)this.dimension.getOrbitalPeriod()) ExtMath.sin((((float)(this.orbit % this.dimension.getOrbitalPeriod()) / (float)this.dimension.getOrbitalPeriod())
-0.125f) * (float)Math.PI * 2.0f); -0.125f) * (float)Math.PI * 2.0f);
} }
public LeavesType getLeavesType() { public LeavesType getLeavesType() {
return LeavesType.values()[(int)((this.daytime % return LeavesType.values()[(int)((this.orbit %
this.dimension.getOrbitalPeriod()) * (long)LeavesType.values().length / this.dimension.getOrbitalPeriod())]; this.dimension.getOrbitalPeriod()) * 4L / this.dimension.getOrbitalPeriod())];
} }
public float getTemperatureK(BlockPos pos) { public float getTemperatureK(BlockPos pos) {
@ -1787,20 +1787,28 @@ public abstract class World implements IWorldAccess {
public void setEntityState(Entity entityIn, byte state) { public void setEntityState(Entity entityIn, byte state) {
} }
public long getRotation() {
return this.rotation;
}
public void setRotation(long time) {
this.rotation = time;
}
public long getOrbit() {
return this.orbit;
}
public void setOrbit(long time) {
this.orbit = time;
}
public Weather getWeather() { public Weather getWeather() {
return this.weather; return this.weather;
} }
public long getDayTime() {
return this.daytime;
}
public void setWeather(Weather weather) { public void setWeather(Weather weather) {
this.dimension.setCurrentWeather(this.weather = weather); this.dimension.setWeather(this.weather = weather);
}
public void setDayTime(long time) {
this.daytime = time;
} }
public float getDarkness() { public float getDarkness() {
@ -1867,7 +1875,7 @@ public abstract class World implements IWorldAccess {
public double getSpaceFactor(double x, double y, double z) { public double getSpaceFactor(double x, double y, double z) {
if(this.dimension.getType() == DimType.SEMI) if(this.dimension.getType() == DimType.SEMI)
return ExtMath.clampd((y - (double)World.MAX_SIZE_Y) / 16384.0, 0.0, 1.0); return ExtMath.clampd((y - (double)World.MAX_SIZE_Y) / 16384.0, 0.0, 1.0);
else if(!this.dimension.isCelestial()) else if(!this.dimension.hasRotation())
return 0.0; return 0.0;
double r = (double)this.dimension.getSize(); double r = (double)this.dimension.getSize();
double xm = (Math.abs(x) - r) / 16384.0; double xm = (Math.abs(x) - r) / 16384.0;
@ -1886,6 +1894,30 @@ public abstract class World implements IWorldAccess {
return Math.abs(gravity) < 0.075 ? 0.0 : gravity; return Math.abs(gravity) < 0.075 ? 0.0 : gravity;
} }
public String formatTime() {
return this.dimension.hasOrbit() ? String.format("%03d.%03d", this.rotation / 1000L, this.rotation % 1000L) : "???.???";
}
public static String formatEpoch(Dimension dim, long epoch, boolean extended) {
if(dim != null && dim.hasOrbit()) {
long year = epoch / dim.getOrbitalPeriod();
long frac = (epoch * 1000L / dim.getOrbitalPeriod()) % 1000L;
long day = epoch / dim.getRotationalPeriod();
return String.format("%03d.%03d.M%d" + (extended ? " D%03d.%03d.G%d" : ""), frac, year % 1000L, year / 1000L + 1L, (day / 1000L) % 1000L, day % 1000L, day / 1000000L);
}
else {
return "???.???.M?" + (extended ? " D???.???.G?" : "");
}
}
public String formatEpoch() {
return formatEpoch(this.dimension, this.dimension.getEpoch(), true);
}
public String formatEpochSimple() {
return formatEpoch(this.dimension, this.dimension.getEpoch(), false);
}
public final void playEffect(int type, BlockPos pos, int data) { public final void playEffect(int type, BlockPos pos, int data) {
this.playEffect(null, type, pos, data); this.playEffect(null, type, pos, data);
} }

View file

@ -148,6 +148,7 @@ public final class Server implements IThreadListener, Executor {
private long lastSchedule; private long lastSchedule;
private long lastPoll; private long lastPoll;
private long tpsRate; private long tpsRate;
private long time;
private long lastWarning; private long lastWarning;
@ -433,7 +434,7 @@ public final class Server implements IThreadListener, Executor {
} }
private void saveDimension(Dimension dim) { private void saveDimension(Dimension dim) {
TagObject tag = dim.writeData(false, dim == Space.INSTANCE ? this.space.getDayTime() : dim.getTimeOffset()); TagObject tag = dim.writeData(false, this.time);
File file = new File(new File(new File("chunk"), UniverseRegistry.getName(dim)), "data.cdt"); File file = new File(new File(new File("chunk"), UniverseRegistry.getName(dim)), "data.cdt");
try { try {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
@ -672,6 +673,10 @@ public final class Server implements IThreadListener, Executor {
} }
} }
public long getTime() {
return this.time;
}
public void run(long time) { public void run(long time) {
Region.loadMap(); Region.loadMap();
this.loadServerConfig(); this.loadServerConfig();
@ -684,7 +689,7 @@ public final class Server implements IThreadListener, Executor {
this.keyPair = EncryptUtil.createKeypair(); this.keyPair = EncryptUtil.createKeypair();
} }
User.loadDatabase(this.users); User.loadDatabase(this.users);
this.worlds.add(this.space = new WorldServer(this, 0L, Space.INSTANCE, UniverseRegistry.getGenerator(Space.INSTANCE))); this.worlds.add(this.space = new WorldServer(this, Space.INSTANCE));
this.dimensions.put(UniverseRegistry.getId(this.space.dimension), this.space); this.dimensions.put(UniverseRegistry.getId(this.space.dimension), this.space);
new File("players").mkdirs(); new File("players").mkdirs();
this.setTpsTarget(20.0f); this.setTpsTarget(20.0f);
@ -805,7 +810,8 @@ public final class Server implements IThreadListener, Executor {
} }
if(++this.syncTimer == 20) { if(++this.syncTimer == 20) {
for(Player conn : this.players) { for(Player conn : this.players) {
this.sendPacket(new SPacketTimeUpdate((conn.getPresentEntity() == null ? this.space : conn.getPresentEntity().worldObj).getDayTime(), Dimensions.formatTime(conn.getPresentEntity() == null ? this.space : (WorldServer)conn.getPresentEntity().worldObj, conn.getPresentEntity(), true), this.getInfo())); WorldServer world = conn.getPresentEntity() == null ? this.space : (WorldServer)conn.getPresentEntity().worldObj;
this.sendPacket(new SPacketTimeUpdate(world.getOrbit(), world.getRotation(), Dimensions.formatTime(world, this.time, conn.getPresentEntity()), this.getInfo()));
} }
this.syncTimer = 0; this.syncTimer = 0;
} }
@ -831,6 +837,8 @@ public final class Server implements IThreadListener, Executor {
this.saveAllWorlds(false); this.saveAllWorlds(false);
this.saveTimer = 0; this.saveTimer = 0;
} }
if(Vars.timeFlow > 0)
this.time += (long)Vars.timeFlow;
Log.flushLog(); Log.flushLog();
this.tickTimes[this.perfTimer++] = System.currentTimeMillis() - now; this.tickTimes[this.perfTimer++] = System.currentTimeMillis() - now;
if(this.perfTimer == 100) { if(this.perfTimer == 100) {
@ -847,7 +855,7 @@ public final class Server implements IThreadListener, Executor {
return null; return null;
WorldServer world = this.dimensions.get(UniverseRegistry.getId(dim)); WorldServer world = this.dimensions.get(UniverseRegistry.getId(dim));
if(world == null) { if(world == null) {
world = new WorldServer(this, this.space.getDayTime(), dim, UniverseRegistry.getGenerator(dim)); world = new WorldServer(this, dim);
this.worlds.add(world); this.worlds.add(world);
this.dimensions.put(UniverseRegistry.getId(dim), world); this.dimensions.put(UniverseRegistry.getId(dim), world);
} }
@ -1012,7 +1020,7 @@ public final class Server implements IThreadListener, Executor {
} }
conn.sendPacket(new SPacketServerConfig(vars)); conn.sendPacket(new SPacketServerConfig(vars));
conn.sendPacket(new SPacketDimensions(Dimensions.getDimensionData())); conn.sendPacket(new SPacketDimensions(Dimensions.getDimensionData()));
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, world.getDayTime(), UniverseRegistry.getName(world.dimension), EntityRegistry.getEntityID(player), tag == null)); conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, this.time, UniverseRegistry.getName(world.dimension), EntityRegistry.getEntityID(player), tag == null));
conn.sendPacket(new SPacketHeldItemChange(player.getSelectedIndex())); conn.sendPacket(new SPacketHeldItemChange(player.getSelectedIndex()));
this.sendPacket(new SPacketPlayerListItem(false, conn)); this.sendPacket(new SPacketPlayerListItem(false, conn));
@ -1147,7 +1155,7 @@ public final class Server implements IThreadListener, Executor {
nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ); nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ);
} }
} }
conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, world.getDayTime(), world.dimension != oldWorld.dimension ? UniverseRegistry.getName(world.dimension) : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor())); conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, this.time, world.dimension != oldWorld.dimension ? UniverseRegistry.getName(world.dimension) : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch); conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel)); conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
this.updateTimeAndWeatherForPlayer(conn, world); this.updateTimeAndWeatherForPlayer(conn, world);
@ -1189,7 +1197,7 @@ public final class Server implements IThreadListener, Executor {
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4); world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
world.addPlayer(nplayer); world.addPlayer(nplayer);
world.spawnEntityInWorld(nplayer); world.spawnEntityInWorld(nplayer);
conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, world.getDayTime(), world.dimension != oldWorld.dimension ? UniverseRegistry.getName(world.dimension) : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor())); conn.sendPacket(new SPacketRespawn(world.dimension != oldWorld.dimension ? world.dimension : null, this.time, world.dimension != oldWorld.dimension ? UniverseRegistry.getName(world.dimension) : null, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
conn.sendPacket(new SPacketSkin(nplayer.getId(), nplayer.getSkin())); // , nplayer.getModel())); conn.sendPacket(new SPacketSkin(nplayer.getId(), nplayer.getSkin())); // , nplayer.getModel()));
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch); conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel)); conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
@ -1207,7 +1215,7 @@ public final class Server implements IThreadListener, Executor {
public void transferToDimension(EntityNPC player, Dimension dimension, BlockPos pos, float yaw, float pitch, PortalType portal) { public void transferToDimension(EntityNPC player, Dimension dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
WorldServer oldWorld = (WorldServer)player.getServerWorld(); // this.getWorld(player.dimension); WorldServer oldWorld = (WorldServer)player.getServerWorld(); // this.getWorld(player.dimension);
WorldServer newWorld = this.getWorld(dimension); WorldServer newWorld = this.getWorld(dimension);
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, newWorld.getDayTime(), UniverseRegistry.getName(newWorld.dimension), EntityRegistry.getEntityID(player), player.connection.isInEditor())); player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, this.time, UniverseRegistry.getName(newWorld.dimension), EntityRegistry.getEntityID(player), player.connection.isInEditor()));
oldWorld.removePlayerEntityDangerously(player); oldWorld.removePlayerEntityDangerously(player);
player.dead = false; player.dead = false;
this.placeInDimension(player, oldWorld, newWorld, pos, portal); this.placeInDimension(player, oldWorld, newWorld, pos, portal);
@ -1278,7 +1286,7 @@ public final class Server implements IThreadListener, Executor {
} }
private void updateTimeAndWeatherForPlayer(Player conn, WorldServer world) { private void updateTimeAndWeatherForPlayer(Player conn, WorldServer world) {
conn.sendPacket(new SPacketTimeUpdate(world.getDayTime(), Dimensions.formatTime(world, conn.getPresentEntity(), true), this.getInfo())); conn.sendPacket(new SPacketTimeUpdate(world.getOrbit(), world.getRotation(), Dimensions.formatTime(world, this.time, conn.getPresentEntity()), this.getInfo()));
conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER, world.getWeather().ordinal())); conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER, world.getWeather().ordinal()));
conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, world.getRainStrength())); conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, world.getRainStrength()));
conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, world.getDarkness())); conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, world.getDarkness()));

View file

@ -239,7 +239,6 @@ public class CommandEnvironment {
this.registerExecutable(new CommandWorld()); this.registerExecutable(new CommandWorld());
this.registerExecutable(new CommandOfflinetp()); this.registerExecutable(new CommandOfflinetp());
this.registerExecutable(new CommandWarp()); this.registerExecutable(new CommandWarp());
this.registerExecutable(new CommandTime());
this.registerExecutable(new CommandRemove()); this.registerExecutable(new CommandRemove());
this.registerExecutable(new CommandWeather()); this.registerExecutable(new CommandWeather());
this.registerExecutable(new CommandKick()); this.registerExecutable(new CommandKick());
@ -281,6 +280,9 @@ public class CommandEnvironment {
this.registerExecutable(new CommandReset()); this.registerExecutable(new CommandReset());
this.registerExecutable(new CommandTick()); this.registerExecutable(new CommandTick());
this.registerExecutable(new CommandFreeze()); this.registerExecutable(new CommandFreeze());
this.registerExecutable(new CommandEpoch());
this.registerExecutable(new CommandTime());
this.registerExecutable(new CommandSeason());
this.registerExecutable(new CommandSet()); this.registerExecutable(new CommandSet());
} }

View file

@ -0,0 +1,61 @@
package server.command.commands;
import common.dimension.Dimension;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.world.WorldServer;
public class CommandEpoch extends Command {
public CommandEpoch() {
super("epoch");
this.addString("epoch", false, "1h", "10h", "20h", "50h", "1d", "10d", "20d", "50d", "1y", "10y", "20y", "50y", "1m", "10m", "20m", "50m");
this.addWorld("dim", true);
this.setParamsOptional();
this.addFlag("absolute", 'a');
}
public static long parseInt(String input, long max) {
long num;
try {
num = Long.parseLong(input);
}
catch(NumberFormatException e) {
throw new RunException("'%s' ist keine gültige Zahl", input);
}
if(num < 0)
throw new RunException("Die Zeit muss mindestens 0 betragen", num);
else if(num > max)
throw new RunException("Die Zeit darf höchstens %d betragen", num, max);
return num;
}
private long parseTime(Dimension dim, String arg) {
long t;
if(arg.toLowerCase().endsWith("m"))
t = dim.getOrbitalPeriod() * 1000L;
else if(arg.toLowerCase().endsWith("y"))
t = dim.getOrbitalPeriod();
else if(arg.toLowerCase().endsWith("d"))
t = dim.getRotationalPeriod();
else if(arg.toLowerCase().endsWith("h"))
t = 1000L;
else
t = -1L;
arg = t == -1L ? arg : arg.substring(0, arg.length() - 1);
t = t < 1L ? 1L : t;
return t * parseInt(arg, Long.MAX_VALUE);
}
public Object exec(CommandEnvironment env, Executor exec, String timeStr, WorldServer world, boolean absolute) {
long time = absolute ? 0L : world.dimension.getEpoch();
time += parseTime(world.dimension, timeStr);
world.dimension.setEpoch(time);
world.resetWeather();
exec.log("Zeit in %s auf %s gesetzt", world.dimension.getDisplay(), world.formatEpoch());
return time;
}
}

View file

@ -16,7 +16,7 @@ public class CommandFreeze extends Command {
exec.log("Die Welt ist jetzt nicht mehr eingefroren"); exec.log("Die Welt ist jetzt nicht mehr eingefroren");
return; return;
} }
env.getServer().setVariableOverride("freeze", () -> {SVars.randomTick = 0; SVars.boltChance = 0; SVars.weatherTick = 0; SVars.weatherChance = 0; SVars.tickSpawn = false; Vars.dayCycle = false; Vars.mobTick = false; Vars.liquidPhysics = false; Vars.blockGravity = false; Vars.fire = false;}); env.getServer().setVariableOverride("freeze", () -> {SVars.randomTick = 0; SVars.boltChance = 0; SVars.weatherTick = 0; SVars.weatherChance = 0; SVars.tickSpawn = false; Vars.timeFlow = 0; Vars.mobTick = false; Vars.liquidPhysics = false; Vars.blockGravity = false; Vars.fire = false;});
exec.log("Welt wurde eingefroren"); exec.log("Welt wurde eingefroren");
} }
} }

View file

@ -0,0 +1,72 @@
package server.command.commands;
import common.dimension.Dimension;
import server.command.Command;
import server.command.CommandEnvironment;
import server.command.Executor;
import server.command.RunException;
import server.world.WorldServer;
public class CommandSeason extends Command {
public CommandSeason() {
super("season");
this.addString("season", false, "spring", "summer", "autumn", "winter", "1d", "10d", "20d", "50d");
this.addWorld("dim", true);
this.setParamsOptional();
this.addFlag("absolute", 'a');
}
private long parseOrbitTime(Dimension dim, String arg) {
if(arg.equalsIgnoreCase("spring"))
return 0L;
else if(arg.equalsIgnoreCase("summer"))
return dim.getOrbitalPeriod() / 4L;
else if(arg.equalsIgnoreCase("autumn"))
return dim.getOrbitalPeriod() / 2L;
else if(arg.equalsIgnoreCase("winter"))
return dim.getOrbitalPeriod() * 3L / 4L;
else if(arg.startsWith("@"))
return CommandEpoch.parseInt(arg.substring(1), dim.getOrbitalPeriod() - 1);
else
return -1L;
}
private long parseTime(Dimension dim, String arg) {
long t;
if(arg.toLowerCase().endsWith("d"))
t = dim.getRotationalPeriod();
else
t = -1L;
arg = t == -1L ? arg : arg.substring(0, arg.length() - 1);
t = t < 1L ? 1L : t;
return t * CommandEpoch.parseInt(arg, Long.MAX_VALUE);
}
public Object exec(CommandEnvironment env, Executor exec, String timeStr, WorldServer world, boolean absolute) {
if(!world.dimension.hasOrbit())
throw new RunException("Welt %s hat keine Jahreszeiten", world.dimension.getDisplay());
long time = absolute ? 0L : world.getOrbit();
long fwd = parseOrbitTime(world.dimension, timeStr);
if(fwd >= 0L) {
if(absolute) {
time += fwd;
}
else {
time -= world.getOrbit() % world.dimension.getOrbitalPeriod();
time += fwd;
time += time <= world.getOrbit() ? world.dimension.getOrbitalPeriod() : 0L;
}
}
else {
time += parseTime(world.dimension, timeStr);
}
time = time % world.dimension.getOrbitalPeriod();
world.dimension.setOrbit(time);
world.setOrbit(time);
world.resetWeather();
exec.log("Jahreszeit in %s auf %s (%d / %d) gesetzt", world.dimension.getDisplay(), world.getLeavesType().getDisplay(), world.getOrbit(), world.dimension.getOrbitalPeriod());
return time;
}
}

View file

@ -1,41 +1,21 @@
package server.command.commands; package server.command.commands;
import common.dimension.Dimension; import common.dimension.Dimension;
import common.dimension.Space;
import server.command.Command; import server.command.Command;
import server.command.CommandEnvironment; import server.command.CommandEnvironment;
import server.command.Executor; import server.command.Executor;
import server.command.RunException; import server.command.RunException;
import server.dimension.Dimensions;
import server.init.UniverseRegistry;
import server.network.Player;
import server.world.WorldServer; import server.world.WorldServer;
public class CommandTime extends Command { public class CommandTime extends Command {
public CommandTime() { public CommandTime() {
super("time"); super("time");
this.addString("time", false, "day", "night", "noon", "midnight", "sunrise", "sunset"); this.addString("time", false, "day", "night", "noon", "midnight", "sunrise", "sunset", "1h", "10h", "20h", "50h");
this.addWorld("dim", true); this.addWorld("dim", true);
this.setParamsOptional(); this.setParamsOptional();
this.addFlag("absolute", 'a'); this.addFlag("absolute", 'a');
this.addFlag("global", 'g');
}
private long parseInt(String input, long max) {
long num;
try {
num = Long.parseLong(input);
}
catch(NumberFormatException e) {
throw new RunException("'%s' ist keine gültige Zahl", input);
}
if(num < 0)
throw new RunException("Die Zeit muss mindestens 0 betragen", num);
else if(num > max)
throw new RunException("Die Zeit darf höchstens %d betragen", num, max);
return num;
} }
private long parseDayTime(Dimension dim, String arg) { private long parseDayTime(Dimension dim, String arg) {
@ -52,65 +32,45 @@ public class CommandTime extends Command {
else if(arg.equalsIgnoreCase("midnight")) else if(arg.equalsIgnoreCase("midnight"))
return 0L; return 0L;
else if(arg.startsWith("@")) else if(arg.startsWith("@"))
return this.parseInt(arg.substring(1), dim.getRotationalPeriod() - 1); return CommandEpoch.parseInt(arg.substring(1), dim.getRotationalPeriod() - 1);
else else
return -1L; return -1L;
} }
private long parseTime(Dimension dim, String arg) { private long parseTime(Dimension dim, String arg) {
long t; long t;
if(arg.toLowerCase().endsWith("y")) if(arg.toLowerCase().endsWith("h"))
t = dim.getOrbitalPeriod();
else if(arg.toLowerCase().endsWith("d"))
t = dim.getRotationalPeriod();
else if(arg.toLowerCase().endsWith("h"))
t = 1000L; t = 1000L;
else else
t = -1L; t = -1L;
arg = t == -1L ? arg : arg.substring(0, arg.length() - 1); arg = t == -1L ? arg : arg.substring(0, arg.length() - 1);
t = t < 1L ? 1L : t; t = t < 1L ? 1L : t;
return t * this.parseInt(arg, Long.MAX_VALUE); return t * CommandEpoch.parseInt(arg, Long.MAX_VALUE);
} }
public Object exec(CommandEnvironment env, Executor exec, String timeStr, WorldServer world, boolean absolute, boolean global) { public Object exec(CommandEnvironment env, Executor exec, String timeStr, WorldServer world, boolean absolute) {
long time = absolute ? 0L : world.getDayTime(); if(!world.dimension.hasRotation())
throw new RunException("Welt %s hat keine Tageszeit", world.dimension.getDisplay());
long time = absolute ? 0L : world.getRotation();
long fwd = parseDayTime(world.dimension, timeStr); long fwd = parseDayTime(world.dimension, timeStr);
if(fwd >= 0L) { if(fwd >= 0L) {
if(absolute) { if(absolute) {
time += fwd; time += fwd;
} }
else { else {
time -= world.getDayTime() % world.dimension.getRotationalPeriod(); time -= world.getRotation() % world.dimension.getRotationalPeriod();
time += fwd; time += fwd;
time += time <= world.getDayTime() ? world.dimension.getRotationalPeriod() : 0L; time += time <= world.getRotation() ? world.dimension.getRotationalPeriod() : 0L;
} }
} }
else { else {
time += parseTime(world.dimension, timeStr); time += parseTime(world.dimension, timeStr);
} }
if(global) { time = time % world.dimension.getRotationalPeriod();
for(Dimension dim : UniverseRegistry.getDimensions()) { world.dimension.setRotation(time);
dim.setTimeOffset(dim != Space.INSTANCE ? 0L : time); world.setRotation(time);
} world.resetWeather();
for(WorldServer wld : env.getServer().getWorlds()) { exec.log("Tageszeit in %s auf %s (%d / %d) gesetzt", world.dimension.getDisplay(), world.formatTime(), world.getRotation(), world.dimension.getRotationalPeriod());
wld.setDayTime(time);
wld.resetWeather();
}
}
else {
if(world.dimension == Space.INSTANCE) {
long diff = time - world.getDayTime();
for(Dimension dim : UniverseRegistry.getDimensions()) {
dim.setTimeOffset(dim != Space.INSTANCE ? dim.getTimeOffset() - diff : time);
}
}
else {
world.dimension.setTimeOffset(time - env.getServer().getSpace().getDayTime());
}
world.setDayTime(time);
world.resetWeather();
}
exec.log("Zeit " + (global ? "aller Dimensionen (relativ zu %s)" : "in %s") + " auf %s gesetzt", world.dimension.getDisplay(), Dimensions.formatTime(world, exec.isPlayer() ? ((Player)exec).getPresentEntity() : null, false));
return time; return time;
} }
} }

View file

@ -12,6 +12,7 @@ import common.dimension.Space;
import common.dimension.Star; import common.dimension.Star;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.packet.SPacketDimensions.DimData; import common.packet.SPacketDimensions.DimData;
import common.world.World;
import server.init.UniverseRegistry; import server.init.UniverseRegistry;
import server.world.WorldServer; import server.world.WorldServer;
@ -105,36 +106,10 @@ public abstract class Dimensions {
return 6; return 6;
} }
public static String formatTime(WorldServer world, Dimension home, int category, boolean days) { public static String formatTime(WorldServer world, long time, EntityNPC player) {
String qualifier = home != null ? (category >= 0 ? category + "." : "?.") : ""; Dimension dim = player == null ? null : player.getOrigin().getDimension();
long time = world.getDayTime(); int category = getTimeQualifier(world.dimension, dim);
String gtime; return (category >= 0 ? category + "." : "?.") + World.formatEpoch(dim, dim == null ? 0L : dim.getEpoch() + time - dim.getLastTicked(), true);
if((home == null || !home.isCelestial()) && !world.dimension.isCelestial()) {
gtime = "???.???.M?";
}
else {
long yearTime = (home != null && home.isCelestial() ? home : world.dimension).getOrbitalPeriod();
long year = time / yearTime;
long frac = (time * 1000L / yearTime) % 1000L;
gtime = String.format("%03d.%03d.M%d", frac, year % 1000L, year / 1000L + 1L);
}
if(!days)
return qualifier + gtime;
String ltime;
if(!world.dimension.isCelestial()) {
ltime = " T???.??? D???.???.G?";
}
else {
long day = time / world.dimension.getRotationalPeriod();
time = time % world.dimension.getRotationalPeriod();
ltime = String.format(" T%03d.%03d D%03d.%03d.G%d",
time / 1000L, time % 1000L, (day / 1000L) % 1000L, day % 1000L, day / 1000000L);
}
return qualifier + gtime + ltime;
}
public static String formatTime(WorldServer world, EntityNPC player, boolean days) {
return formatTime(world, player == null ? null : player.getOrigin().getDimension(), player == null ? -1 : getTimeQualifier(world.dimension, player.getOrigin().getDimension()), days);
} }
public static void updateDimensions() { public static void updateDimensions() {

View file

@ -249,18 +249,23 @@ public final class WorldServer extends AWorldServer {
} }
} }
public WorldServer(Server server, long dtime, Dimension dim, GeneratorData gen) { public WorldServer(Server server, Dimension dim) {
super(dim); super(dim);
this.server = server; this.server = server;
// this.time = time; this.time = this.dimension.getTimeExisted();
this.daytime = dtime + this.dimension.getTimeOffset(); long dtime = this.server.getTime() - this.dimension.getLastTicked();
this.gen = gen; this.dimension.setLastTicked(this.server.getTime());
if(this.dimension.hasOrbit())
this.dimension.setOrbit(this.orbit = (this.dimension.getOrbit() + dtime) % this.dimension.getOrbitalPeriod());
if(this.dimension.hasRotation())
this.dimension.setRotation(this.rotation = (this.dimension.getRotation() + dtime) % this.dimension.getRotationalPeriod());
this.dimension.setEpoch(this.dimension.getEpoch() + dtime);
this.gen = UniverseRegistry.getGenerator(dim);
this.updateViewRadius(); this.updateViewRadius();
this.chunkDir = new File(new File("chunk"), UniverseRegistry.getName(dim)); this.chunkDir = new File(new File("chunk"), UniverseRegistry.getName(dim));
this.chunkDir.mkdirs(); this.chunkDir.mkdirs();
this.seed = this.dimension.getSeed(); this.seed = this.dimension.getSeed();
this.time = this.dimension.getTimeExisted();
this.grng = new Random(this.seed ^ 836430928262265276L); this.grng = new Random(this.seed ^ 836430928262265276L);
this.tempGen = new PerlinGen(this.grng, 1); this.tempGen = new PerlinGen(this.grng, 1);
@ -320,9 +325,14 @@ public final class WorldServer extends AWorldServer {
// if(this.primary) // if(this.primary)
// this.info.tick(); // this.info.tick();
this.dimension.setTimeExisted(this.time += 1L); this.dimension.setTimeExisted(this.time += 1L);
// this.dataModified = true; this.dimension.setLastTicked(this.server.getTime());
if(Vars.dayCycle) // { if(Vars.timeFlow > 0) {
this.daytime += (long)Vars.timeFlow; if(this.dimension.hasOrbit())
this.dimension.setOrbit(this.orbit = ((this.orbit + (long)Vars.timeFlow) % this.dimension.getOrbitalPeriod()));
if(this.dimension.hasRotation())
this.dimension.setRotation(this.rotation = ((this.rotation + (long)Vars.timeFlow) % this.dimension.getRotationalPeriod()));
this.dimension.setEpoch(this.dimension.getEpoch() + (long)Vars.timeFlow);
}
// if(this.dimension.getType().dayCycle) // if(this.dimension.getType().dayCycle)
// this.season = this.getSeasonByTime(); // this.season = this.getSeasonByTime();
// } // }
@ -2199,8 +2209,8 @@ public final class WorldServer extends AWorldServer {
public LeavesType getLeavesGen(BlockPos pos) { public LeavesType getLeavesGen(BlockPos pos) {
return this.canFreezeAt(pos) ? LeavesType.SNOWY : (!this.dimension.hasSeasons() ? return this.canFreezeAt(pos) ? LeavesType.SNOWY : (!this.dimension.hasSeasons() ?
this.gen.getLeavesType() : LeavesType.values()[(int)((this.daytime % this.gen.getLeavesType() : LeavesType.values()[(int)((this.orbit %
this.dimension.getOrbitalPeriod()) * (long)LeavesType.values().length / this.dimension.getOrbitalPeriod())]); this.dimension.getOrbitalPeriod()) * 4L / this.dimension.getOrbitalPeriod())]);
} }
// public boolean canBlockSeeSky(BlockPos pos) { // public boolean canBlockSeeSky(BlockPos pos) {