add variable sync

This commit is contained in:
Sen 2025-07-11 23:01:59 +02:00
parent b6242d5de1
commit aee94aa14d
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
33 changed files with 392 additions and 200 deletions

View file

@ -5,12 +5,12 @@ import java.util.Map;
import common.collect.Maps;
public enum DimType {
STAR("star", "Stern %s", true, false, false, false, false, false, true),
PLANET("planet", "Planet %s", true, true, true, true, true, true, true),
MOON("moon", "Mond %s", true, false, false, true, false, false, true),
SPACE("space", "%s", false, false, false, false, false, false, true),
SEMI("semi", "%s", false, false, true, false, false, true, true),
AREA("area", "%s", false, false, false, false, false, false, false);
STAR("star", "Stern %s", true, false, false, false, false, true),
PLANET("planet", "Planet %s", true, true, true, true, true, true),
MOON("moon", "Mond %s", true, false, false, true, false, true),
SPACE("space", "%s", false, false, false, false, false, true),
SEMI("semi", "%s", false, false, true, false, true, true),
AREA("area", "%s", false, false, false, false, false, false);
private static final Map<String, DimType> LOOKUP = Maps.newHashMap();
@ -19,20 +19,17 @@ public enum DimType {
public final boolean time;
public final boolean days;
public final boolean weather;
public final boolean sun;
public final boolean moon;
public final boolean celestials;
public final boolean clouds;
public final boolean sky;
private DimType(String name, String format,
boolean time, boolean days, boolean weather, boolean sun, boolean moon, boolean clouds, boolean sky) {
private DimType(String name, String format, boolean time, boolean days, boolean weather, boolean celestials, boolean clouds, boolean sky) {
this.name = name;
this.format = format;
this.time = time;
this.days = days;
this.weather = weather;
this.sun = sun;
this.moon = moon;
this.celestials = celestials;
this.clouds = clouds;
this.sky = sky;
}

View file

@ -159,6 +159,8 @@ public abstract class Dimension extends Nameable {
private ColorGenerator starColorFunc = null;
private ColorGenerator deepstarColorFunc = null;
private String display; // synced only
private int sunColor = 0xffffffff;
private int[] moonColors = null;
// common
private float gravity = 1.0f;
@ -739,6 +741,31 @@ public abstract class Dimension extends Nameable {
public final boolean hasDenseFog() {
return this.denseFog;
}
protected int calcSunColor() {
return 0xffffffff;
}
protected int[] calcMoonColors() {
return new int[0];
}
public final int getSunColor() {
return this.sunColor != 0xffffffff ? this.sunColor : this.calcSunColor();
}
public final int[] getMoonColors() {
return this.moonColors != null ? this.moonColors : this.calcMoonColors();
}
public final void setSunColor(int color) {
this.sunColor = color;
}
public final void setMoonColors(int[] colors) {
this.moonColors = colors;
}
public final State getFiller() {

View file

@ -1,5 +1,7 @@
package common.dimension;
import common.init.UniverseRegistry;
public final class Moon extends Dimension {
Moon() {
super(true);
@ -16,4 +18,17 @@ public final class Moon extends Dimension {
public final DimType getType() {
return DimType.MOON;
}
protected int calcSunColor() {
Planet planet = UniverseRegistry.getPlanet(this);
if(planet == null)
return super.calcSunColor();
Star star = UniverseRegistry.getStar(planet);
return star == null ? super.calcSunColor() : star.getSkyColor();
}
protected int[] calcMoonColors() {
Planet planet = UniverseRegistry.getPlanet(this);
return planet == null ? super.calcMoonColors() : new int[] {planet.getSkyColor()};
}
}

View file

@ -1,11 +1,11 @@
package common.dimension;
import java.util.Set;
import common.collect.Sets;
import java.util.List;
import common.collect.Lists;
import common.init.UniverseRegistry;
public final class Planet extends Dimension {
private final Set<Moon> moons = Sets.newHashSet();
private final List<Moon> moons = Lists.newArrayList();
Planet() {
super(true);
@ -41,4 +41,17 @@ public final class Planet extends Dimension {
public final DimType getType() {
return DimType.PLANET;
}
protected int calcSunColor() {
Star star = UniverseRegistry.getStar(this);
return star == null ? super.calcSunColor() : star.getSkyColor();
}
protected int[] calcMoonColors() {
int[] colors = new int[this.moons.size()];
for(int z = 0; z < colors.length; z++) {
colors[z] = this.moons.get(z).getSkyColor();
}
return colors;
}
}

View file

@ -302,6 +302,14 @@ public abstract class UniverseRegistry {
return dim == null ? null : NAMES.get(dim);
}
public static Star getStar(Planet planet) {
return PLANET_MAP.get(planet);
}
public static Planet getPlanet(Moon moon) {
return MOON_MAP.get(moon);
}
public static Dimension getDimension(String name) {
return NAME_MAP.get(name);
}

View file

@ -22,7 +22,7 @@ import common.packet.SPacketWindowItems;
import common.packet.SPacketWindowProperty;
import common.packet.SPacketConfirmTransaction;
import common.packet.SPacketUpdateSign;
import common.packet.SPacketUpdateTileEntity;
import common.packet.SPacketUpdateDevice;
import common.packet.SPacketSignEditorOpen;
import common.packet.SPacketPlayerListItem;
import common.packet.SPacketPlayerAbilities;
@ -52,6 +52,7 @@ import common.packet.SPacketMessage;
import common.packet.SPacketMultiBlockChange;
import common.packet.SPacketPlayerPosLook;
import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketServerTick;
import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin;
@ -62,7 +63,6 @@ import common.packet.SPacketTimeUpdate;
import common.packet.SPacketTrades;
import common.packet.SPacketUpdateDisplay;
import common.packet.SPacketUpdateHealth;
import common.packet.SPacketWorld;
import common.sound.Sound;
public interface IClientPlayer extends NetHandler {
@ -116,7 +116,7 @@ public interface IClientPlayer extends NetHandler {
void handleSignEditorOpen(SPacketSignEditorOpen packet);
void handleUpdateSign(SPacketUpdateSign packet);
void handleUpdateDisplay(SPacketUpdateDisplay packet);
void handleUpdateTileEntity(SPacketUpdateTileEntity packet);
void handleUpdateTileEntity(SPacketUpdateDevice packet);
void handleWindowProperty(SPacketWindowProperty packet);
void handleEntityEquipment(SPacketEntityEquipment packet);
void handleCloseWindow(SPacketCloseWindow packet);
@ -138,7 +138,7 @@ public interface IClientPlayer extends NetHandler {
void handleParticles(SPacketParticles packet);
void handleSkin(SPacketSkin packet);
void handleTrades(SPacketTrades packet);
void handleWorld(SPacketWorld packet);
void handleDimName(SPacketDimensionName packet);
void handleForm(SPacketDisplayForm packet);
void handleServerConfig(SPacketServerConfig packet);
}

View file

@ -59,7 +59,7 @@ import common.packet.SPacketWindowItems;
import common.packet.SPacketWindowProperty;
import common.packet.SPacketConfirmTransaction;
import common.packet.SPacketUpdateSign;
import common.packet.SPacketUpdateTileEntity;
import common.packet.SPacketUpdateDevice;
import common.packet.SPacketSignEditorOpen;
import common.packet.SPacketPlayerListItem;
import common.packet.SPacketPlayerAbilities;
@ -89,6 +89,7 @@ import common.packet.SPacketMessage;
import common.packet.SPacketMultiBlockChange;
import common.packet.SPacketPlayerPosLook;
import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketServerTick;
import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin;
@ -99,7 +100,6 @@ import common.packet.SPacketTimeUpdate;
import common.packet.SPacketTrades;
import common.packet.SPacketUpdateDisplay;
import common.packet.SPacketUpdateHealth;
import common.packet.SPacketWorld;
public enum PacketRegistry {
HANDSHAKE {{
@ -169,14 +169,13 @@ public enum PacketRegistry {
this.server(SPacketConfirmTransaction.class);
this.server(SPacketUpdateSign.class);
this.server(SPacketUpdateDisplay.class);
this.server(SPacketUpdateTileEntity.class);
this.server(SPacketUpdateDevice.class);
this.server(SPacketSignEditorOpen.class);
this.server(SPacketPlayerListItem.class);
this.server(SPacketPlayerAbilities.class);
this.server(SPacketTabComplete.class);
this.server(SPacketSkin.class);
this.server(SPacketDisconnect.class);
this.server(SPacketWorld.class);
this.server(SPacketCamera.class);
this.server(SPacketBiome.class);
this.server(SPacketUpdateEntityTags.class);
@ -186,6 +185,7 @@ public enum PacketRegistry {
this.server(SPacketServerTick.class);
this.server(SPacketLoading.class);
this.server(SPacketDisplayForm.class);
this.server(SPacketServerConfig.class);
this.client(CPacketKeepAlive.class);
this.client(CPacketMessage.class);

View file

@ -18,6 +18,8 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
private String dimName;
private String dimDisplay;
private String dimFull;
private int sunColor;
private int[] moonColors;
private int type;
private boolean editor;
@ -37,6 +39,10 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
this.dimName = UniverseRegistry.getName(dim);
this.dimDisplay = dim.getCustomName();
this.dimFull = dim.getFormattedName(true);
if(this.dimType.celestials) {
this.sunColor = dim.getSunColor();
this.moonColors = dim.getMoonColors();
}
this.dimId = -1;
}
else {
@ -61,6 +67,13 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
this.dimName = buf.readString(1024);
this.dimDisplay = buf.readString(1024);
this.dimFull = buf.readString(4096);
if(this.dimType.celestials) {
this.sunColor = buf.readInt();
this.moonColors = new int[buf.readVarInt()];
for(int z = 0; z < this.moonColors.length; z++) {
this.moonColors[z] = buf.readInt();
}
}
}
this.type = buf.readUnsignedShort();
this.editor = buf.readBoolean();
@ -76,6 +89,13 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
buf.writeString(this.dimName);
buf.writeString(this.dimDisplay);
buf.writeString(this.dimFull);
if(this.dimType.celestials) {
buf.writeInt(this.sunColor);
buf.writeVarInt(this.moonColors.length);
for(int z = 0; z < this.moonColors.length; z++) {
buf.writeInt(this.moonColors[z]);
}
}
}
buf.writeShort(this.type & 65535);
buf.writeBoolean(this.editor);
@ -91,6 +111,10 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
dim.fromTags(this.dimData);
dim.setCustomName(this.dimDisplay);
dim.setDisplayName(this.dimFull);
if(this.dimType.celestials) {
dim.setSunColor(this.sunColor);
dim.setMoonColors(this.moonColors);
}
return dim;
}

View file

@ -0,0 +1,83 @@
package common.packet;
import java.io.IOException;
import java.util.List;
import common.collect.Lists;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
import common.util.Pair;
public class SPacketServerConfig implements Packet<IClientPlayer> {
private List<Pair<String, Object>> values;
public SPacketServerConfig() {
}
public SPacketServerConfig(List<Pair<String, Object>> values) {
this.values = values;
}
public SPacketServerConfig(String var, Object value) {
this.values = Lists.newArrayList(new Pair(var, value));
}
public void readPacketData(PacketBuffer buf) throws IOException {
this.values = Lists.newArrayList();
int n = buf.readVarInt();
for(int z = 0; z < n; z++) {
String var = buf.readString(64);
Object value;
switch(buf.readByte()) {
case 0:
default:
value = false;
break;
case 1:
value = true;
break;
case 2:
value = buf.readVarInt();
break;
case 3:
value = buf.readFloat();
break;
case 4:
value = buf.readString(1024);
break;
}
this.values.add(new Pair(var, value));
}
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeVarInt(this.values.size());
for(Pair<String, Object> var : this.values) {
buf.writeString(var.first());
if(var.second() instanceof Boolean bool) {
buf.writeByte(bool ? 1 : 0);
}
else if(var.second() instanceof Integer i) {
buf.writeByte(2);
buf.writeVarInt(i);
}
else if(var.second() instanceof Float f) {
buf.writeByte(3);
buf.writeFloat(f);
}
else if(var.second() instanceof String str) {
buf.writeByte(4);
buf.writeString(str);
}
}
}
public void processPacket(IClientPlayer handler) {
handler.handleServerConfig(this);
}
public List<Pair<String, Object>> getValues() {
return this.values;
}
}

View file

@ -12,17 +12,17 @@ import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.world.State;
public class SPacketUpdateTileEntity implements Packet<IClientPlayer>
public class SPacketUpdateDevice implements Packet<IClientPlayer>
{
private BlockPos blockPos;
private Block type;
private TagObject tag;
public SPacketUpdateTileEntity()
public SPacketUpdateDevice()
{
}
public SPacketUpdateTileEntity(TileEntity tile)
public SPacketUpdateDevice(TileEntity tile)
{
this.blockPos = tile.getPos();
this.type = tile.getBlockType();

View file

@ -1,51 +0,0 @@
package common.packet;
import java.io.IOException;
import common.network.IClientPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
public class SPacketWorld implements Packet<IClientPlayer> {
private float gravity;
private int timeFactor;
private boolean dayCycle;
public SPacketWorld() {
}
public SPacketWorld(float gravity, boolean dayCycle, int timeFactor) {
this.gravity = gravity;
this.timeFactor = timeFactor;
this.dayCycle = dayCycle;
}
public void processPacket(IClientPlayer handler) {
handler.handleWorld(this);
}
public void readPacketData(PacketBuffer buf) throws IOException {
this.gravity = buf.readFloat();
this.timeFactor = buf.readVarInt();
int flags = buf.readUnsignedByte();
this.dayCycle = (flags & 1) > 0;
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeFloat(this.gravity);
buf.writeVarInt(this.timeFactor);
buf.writeByte(this.dayCycle ? 1 : 0);
}
public float getGravity() {
return this.gravity;
}
public int getTimeFactor() {
return this.timeFactor;
}
public boolean hasDayCycle() {
return this.dayCycle;
}
}

View file

@ -8,7 +8,7 @@ import common.inventory.ContainerTile;
import common.inventory.InventoryPlayer;
import common.item.ItemStack;
import common.network.Packet;
import common.packet.SPacketUpdateTileEntity;
import common.packet.SPacketUpdateDevice;
import common.rng.Random;
import common.tags.TagObject;
import java.util.List;
@ -326,7 +326,7 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo
public Packet getDescriptionPacket()
{
return new SPacketUpdateTileEntity(this);
return new SPacketUpdateDevice(this);
}
public int getColor() {

View file

@ -187,6 +187,10 @@ public abstract class Vars {
public static boolean itemFallDamage = true;
@Var(name = "signEditing")
public static boolean editSigns = true;
@Var(name = "daylightCycle")
public static boolean dayCycle = true;
@Var(name = "dropPlayerSkulls")
public static boolean skullDrop = true;
@Var(name = "keepInventory")
public static boolean keepInventory = false;
@ -255,7 +259,16 @@ public abstract class Vars {
public static int spawnMoreZombie = 25;
@Var(name = "explosionBlocksPerTick", min = 100, max = 100000)
public static int maxExplosionIters = 1024;
@Var(name = "viewDistance", min = 2, max = 16)
public static int distance = 8;
@Var(name = "timeFlow", min = 1)
public static int timeFlow = 1;
@Var(name = "gravity", min = -10.0f, max = 10.0f)
public static float gravity = 1.0f;
@Var(name = "knockback")
public static float knockback = 1.0f;
@Var(name = "baseSeed", nonDefault = true)
public static String seed = "";
}

View file

@ -38,6 +38,7 @@ import common.util.HitPosition;
import common.util.IntHashMap;
import common.util.ParticleType;
import common.util.Vec3;
import common.vars.Vars;
public abstract class World implements IWorldAccess {
public static final float[][] BRIGHTNESS = new float[16][16];
@ -60,7 +61,6 @@ public abstract class World implements IWorldAccess {
public final boolean client;
public double gravity = 1.0;
protected long timeFactor = 1L;
public final Random rand = new Random();
public final List<Entity> entities = Lists.<Entity>newArrayList();
protected final List<Entity> unloaded = Lists.<Entity>newArrayList();
@ -126,8 +126,8 @@ public abstract class World implements IWorldAccess {
this.weather = dim.getWeather();
}
public void setGravity(float gravity) {
this.gravity = (double)this.dimension.getGravity() * 0.1 * gravity;
public void updatePhysics() {
this.gravity = (double)this.dimension.getGravity() * 0.1 * Vars.gravity;
if(Math.abs(this.gravity) < 0.075)
this.gravity = Math.signum(this.gravity) * 0.075;
}
@ -902,15 +902,16 @@ public abstract class World implements IWorldAccess {
}
public float getCelestialAngle(float partialTicks) {
return !this.dimension.getType().days ? 0.5f : this.calculateCelestialAngle(this.daytime, partialTicks);
return !this.dimension.getType().days ? 0.5f : this.calculateCelestialAngle(this.daytime, Vars.dayCycle ? partialTicks : 0.0f);
}
public int getMoonPhase() {
return (int)(this.daytime / this.dimension.getRotationalPeriod() % 8L + 8L) % 8;
public int getMoonPhase(int moon) {
this.rand.setSeed((this.dimension.getSeed() + moon) ^ (moon << 12));
return (int)(this.daytime / this.dimension.getRotationalPeriod() % 8L + 8L + this.rand.zrange(8)) % 8;
}
public float getCurrentMoonPhaseFactor() {
return MOON_PHASES[this.getMoonPhase()];
return MOON_PHASES[this.getMoonPhase(0)];
}
public float getCelestialAngleRadians(float partialTicks) {
@ -1955,12 +1956,6 @@ public abstract class World implements IWorldAccess {
// return null;
// }
public void setTimeFactor(int factor) {
this.timeFactor = Math.max((long)factor, 1L);
// if(this.timeFactor > Constants.EARTH_DAY)
// this.timeFactor = (this.timeFactor - (this.timeFactor % Constants.EARTH_DAY)) + 1L;
}
public void setEntityState(Entity entityIn, byte state) {
}