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

@ -174,7 +174,9 @@ import common.util.Facing;
import common.util.HitPosition; import common.util.HitPosition;
import common.util.LazyLoader; import common.util.LazyLoader;
import common.util.Util; import common.util.Util;
import common.util.Var;
import common.util.HitPosition.ObjectType; import common.util.HitPosition.ObjectType;
import common.vars.Vars;
import common.world.LightType; import common.world.LightType;
import common.world.State; import common.world.State;
import common.world.World; import common.world.World;
@ -301,6 +303,7 @@ public class Client implements IThreadListener {
private final Map<Integer, Long> bars = Maps.newTreeMap(); private final Map<Integer, Long> bars = Maps.newTreeMap();
private final Thread clThread = Thread.currentThread(); private final Thread clThread = Thread.currentThread();
private final Map<String, CVar> cvars = Maps.newTreeMap(); private final Map<String, CVar> cvars = Maps.newTreeMap();
private final Map<String, Field> synced = Maps.newTreeMap();
private final Map<Keysym, DebugFunction> debug = Maps.newTreeMap(); private final Map<Keysym, DebugFunction> debug = Maps.newTreeMap();
private final List<Message> console = Lists.newArrayList(); private final List<Message> console = Lists.newArrayList();
private final List<Message> chat = Lists.newArrayList(); private final List<Message> chat = Lists.newArrayList();
@ -327,7 +330,6 @@ public class Client implements IThreadListener {
public boolean xrayActive; public boolean xrayActive;
public boolean tileOverlay; public boolean tileOverlay;
public boolean itemCheat; public boolean itemCheat;
public boolean dayCycle = true;
public boolean debugPlayer; public boolean debugPlayer;
public boolean cameraUsed; public boolean cameraUsed;
public boolean charEditor; public boolean charEditor;
@ -337,7 +339,6 @@ public class Client implements IThreadListener {
private int chunkLoadTimer; private int chunkLoadTimer;
public int thirdPersonView; public int thirdPersonView;
public int timeFactor = 1;
public int chunksUpdated; public int chunksUpdated;
public int selectedCharacter = -1; public int selectedCharacter = -1;
@ -350,7 +351,6 @@ public class Client implements IThreadListener {
public float moveStrafe; public float moveStrafe;
public float moveForward; public float moveForward;
public float zoomLevel; public float zoomLevel;
public float gravity = 1.0f;
private long tmr_timer; private long tmr_timer;
private long tmr_start; private long tmr_start;
@ -625,9 +625,6 @@ public class Client implements IThreadListener {
this.player.noclip = true; this.player.noclip = true;
this.player.addEffect(new StatusEffect(Effect.FLYING, Integer.MAX_VALUE, 1)); this.player.addEffect(new StatusEffect(Effect.FLYING, Integer.MAX_VALUE, 1));
this.player.setHeight(2.0f); this.player.setHeight(2.0f);
world.setGravity(this.gravity = 1.0f);
world.setTimeFactor(this.timeFactor = 1);
this.dayCycle = true;
} }
public void unloadWorld() { public void unloadWorld() {
@ -700,6 +697,19 @@ public class Client implements IThreadListener {
this.renderGlobal.onReload(); this.renderGlobal.onReload();
EntityTexManager.loadNpcTextures(); EntityTexManager.loadNpcTextures();
this.effectRenderer = new EffectRenderer(this.textureManager); this.effectRenderer = new EffectRenderer(this.textureManager);
for(Field field : Vars.class.getDeclaredFields()) {
if(field.isAnnotationPresent(Var.class)) {
if(!Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()))
throw new IllegalArgumentException("Feld für Variable " + field + " muss statisch und änderbar sein!");
Var value = field.getAnnotation(Var.class);
if(value.name().isEmpty())
throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!");
if(this.synced.containsKey(value.name()))
throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!");
this.synced.put(value.name(), field);
}
}
} }
public void start() public void start()
@ -1115,6 +1125,21 @@ public class Client implements IThreadListener {
// this.renderItem.renderItemOverlayIntoGUI(itemstack, xPos, 0, null); // this.renderItem.renderItemOverlayIntoGUI(itemstack, xPos, 0, null);
} }
} }
if(this.pointed != null && this.pointed.block != null) {
State state = this.world.getState(this.pointed.block);
if(state.getBlock() != Blocks.air) {
Item item = state.getBlock().getItem(this.world, this.pointed.block);
if(item != null) {
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef((float)(this.fb_x / 2 - 180 + 4 + 1), (float)(40 + 1), 0.0f);
GL11.glScalef(2.0f, 2.0f, 2.0f);
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(new ItemStack(item), 0, 0);
}
}
}
GL11.glPopMatrix(); GL11.glPopMatrix();
ItemRenderer.disableStandardItemLighting(); ItemRenderer.disableStandardItemLighting();
@ -1948,7 +1973,7 @@ public class Client implements IThreadListener {
this.world.getDarkness() this.world.getDarkness()
) + "\n" + ) + "\n" +
String.format("Zeitfaktor: %dx, Schwerkraft: %.2f m/s²", String.format("Zeitfaktor: %dx, Schwerkraft: %.2f m/s²",
this.timeFactor, this.world.gravity * 10.0 Vars.timeFlow, this.world.gravity * 10.0
) + "\n" + ) + "\n" +
String.format("Letzte Zeitsynch.: + %d.%d s", String.format("Letzte Zeitsynch.: + %d.%d s",
ticked / 1000L, (ticked / 100L) % 10L ticked / 1000L, (ticked / 100L) % 10L
@ -3508,4 +3533,29 @@ public class Client implements IThreadListener {
} }
}, "File Browser listener").start(); }, "File Browser listener").start();
} }
public Object getSyncedVar(String name) {
Field field = this.synced.get(name);
if(field != null) {
try {
return field.get(null);
}
catch(IllegalArgumentException | IllegalAccessException e) {
}
}
return null;
}
public void setSyncedVar(String name, Object value) {
Field field = this.synced.get(name);
if(field != null) {
try {
field.set(null, value);
}
catch(Throwable e) {
return;
}
Log.NETWORK.debug("Variable %s = %s", name, value);
}
}
} }

View file

@ -76,7 +76,7 @@ import common.packet.SPacketWindowItems;
import common.packet.SPacketWindowProperty; import common.packet.SPacketWindowProperty;
import common.packet.SPacketConfirmTransaction; import common.packet.SPacketConfirmTransaction;
import common.packet.SPacketUpdateSign; import common.packet.SPacketUpdateSign;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateDevice;
import common.packet.SPacketSignEditorOpen; import common.packet.SPacketSignEditorOpen;
import common.packet.SPacketPlayerListItem; import common.packet.SPacketPlayerListItem;
import common.packet.SPacketPlayerAbilities; import common.packet.SPacketPlayerAbilities;
@ -106,6 +106,7 @@ import common.packet.SPacketMessage;
import common.packet.SPacketMultiBlockChange; import common.packet.SPacketMultiBlockChange;
import common.packet.SPacketPlayerPosLook; import common.packet.SPacketPlayerPosLook;
import common.packet.SPacketRespawn; import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketServerTick; import common.packet.SPacketServerTick;
import common.packet.SPacketSetExperience; import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin; import common.packet.SPacketSkin;
@ -116,13 +117,13 @@ import common.packet.SPacketTimeUpdate;
import common.packet.SPacketTrades; import common.packet.SPacketTrades;
import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateDisplay;
import common.packet.SPacketUpdateHealth; import common.packet.SPacketUpdateHealth;
import common.packet.SPacketWorld;
import common.rng.Random; import common.rng.Random;
import common.sound.Sound; import common.sound.Sound;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.tileentity.TileEntityDevice; import common.tileentity.TileEntityDevice;
import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntityDisplay;
import common.tileentity.TileEntitySign; import common.tileentity.TileEntitySign;
import common.util.Pair;
import common.village.MerchantRecipeList; import common.village.MerchantRecipeList;
import common.world.Explosion; import common.world.Explosion;
import common.world.Weather; import common.world.Weather;
@ -215,6 +216,13 @@ public class ClientPlayer implements IClientPlayer
// this.gameController.confirmSkin(false); // this.gameController.confirmSkin(false);
} }
public void handleServerConfig(SPacketServerConfig packet) {
NetHandler.checkThread(packet, this, this.gm);
for(Pair<String, Object> var : packet.getValues()) {
this.gm.setSyncedVar(var.first(), var.second());
}
}
public void handleJoinGame(SPacketJoinGame packetIn) public void handleJoinGame(SPacketJoinGame packetIn)
{ {
NetHandler.checkThread(packetIn, this, this.gm); NetHandler.checkThread(packetIn, this, this.gm);
@ -1334,7 +1342,7 @@ public class ClientPlayer implements IClientPlayer
* Updates the metadata of instances of the following entitytypes: Mob spawners, command blocks, * Updates the metadata of instances of the following entitytypes: Mob spawners, command blocks,
* beacons, skulls, flowerpot * beacons, skulls, flowerpot
*/ */
public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn) public void handleUpdateTileEntity(SPacketUpdateDevice packetIn)
{ {
NetHandler.checkThread(packetIn, this, this.gm, this.world); NetHandler.checkThread(packetIn, this, this.gm, this.world);
@ -1904,14 +1912,6 @@ public class ClientPlayer implements IClientPlayer
} }
} }
public void handleWorld(SPacketWorld packetIn) {
NetHandler.checkThread(packetIn, this, this.gm, this.world);
this.world.setGravity(this.gm.gravity = packetIn.getGravity());
this.world.setTimeFactor(this.gm.timeFactor = packetIn.getTimeFactor());
// this.clientWorldController.setDifficulty(this.gameController.difficulty = packetIn.getDifficulty());
this.gm.dayCycle = packetIn.hasDayCycle();
}
public void handleDimName(SPacketDimensionName packetIn) { public void handleDimName(SPacketDimensionName packetIn) {
NetHandler.checkThread(packetIn, this, this.gm, this.world); NetHandler.checkThread(packetIn, this, this.gm, this.world);
if(this.world.dimension.isCustom()) { if(this.world.dimension.isCustom()) {

View file

@ -33,6 +33,7 @@ import common.block.tile.BlockSign;
import common.collect.Lists; import common.collect.Lists;
import common.collect.Maps; import common.collect.Maps;
import common.collect.Sets; import common.collect.Sets;
import common.dimension.DimType;
import common.entity.Entity; import common.entity.Entity;
import common.entity.npc.EntityNPC; import common.entity.npc.EntityNPC;
import common.entity.projectile.EntityBox; import common.entity.projectile.EntityBox;
@ -108,14 +109,16 @@ public class RenderGlobal
return this.time; return this.time;
} }
} }
private static final String MOON_TEX = "textures/world/moon_phases.png"; private static final String MOON_TEX = "textures/world/moon_phases.png";
private static final String PLANET_TEX = "textures/world/planet_phases.png";
private static final String SUN_TEX = "textures/world/sun.png"; private static final String SUN_TEX = "textures/world/sun.png";
private static final float[] SUN_COLOR = new float[4]; private static final float[] SUN_COLOR = new float[4];
private final Client gm; private final Client gm;
private final TextureManager renderEngine; private final TextureManager renderEngine;
private final RenderManager renderManager; private final RenderManager renderManager;
private final Random rand = new Random();
private WorldClient theWorld; private WorldClient theWorld;
private Set<RenderChunk> chunksToUpdate = new LinkedHashSet<RenderChunk>(); private Set<RenderChunk> chunksToUpdate = new LinkedHashSet<RenderChunk>();
private List<RenderGlobal.ContainerLocalRenderInformation> renderInfos = new ArrayList<ContainerLocalRenderInformation>(69696); private List<RenderGlobal.ContainerLocalRenderInformation> renderInfos = new ArrayList<ContainerLocalRenderInformation>(69696);
@ -1242,35 +1245,47 @@ public class RenderGlobal
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO); GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO);
GL11.glPushMatrix(); GL11.glPushMatrix();
float f16 = 1.0F - Math.max(this.theWorld.getRainStrength(), this.theWorld.getFogStrength()); float f16 = 1.0F - Math.max(this.theWorld.getRainStrength(), this.theWorld.getFogStrength());
GlState.color(1.0F, 1.0F, 1.0F, f16);
GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(this.theWorld.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F); GL11.glRotatef(this.theWorld.getCelestialAngle(partialTicks) * 360.0F, 1.0F, 0.0F, 0.0F);
if(this.gm.world.dimension.getType().sun) { if(this.gm.world.dimension.getType().celestials) {
float size = 30.0F; float size = 30.0F;
this.renderEngine.bindTexture(SUN_TEX); this.renderEngine.bindTexture(SUN_TEX);
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); int color = this.gm.world.dimension.getSunColor();
worldrenderer.pos((double)(-size), 100.0D, (double)(-size)).tex(0.0D, 0.0D).endVertex(); if(color != 0xffffffff) {
worldrenderer.pos((double)size, 100.0D, (double)(-size)).tex(1.0D, 0.0D).endVertex(); Vec3 ncolor = new Vec3(color).normalize();
worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex(); GlState.color((float)ncolor.xCoord, (float)ncolor.yCoord, (float)ncolor.zCoord, f16);
worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex(); worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
Tessellator.draw(); worldrenderer.pos((double)(-size), 100.0D, (double)(-size)).tex(0.0D, 0.0D).endVertex();
} worldrenderer.pos((double)size, 100.0D, (double)(-size)).tex(1.0D, 0.0D).endVertex();
if(this.gm.world.dimension.getType().moon) { worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex();
float size = 20.0F; worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex();
this.renderEngine.bindTexture(MOON_TEX); Tessellator.draw();
int i = this.theWorld.getMoonPhase(); }
int k = i % 4; size = 20.0F;
int i1 = i / 4 % 2; this.renderEngine.bindTexture(this.gm.world.dimension.getType() == DimType.MOON ? PLANET_TEX : MOON_TEX);
float f22 = (float)(k + 0) / 4.0F; int[] colors = this.gm.world.dimension.getMoonColors();
float f23 = (float)(i1 + 0) / 2.0F; this.rand.setSeed(this.gm.world.dimension.getSeed());
float f24 = (float)(k + 1) / 4.0F; int mx = 0;
float f14 = (float)(i1 + 1) / 2.0F; int mz = 0;
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); for(int z = 0; z < colors.length; z++) {
worldrenderer.pos((double)(-size), -100.0D, (double)size).tex((double)f24, (double)f14).endVertex(); Vec3 ncolor = new Vec3(colors[z]).normalize();
worldrenderer.pos((double)size, -100.0D, (double)size).tex((double)f22, (double)f14).endVertex(); GlState.color((float)ncolor.xCoord, (float)ncolor.yCoord, (float)ncolor.zCoord, f16);
worldrenderer.pos((double)size, -100.0D, (double)(-size)).tex((double)f22, (double)f23).endVertex(); int i = this.theWorld.getMoonPhase(z);
worldrenderer.pos((double)(-size), -100.0D, (double)(-size)).tex((double)f24, (double)f23).endVertex(); int k = i % 4;
Tessellator.draw(); int i1 = i / 4 % 2;
float f22 = (float)(k + 0) / 4.0F;
float f23 = (float)(i1 + 0) / 2.0F;
float f24 = (float)(k + 1) / 4.0F;
float f14 = (float)(i1 + 1) / 2.0F;
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldrenderer.pos((double)(-size + mx), -100.0D, (double)(size + mz)).tex((double)f24, (double)f14).endVertex();
worldrenderer.pos((double)(size + mx), -100.0D, (double)(size + mz)).tex((double)f22, (double)f14).endVertex();
worldrenderer.pos((double)(size + mx), -100.0D, (double)(-size + mz)).tex((double)f22, (double)f23).endVertex();
worldrenderer.pos((double)(-size + mx), -100.0D, (double)(-size + mz)).tex((double)f24, (double)f23).endVertex();
Tessellator.draw();
mx = this.rand.range(-100, 100);
mz = this.rand.range(-100, 100);
}
} }
GlState.disableTexture2D(); GlState.disableTexture2D();

View file

@ -28,6 +28,7 @@ import common.util.ExtMath;
import common.util.LongHashMap; import common.util.LongHashMap;
import common.util.ParticleType; import common.util.ParticleType;
import common.util.Vec3; import common.util.Vec3;
import common.vars.Vars;
import common.util.BlockPos.MutableBlockPos; import common.util.BlockPos.MutableBlockPos;
import common.world.AWorldClient; import common.world.AWorldClient;
import common.world.State; import common.world.State;
@ -57,8 +58,7 @@ public class WorldClient extends AWorldClient
this.emptyChunk = new ChunkEmpty(this, this.gm.debugWorld); this.emptyChunk = new ChunkEmpty(this, this.gm.debugWorld);
this.calculateInitialSkylight(); this.calculateInitialSkylight();
this.calculateInitialWeather(); this.calculateInitialWeather();
this.setGravity(this.gm.gravity); this.updatePhysics();
this.setTimeFactor(this.gm.timeFactor);
// this.setDifficulty(this.gm.difficulty); // this.setDifficulty(this.gm.difficulty);
} }
@ -97,12 +97,13 @@ public class WorldClient extends AWorldClient
public void tick() public void tick()
{ {
this.updatePhysics();
this.markReload(); this.markReload();
// this.info.tick(); // this.info.tick();
if (this.gm.dayCycle) if (Vars.dayCycle)
{ {
this.daytime += this.timeFactor; this.daytime += Vars.timeFlow;
} }
for (int i = 0; i < 10 && !this.spawnQueue.isEmpty(); ++i) for (int i = 0; i < 10 && !this.spawnQueue.isEmpty(); ++i)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

View file

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

View file

@ -159,6 +159,8 @@ public abstract class Dimension extends Nameable {
private ColorGenerator starColorFunc = null; private ColorGenerator starColorFunc = null;
private ColorGenerator deepstarColorFunc = null; private ColorGenerator deepstarColorFunc = null;
private String display; // synced only private String display; // synced only
private int sunColor = 0xffffffff;
private int[] moonColors = null;
// common // common
private float gravity = 1.0f; private float gravity = 1.0f;
@ -739,6 +741,31 @@ public abstract class Dimension extends Nameable {
public final boolean hasDenseFog() { public final boolean hasDenseFog() {
return this.denseFog; 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() { public final State getFiller() {

View file

@ -1,5 +1,7 @@
package common.dimension; package common.dimension;
import common.init.UniverseRegistry;
public final class Moon extends Dimension { public final class Moon extends Dimension {
Moon() { Moon() {
super(true); super(true);
@ -16,4 +18,17 @@ public final class Moon extends Dimension {
public final DimType getType() { public final DimType getType() {
return DimType.MOON; 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; package common.dimension;
import java.util.Set; import java.util.List;
import common.collect.Lists;
import common.collect.Sets; import common.init.UniverseRegistry;
public final class Planet extends Dimension { public final class Planet extends Dimension {
private final Set<Moon> moons = Sets.newHashSet(); private final List<Moon> moons = Lists.newArrayList();
Planet() { Planet() {
super(true); super(true);
@ -41,4 +41,17 @@ public final class Planet extends Dimension {
public final DimType getType() { public final DimType getType() {
return DimType.PLANET; 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); 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) { public static Dimension getDimension(String name) {
return NAME_MAP.get(name); return NAME_MAP.get(name);
} }

View file

@ -22,7 +22,7 @@ import common.packet.SPacketWindowItems;
import common.packet.SPacketWindowProperty; import common.packet.SPacketWindowProperty;
import common.packet.SPacketConfirmTransaction; import common.packet.SPacketConfirmTransaction;
import common.packet.SPacketUpdateSign; import common.packet.SPacketUpdateSign;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateDevice;
import common.packet.SPacketSignEditorOpen; import common.packet.SPacketSignEditorOpen;
import common.packet.SPacketPlayerListItem; import common.packet.SPacketPlayerListItem;
import common.packet.SPacketPlayerAbilities; import common.packet.SPacketPlayerAbilities;
@ -52,6 +52,7 @@ import common.packet.SPacketMessage;
import common.packet.SPacketMultiBlockChange; import common.packet.SPacketMultiBlockChange;
import common.packet.SPacketPlayerPosLook; import common.packet.SPacketPlayerPosLook;
import common.packet.SPacketRespawn; import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketServerTick; import common.packet.SPacketServerTick;
import common.packet.SPacketSetExperience; import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin; import common.packet.SPacketSkin;
@ -62,7 +63,6 @@ import common.packet.SPacketTimeUpdate;
import common.packet.SPacketTrades; import common.packet.SPacketTrades;
import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateDisplay;
import common.packet.SPacketUpdateHealth; import common.packet.SPacketUpdateHealth;
import common.packet.SPacketWorld;
import common.sound.Sound; import common.sound.Sound;
public interface IClientPlayer extends NetHandler { public interface IClientPlayer extends NetHandler {
@ -116,7 +116,7 @@ public interface IClientPlayer extends NetHandler {
void handleSignEditorOpen(SPacketSignEditorOpen packet); void handleSignEditorOpen(SPacketSignEditorOpen packet);
void handleUpdateSign(SPacketUpdateSign packet); void handleUpdateSign(SPacketUpdateSign packet);
void handleUpdateDisplay(SPacketUpdateDisplay packet); void handleUpdateDisplay(SPacketUpdateDisplay packet);
void handleUpdateTileEntity(SPacketUpdateTileEntity packet); void handleUpdateTileEntity(SPacketUpdateDevice packet);
void handleWindowProperty(SPacketWindowProperty packet); void handleWindowProperty(SPacketWindowProperty packet);
void handleEntityEquipment(SPacketEntityEquipment packet); void handleEntityEquipment(SPacketEntityEquipment packet);
void handleCloseWindow(SPacketCloseWindow packet); void handleCloseWindow(SPacketCloseWindow packet);
@ -138,7 +138,7 @@ public interface IClientPlayer extends NetHandler {
void handleParticles(SPacketParticles packet); void handleParticles(SPacketParticles packet);
void handleSkin(SPacketSkin packet); void handleSkin(SPacketSkin packet);
void handleTrades(SPacketTrades packet); void handleTrades(SPacketTrades packet);
void handleWorld(SPacketWorld packet);
void handleDimName(SPacketDimensionName packet); void handleDimName(SPacketDimensionName packet);
void handleForm(SPacketDisplayForm 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.SPacketWindowProperty;
import common.packet.SPacketConfirmTransaction; import common.packet.SPacketConfirmTransaction;
import common.packet.SPacketUpdateSign; import common.packet.SPacketUpdateSign;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateDevice;
import common.packet.SPacketSignEditorOpen; import common.packet.SPacketSignEditorOpen;
import common.packet.SPacketPlayerListItem; import common.packet.SPacketPlayerListItem;
import common.packet.SPacketPlayerAbilities; import common.packet.SPacketPlayerAbilities;
@ -89,6 +89,7 @@ import common.packet.SPacketMessage;
import common.packet.SPacketMultiBlockChange; import common.packet.SPacketMultiBlockChange;
import common.packet.SPacketPlayerPosLook; import common.packet.SPacketPlayerPosLook;
import common.packet.SPacketRespawn; import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketServerTick; import common.packet.SPacketServerTick;
import common.packet.SPacketSetExperience; import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin; import common.packet.SPacketSkin;
@ -99,7 +100,6 @@ import common.packet.SPacketTimeUpdate;
import common.packet.SPacketTrades; import common.packet.SPacketTrades;
import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateDisplay;
import common.packet.SPacketUpdateHealth; import common.packet.SPacketUpdateHealth;
import common.packet.SPacketWorld;
public enum PacketRegistry { public enum PacketRegistry {
HANDSHAKE {{ HANDSHAKE {{
@ -169,14 +169,13 @@ public enum PacketRegistry {
this.server(SPacketConfirmTransaction.class); this.server(SPacketConfirmTransaction.class);
this.server(SPacketUpdateSign.class); this.server(SPacketUpdateSign.class);
this.server(SPacketUpdateDisplay.class); this.server(SPacketUpdateDisplay.class);
this.server(SPacketUpdateTileEntity.class); this.server(SPacketUpdateDevice.class);
this.server(SPacketSignEditorOpen.class); this.server(SPacketSignEditorOpen.class);
this.server(SPacketPlayerListItem.class); this.server(SPacketPlayerListItem.class);
this.server(SPacketPlayerAbilities.class); this.server(SPacketPlayerAbilities.class);
this.server(SPacketTabComplete.class); this.server(SPacketTabComplete.class);
this.server(SPacketSkin.class); this.server(SPacketSkin.class);
this.server(SPacketDisconnect.class); this.server(SPacketDisconnect.class);
this.server(SPacketWorld.class);
this.server(SPacketCamera.class); this.server(SPacketCamera.class);
this.server(SPacketBiome.class); this.server(SPacketBiome.class);
this.server(SPacketUpdateEntityTags.class); this.server(SPacketUpdateEntityTags.class);
@ -186,6 +185,7 @@ public enum PacketRegistry {
this.server(SPacketServerTick.class); this.server(SPacketServerTick.class);
this.server(SPacketLoading.class); this.server(SPacketLoading.class);
this.server(SPacketDisplayForm.class); this.server(SPacketDisplayForm.class);
this.server(SPacketServerConfig.class);
this.client(CPacketKeepAlive.class); this.client(CPacketKeepAlive.class);
this.client(CPacketMessage.class); this.client(CPacketMessage.class);

View file

@ -18,6 +18,8 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
private String dimName; private String dimName;
private String dimDisplay; private String dimDisplay;
private String dimFull; private String dimFull;
private int sunColor;
private int[] moonColors;
private int type; private int type;
private boolean editor; private boolean editor;
@ -37,6 +39,10 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
this.dimName = UniverseRegistry.getName(dim); this.dimName = UniverseRegistry.getName(dim);
this.dimDisplay = dim.getCustomName(); this.dimDisplay = dim.getCustomName();
this.dimFull = dim.getFormattedName(true); this.dimFull = dim.getFormattedName(true);
if(this.dimType.celestials) {
this.sunColor = dim.getSunColor();
this.moonColors = dim.getMoonColors();
}
this.dimId = -1; this.dimId = -1;
} }
else { else {
@ -61,6 +67,13 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
this.dimName = buf.readString(1024); this.dimName = buf.readString(1024);
this.dimDisplay = buf.readString(1024); this.dimDisplay = buf.readString(1024);
this.dimFull = buf.readString(4096); 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.type = buf.readUnsignedShort();
this.editor = buf.readBoolean(); this.editor = buf.readBoolean();
@ -76,6 +89,13 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
buf.writeString(this.dimName); buf.writeString(this.dimName);
buf.writeString(this.dimDisplay); buf.writeString(this.dimDisplay);
buf.writeString(this.dimFull); 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.writeShort(this.type & 65535);
buf.writeBoolean(this.editor); buf.writeBoolean(this.editor);
@ -91,6 +111,10 @@ public class SPacketRespawn implements Packet<IClientPlayer> {
dim.fromTags(this.dimData); dim.fromTags(this.dimData);
dim.setCustomName(this.dimDisplay); dim.setCustomName(this.dimDisplay);
dim.setDisplayName(this.dimFull); dim.setDisplayName(this.dimFull);
if(this.dimType.celestials) {
dim.setSunColor(this.sunColor);
dim.setMoonColors(this.moonColors);
}
return dim; 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.util.BlockPos;
import common.world.State; import common.world.State;
public class SPacketUpdateTileEntity implements Packet<IClientPlayer> public class SPacketUpdateDevice implements Packet<IClientPlayer>
{ {
private BlockPos blockPos; private BlockPos blockPos;
private Block type; private Block type;
private TagObject tag; private TagObject tag;
public SPacketUpdateTileEntity() public SPacketUpdateDevice()
{ {
} }
public SPacketUpdateTileEntity(TileEntity tile) public SPacketUpdateDevice(TileEntity tile)
{ {
this.blockPos = tile.getPos(); this.blockPos = tile.getPos();
this.type = tile.getBlockType(); 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.inventory.InventoryPlayer;
import common.item.ItemStack; import common.item.ItemStack;
import common.network.Packet; import common.network.Packet;
import common.packet.SPacketUpdateTileEntity; import common.packet.SPacketUpdateDevice;
import common.rng.Random; import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import java.util.List; import java.util.List;
@ -326,7 +326,7 @@ public abstract class TileEntityDevice extends TileEntityLockable implements IHo
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
return new SPacketUpdateTileEntity(this); return new SPacketUpdateDevice(this);
} }
public int getColor() { public int getColor() {

View file

@ -187,6 +187,10 @@ public abstract class Vars {
public static boolean itemFallDamage = true; public static boolean itemFallDamage = 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")
public static boolean skullDrop = true;
@Var(name = "keepInventory") @Var(name = "keepInventory")
public static boolean keepInventory = false; public static boolean keepInventory = false;
@ -255,7 +259,16 @@ public abstract class Vars {
public static int spawnMoreZombie = 25; public static int spawnMoreZombie = 25;
@Var(name = "explosionBlocksPerTick", min = 100, max = 100000) @Var(name = "explosionBlocksPerTick", min = 100, max = 100000)
public static int maxExplosionIters = 1024; 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") @Var(name = "knockback")
public static float knockback = 1.0f; 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.IntHashMap;
import common.util.ParticleType; import common.util.ParticleType;
import common.util.Vec3; import common.util.Vec3;
import common.vars.Vars;
public abstract class World implements IWorldAccess { public abstract class World implements IWorldAccess {
public static final float[][] BRIGHTNESS = new float[16][16]; public static final float[][] BRIGHTNESS = new float[16][16];
@ -60,7 +61,6 @@ public abstract class World implements IWorldAccess {
public final boolean client; public final boolean client;
public double gravity = 1.0; public double gravity = 1.0;
protected long timeFactor = 1L;
public final Random rand = new Random(); public final Random rand = new Random();
public final List<Entity> entities = Lists.<Entity>newArrayList(); public final List<Entity> entities = Lists.<Entity>newArrayList();
protected final List<Entity> unloaded = 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(); this.weather = dim.getWeather();
} }
public void setGravity(float gravity) { public void updatePhysics() {
this.gravity = (double)this.dimension.getGravity() * 0.1 * gravity; this.gravity = (double)this.dimension.getGravity() * 0.1 * Vars.gravity;
if(Math.abs(this.gravity) < 0.075) if(Math.abs(this.gravity) < 0.075)
this.gravity = Math.signum(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) { 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() { public int getMoonPhase(int moon) {
return (int)(this.daytime / this.dimension.getRotationalPeriod() % 8L + 8L) % 8; 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() { public float getCurrentMoonPhaseFactor() {
return MOON_PHASES[this.getMoonPhase()]; return MOON_PHASES[this.getMoonPhase(0)];
} }
public float getCelestialAngleRadians(float partialTicks) { public float getCelestialAngleRadians(float partialTicks) {
@ -1955,12 +1956,6 @@ public abstract class World implements IWorldAccess {
// return null; // 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) { public void setEntityState(Entity entityIn, byte state) {
} }

View file

@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -77,15 +78,16 @@ import common.packet.SPacketDisconnect;
import common.packet.SPacketHeldItemChange; import common.packet.SPacketHeldItemChange;
import common.packet.SPacketJoinGame; import common.packet.SPacketJoinGame;
import common.packet.SPacketRespawn; import common.packet.SPacketRespawn;
import common.packet.SPacketServerConfig;
import common.packet.SPacketSetExperience; import common.packet.SPacketSetExperience;
import common.packet.SPacketSkin; import common.packet.SPacketSkin;
import common.packet.SPacketTimeUpdate; import common.packet.SPacketTimeUpdate;
import common.packet.SPacketWorld;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.EncryptUtil; import common.util.EncryptUtil;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.LazyLoader; import common.util.LazyLoader;
import common.util.Pair;
import common.util.PortalType; import common.util.PortalType;
import common.util.Position; import common.util.Position;
import common.util.Util; import common.util.Util;
@ -274,18 +276,10 @@ public final class Server implements IThreadListener, Executor {
throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!"); throw new IllegalArgumentException("Variablenname von " + field + " kann nicht leer sein!");
if(this.variables.containsKey(value.name())) if(this.variables.containsKey(value.name()))
throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!"); throw new IllegalArgumentException("Variable " + value.name() + " existiert bereits!");
this.variables.put(value.name(), new SVar(field, value)); this.variables.put(value.name(), new SVar(field, value, clazz == Vars.class));
} }
} }
} }
this.setCallback(new Runnable() {
public void run() {
for(WorldServer world : Server.this.getWorlds()) {
world.updatePhysics();
}
Server.this.sendPacket(new SPacketWorld(WorldServer.clampGravity(), SVars.dayCycle, SVars.timeFlow));
}
}, "daylightCycle", "timeFlow", "gravity");
this.setCallback(new Runnable() { this.setCallback(new Runnable() {
public void run() { public void run() {
for(WorldServer world : Server.this.getWorlds()) { for(WorldServer world : Server.this.getWorlds()) {
@ -495,14 +489,14 @@ public final class Server implements IThreadListener, Executor {
public void preload(WorldServer world, int bx, int bz) { public void preload(WorldServer world, int bx, int bz) {
int done = 0; int done = 0;
int total = SVars.distance * 2 + 1; int total = Vars.distance * 2 + 1;
total *= total; total *= total;
Log.TICK.info("Generiere und lade Welt"); Log.TICK.info("Generiere und lade Welt");
bx = bx >> 4; bx = bx >> 4;
bz = bz >> 4; bz = bz >> 4;
long last = System.currentTimeMillis(); long last = System.currentTimeMillis();
for(int x = -SVars.distance; x <= SVars.distance; x++) { for(int x = -Vars.distance; x <= Vars.distance; x++) {
for(int z = -SVars.distance; z <= SVars.distance; z++) { for(int z = -Vars.distance; z <= Vars.distance; z++) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if(time - last > 1000L) { if(time - last > 1000L) {
Log.TICK.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%"); Log.TICK.info("Bereite Spawnbereich vor" + ": " + (done * 100 / total) + "%");
@ -739,10 +733,14 @@ public final class Server implements IThreadListener, Executor {
+ player.getId() + " auf " + UniverseRegistry.getName(world.dimension) + ": " + player.getId() + " auf " + UniverseRegistry.getName(world.dimension) + ": "
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? "Charakter-Editor" : "'" + player.getCommandName() + "'") + ")"); + String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? "Charakter-Editor" : "'" + player.getCommandName() + "'") + ")");
List<Pair<String, Object>> vars = Lists.newArrayList();
for(Entry<String, SVar> var : this.variables.entrySet()) {
if(var.getValue().sync)
vars.add(new Pair(var.getKey(), var.getValue().getRaw()));
}
conn.sendPacket(new SPacketServerConfig(vars));
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null)); conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
SVars.dayCycle, SVars.timeFlow));
this.sendPacket(new SPacketPlayerListItem(false, conn)); this.sendPacket(new SPacketPlayerListItem(false, conn));
world.spawnEntityInWorld(player); world.spawnEntityInWorld(player);

View file

@ -5,6 +5,7 @@ import java.util.Map.Entry;
import common.collect.Lists; import common.collect.Lists;
import common.color.TextColor; import common.color.TextColor;
import common.packet.SPacketServerConfig;
import server.command.ArgumentSplitter; import server.command.ArgumentSplitter;
import server.command.Command; import server.command.Command;
import server.command.CommandEnvironment; import server.command.CommandEnvironment;
@ -93,6 +94,8 @@ public class CommandSv extends Command {
} }
} }
sv.set(value, false, true); sv.set(value, false, true);
if(sv.sync)
env.getServer().sendPacket(new SPacketServerConfig(variable, sv.getRaw()));
} }
exec.log(this.formatVariable(variable, sv, value == null ? "=" : "->", false)); exec.log(this.formatVariable(variable, sv, value == null ? "=" : "->", false));
return sv.noDef && sv.def.equals(sv.get()) ? null : sv.get(); return sv.noDef && sv.def.equals(sv.get()) ? null : sv.get();

View file

@ -116,6 +116,7 @@ import common.util.PortalType;
import common.util.Position; import common.util.Position;
import common.util.Vec3i; import common.util.Vec3i;
import common.util.WorldPos; import common.util.WorldPos;
import common.vars.Vars;
import common.village.MerchantRecipeList; import common.village.MerchantRecipeList;
import common.world.BlockArray; import common.world.BlockArray;
import common.world.State; import common.world.State;
@ -281,11 +282,11 @@ public class Player extends User implements Executor, IPlayer
this.deathPos = this.entity.getPos(); this.deathPos = this.entity.getPos();
this.entity.sendDeathMessage(); this.entity.sendDeathMessage();
if (!SVars.keepInventory && SVars.playerDrop) if (!Vars.keepInventory && Vars.playerDrop)
{ {
this.entity.inventory.dropAllItems(); this.entity.inventory.dropAllItems();
} }
if(SVars.skullDrop) { if(Vars.skullDrop) {
ItemStack stack = new ItemStack(Items.skull); ItemStack stack = new ItemStack(Items.skull);
this.entity.dropItem(stack, true, false); this.entity.dropItem(stack, true, false);
} }
@ -466,7 +467,7 @@ public class Player extends User implements Executor, IPlayer
{ {
this.lastExperience = -1; this.lastExperience = -1;
this.lastHealth = -1.0F; this.lastHealth = -1.0F;
if(SVars.keepInventory) if(Vars.keepInventory)
this.entity.inventory.copyInventory(oldPlayer.inventory); this.entity.inventory.copyInventory(oldPlayer.inventory);
this.entity.experienceLevel = oldPlayer.experienceLevel; this.entity.experienceLevel = oldPlayer.experienceLevel;
this.entity.experienceTotal = oldPlayer.experienceTotal; this.entity.experienceTotal = oldPlayer.experienceTotal;

View file

@ -9,18 +9,20 @@ public class SVar {
public final ValueType type; public final ValueType type;
public final String def; public final String def;
public final boolean noDef; public final boolean noDef;
public final boolean sync;
private final Field field; private final Field field;
private final float min; private final float min;
private final float max; private final float max;
private Runnable callback; private Runnable callback;
public SVar(Field field, Var value) { public SVar(Field field, Var value, boolean sync) {
this.type = field.getType() == int.class ? ValueType.INTEGER : (field.getType() == boolean.class ? ValueType.BOOLEAN : this.type = field.getType() == int.class ? ValueType.INTEGER : (field.getType() == boolean.class ? ValueType.BOOLEAN :
(field.getType() == String.class ? ValueType.STRING : (field.getType() == float.class ? ValueType.FLOAT : null))); (field.getType() == String.class ? ValueType.STRING : (field.getType() == float.class ? ValueType.FLOAT : null)));
if(this.type == null) if(this.type == null)
throw new IllegalArgumentException(value.name() + ": Unbekannter Variablen-Typ - " + field.getType()); throw new IllegalArgumentException(value.name() + ": Unbekannter Variablen-Typ - " + field.getType());
this.field = field; this.field = field;
this.sync = sync;
this.def = this.get(); this.def = this.get();
this.noDef = value.nonDefault(); this.noDef = value.nonDefault();
this.min = (this.type == ValueType.INTEGER || this.type == ValueType.FLOAT) this.min = (this.type == ValueType.INTEGER || this.type == ValueType.FLOAT)
@ -39,6 +41,15 @@ public class SVar {
} }
} }
public Object getRaw() {
try {
return this.field.get(null);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public void setCallback(Runnable callback) { public void setCallback(Runnable callback) {
this.callback = callback; this.callback = callback;
} }

View file

@ -1,9 +1,8 @@
package server.vars; package server.vars;
import common.util.Var; import common.util.Var;
import common.vars.Vars;
public abstract class SVars extends Vars { public abstract class SVars {
@Var(name = "tickSpawning") @Var(name = "tickSpawning")
public static boolean tickSpawn = true; public static boolean tickSpawn = true;
@Var(name = "genSpawning") @Var(name = "genSpawning")
@ -20,10 +19,6 @@ public abstract class SVars extends Vars {
public static boolean spawnStrongholdMobs = true; public static boolean spawnStrongholdMobs = true;
@Var(name = "spawnHutMages") @Var(name = "spawnHutMages")
public static boolean spawnHutMage = true; public static boolean spawnHutMage = true;
@Var(name = "daylightCycle")
public static boolean dayCycle = true;
@Var(name = "dropPlayerSkulls")
public static boolean skullDrop = true;
@Var(name = "checkRespawn") @Var(name = "checkRespawn")
public static boolean checkBed = true; public static boolean checkBed = true;
@Var(name = "registration") @Var(name = "registration")
@ -70,14 +65,10 @@ public abstract class SVars extends Vars {
public static int playerLimit = 0; public static int playerLimit = 0;
@Var(name = "compressAbove") @Var(name = "compressAbove")
public static int compression = 256; public static int compression = 256;
@Var(name = "timeFlow")
public static int timeFlow = 1;
@Var(name = "emptyTicks") @Var(name = "emptyTicks")
public static int unloadTicks = 1200; public static int unloadTicks = 1200;
@Var(name = "weatherChance") @Var(name = "weatherChance")
public static int weatherChance = 48000; public static int weatherChance = 48000;
@Var(name = "viewDistance", min = 2, max = 16)
public static int distance = 8;
@Var(name = "maxSpawns") @Var(name = "maxSpawns")
public static int maxMobs = 120; public static int maxMobs = 120;
@Var(name = "connectionTimeout", min = 10, max = 300) @Var(name = "connectionTimeout", min = 10, max = 300)
@ -89,11 +80,6 @@ public abstract class SVars extends Vars {
@Var(name = "spawnDungeonMobs") @Var(name = "spawnDungeonMobs")
public static int spawnDungeonMobs = 4; public static int spawnDungeonMobs = 4;
@Var(name = "gravity")
public static float gravity = 1.0f;
@Var(name = "password", nonDefault = true) @Var(name = "password", nonDefault = true)
public static String password = ""; public static String password = "";
@Var(name = "baseSeed", nonDefault = true)
public static String seed = "";
} }

View file

@ -67,6 +67,7 @@ import common.util.ParticleType;
import common.util.PortalType; import common.util.PortalType;
import common.util.Position; import common.util.Position;
import common.util.Vec3; import common.util.Vec3;
import common.vars.Vars;
import common.village.Village; import common.village.Village;
import common.world.BlockArray; import common.world.BlockArray;
import common.world.Explosion; import common.world.Explosion;
@ -181,7 +182,7 @@ public final class WorldServer extends AWorldServer {
private long time; private long time;
public static float clampGravity() { public static float clampGravity() {
return ExtMath.clampf(SVars.gravity, -10.0f, 10.0f); return ExtMath.clampf(Vars.gravity, -10.0f, 10.0f);
} }
public void sendPacket(Packet packet) { public void sendPacket(Packet packet) {
@ -317,8 +318,8 @@ public final class WorldServer extends AWorldServer {
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();
if(!SVars.seed.isEmpty()) if(!Vars.seed.isEmpty())
this.rand.setSeed((long)SVars.seed.hashCode() ^ ~((long)UniverseRegistry.getName(dim).hashCode())); this.rand.setSeed((long)Vars.seed.hashCode() ^ ~((long)UniverseRegistry.getName(dim).hashCode()));
this.seed = this.rand.longv(); this.seed = this.rand.longv();
this.dimension.setSeed(this.seed); this.dimension.setSeed(this.seed);
TagObject tag = null; TagObject tag = null;
@ -348,7 +349,7 @@ public final class WorldServer extends AWorldServer {
// ... // ...
} }
else { else {
Log.TICK.info("Startwert für %s: %d" + (SVars.seed.isEmpty() ? "" : " von Basiswert '%s'"), this.dimension.getFormattedName(false), this.seed, SVars.seed); Log.TICK.info("Startwert für %s: %d" + (Vars.seed.isEmpty() ? "" : " von Basiswert '%s'"), this.dimension.getFormattedName(false), this.seed, Vars.seed);
} }
if(this.exterminated) if(this.exterminated)
this.weather = Weather.CLEAR; this.weather = Weather.CLEAR;
@ -379,17 +380,13 @@ public final class WorldServer extends AWorldServer {
public Server getServer() { public Server getServer() {
return this.server; return this.server;
} }
public void updatePhysics() {
this.setTimeFactor(SVars.timeFlow);
this.setGravity(clampGravity());
}
public void tick() { public void tick() {
this.updatePhysics();
this.updateWeather(false); this.updateWeather(false);
this.biomeGen.cleanupCache(); this.biomeGen.cleanupCache();
// this.profiler.start("mobSpawner"); // this.profiler.start("mobSpawner");
if(this.mobs && SVars.mobs && SVars.tickSpawn) { if(this.mobs && Vars.mobs && SVars.tickSpawn) {
Spawner.spawn(this); Spawner.spawn(this);
} }
// this.profiler.next("chunkSource"); // this.profiler.next("chunkSource");
@ -413,8 +410,8 @@ public final class WorldServer extends AWorldServer {
// this.info.tick(); // this.info.tick();
this.time += 1L; this.time += 1L;
// this.dataModified = true; // this.dataModified = true;
if(SVars.dayCycle) // { if(Vars.dayCycle) // {
this.daytime += this.timeFactor; this.daytime += Vars.timeFlow;
// if(this.dimension.getType().dayCycle) // if(this.dimension.getType().dayCycle)
// this.season = this.getSeasonByTime(); // this.season = this.getSeasonByTime();
// } // }
@ -520,7 +517,7 @@ public final class WorldServer extends AWorldServer {
} }
protected void updateBlocks() { protected void updateBlocks() {
this.setActivePlayerChunksAndCheckLight(SVars.distance); this.setActivePlayerChunksAndCheckLight(Vars.distance);
int dtics = 0; int dtics = 0;
int rtics = 0; int rtics = 0;
@ -574,7 +571,7 @@ public final class WorldServer extends AWorldServer {
this.getState(blockpos1).getBlock().fillWithRain(this, blockpos1); this.getState(blockpos1).getBlock().fillWithRain(this, blockpos1);
} }
if(SVars.igniteChance > 0 && SVars.fire && !this.isRaining() && if(SVars.igniteChance > 0 && Vars.fire && !this.isRaining() &&
this.rand.chance(this.hasDownfall() ? Math.max(1, SVars.igniteChance / 3) : SVars.igniteChance) this.rand.chance(this.hasDownfall() ? Math.max(1, SVars.igniteChance / 3) : SVars.igniteChance)
&& this.canPlaceFireAt(blockpos2)) { && this.canPlaceFireAt(blockpos2)) {
this.setState(blockpos2, Blocks.fire.getState()); this.setState(blockpos2, Blocks.fire.getState());
@ -1006,7 +1003,7 @@ public final class WorldServer extends AWorldServer {
this.effects.add(entity); this.effects.add(entity);
this.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D, this.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D,
new SPacketSpawnGlobalEntity(entity, 1, entity.color)); new SPacketSpawnGlobalEntity(entity, 1, entity.color));
if(fire && SVars.fire) { if(fire && Vars.fire) {
BlockPos pos = new BlockPos(entity); BlockPos pos = new BlockPos(entity);
if(this.isAreaLoaded(pos, 10)) { if(this.isAreaLoaded(pos, 10)) {
if(this.getState(pos).getBlock() == Blocks.air && Blocks.fire.canPlaceBlockAt(this, pos)) if(this.getState(pos).getBlock() == Blocks.air && Blocks.fire.canPlaceBlockAt(this, pos))
@ -1460,7 +1457,7 @@ public final class WorldServer extends AWorldServer {
liquid.generate(this, this.grng, pos); liquid.generate(this, this.grng, pos);
} }
} }
if(this.mobs && SVars.mobs && SVars.genSpawn) { if(this.mobs && Vars.mobs && SVars.genSpawn) {
Spawner.generate(this, biome, bx + 8, bz + 8, 16, 16, this.grng); Spawner.generate(this, biome, bx + 8, bz + 8, 16, 16, this.grng);
} }
// if(this.snow) { // if(this.snow) {
@ -1958,7 +1955,7 @@ public final class WorldServer extends AWorldServer {
} }
public void updateViewRadius() { public void updateViewRadius() {
int radius = ExtMath.clampi(SVars.distance, 3, 128); int radius = ExtMath.clampi(Vars.distance, 3, 128);
if(radius != this.viewRadius) { if(radius != this.viewRadius) {
int diff = radius - this.viewRadius; int diff = radius - this.viewRadius;
@ -1992,7 +1989,7 @@ public final class WorldServer extends AWorldServer {
this.viewRadius = radius; this.viewRadius = radius;
} }
this.trackDistance = SVars.distance * 16 - 16; this.trackDistance = Vars.distance * 16 - 16;
} }
public void trackEntity(Entity entityIn) { public void trackEntity(Entity entityIn) {

View file

@ -16,6 +16,7 @@ import common.tileentity.TileEntity;
import common.tileentity.TileEntityChest; import common.tileentity.TileEntityChest;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.World; import common.world.World;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -154,7 +155,7 @@ public class FeatureDungeons
} }
} }
if(SVars.mobs && SVars.spawnDungeonMobs > 0) { if(Vars.mobs && SVars.spawnDungeonMobs > 0) {
for(int z = 0; z < SVars.spawnDungeonMobs; z++) { for(int z = 0; z < SVars.spawnDungeonMobs; z++) {
EntityLiving entity = this.pickMobSpawner(rand, worldIn); EntityLiving entity = this.pickMobSpawner(rand, worldIn);
entity.setLocationAndAngles((double)position.getX() + rand.doublev(), (double)position.getY(), (double)position.getZ() + rand.doublev(), worldIn.rand.floatv() * 360.0F, 0.0F); entity.setLocationAndAngles((double)position.getX() + rand.doublev(), (double)position.getY(), (double)position.getZ() + rand.doublev(), worldIn.rand.floatv() * 360.0F, 0.0F);

View file

@ -10,6 +10,7 @@ import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.State; import common.world.State;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -1366,7 +1367,7 @@ public class StructureBridge
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 6, 8, 5, 7, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false); this.fillWithBlocks(worldIn, structureBoundingBoxIn, 1, 6, 8, 5, 7, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false);
this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 8, 8, 4, 8, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false); this.fillWithBlocks(worldIn, structureBoundingBoxIn, 2, 8, 8, 4, 8, 8, Blocks.blood_brick_fence.getState(), Blocks.blood_brick_fence.getState(), false);
if (!this.hasSpawner && SVars.mobs && SVars.spawnBridgeMobs) if (!this.hasSpawner && Vars.mobs && SVars.spawnBridgeMobs)
{ {
BlockPos blockpos = new BlockPos(this.getXWithOffset(3, 5), this.getYWithOffset(5), this.getZWithOffset(3, 5)); BlockPos blockpos = new BlockPos(this.getXWithOffset(3, 5), this.getYWithOffset(5), this.getZWithOffset(3, 5));

View file

@ -16,6 +16,7 @@ import common.rng.WeightedList;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.State; import common.world.State;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -363,7 +364,7 @@ public class StructureMineshaft
this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, RngLoot.addToList(LootConstants.MINESHAFT_CHEST, ItemEnchantedBook.getRandom(randomIn)), 3 + randomIn.zrange(4)); this.generateChestContents(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, RngLoot.addToList(LootConstants.MINESHAFT_CHEST, ItemEnchantedBook.getRandom(randomIn)), 3 + randomIn.zrange(4));
} }
if (this.hasSpiders && !this.spawnerPlaced && SVars.mobs && SVars.spawnMineshaftMobs) if (this.hasSpiders && !this.spawnerPlaced && Vars.mobs && SVars.spawnMineshaftMobs)
{ {
int l1 = this.getYWithOffset(0); int l1 = this.getYWithOffset(0);
int i2 = k1 - 1 + randomIn.zrange(3); int i2 = k1 - 1 + randomIn.zrange(3);

View file

@ -15,6 +15,7 @@ import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.State; import common.world.State;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -669,7 +670,7 @@ public class StructureScattered
} }
} }
if (!this.hasMage && SVars.mobs && SVars.spawnHutMage) if (!this.hasMage && Vars.mobs && SVars.spawnHutMage)
{ {
int l1 = this.getXWithOffset(2, 5); int l1 = this.getXWithOffset(2, 5);
int i2 = this.getYWithOffset(2); int i2 = this.getYWithOffset(2);

View file

@ -17,6 +17,7 @@ import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.State; import common.world.State;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -902,7 +903,7 @@ public class StructureStronghold
// this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 10, structureBoundingBoxIn); // this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 10, structureBoundingBoxIn);
// this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 11, structureBoundingBoxIn); // this.setBlockState(worldIn, Blocks.end_portal_frame.getStateFromMeta(j1).withProperty(BlockPortalFrame.ORB, Boolean.valueOf(randomIn.floatv() > 0.9F)), 7, 3, 11, structureBoundingBoxIn);
if (!this.hasSpawner && SVars.mobs && SVars.spawnStrongholdMobs) if (!this.hasSpawner && Vars.mobs && SVars.spawnStrongholdMobs)
{ {
i = this.getYWithOffset(3); i = this.getYWithOffset(3);
BlockPos blockpos = new BlockPos(this.getXWithOffset(5, 6), i, this.getZWithOffset(5, 6)); BlockPos blockpos = new BlockPos(this.getXWithOffset(5, 6), i, this.getZWithOffset(5, 6));

View file

@ -18,6 +18,7 @@ import common.rng.Random;
import common.tags.TagObject; import common.tags.TagObject;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.Facing; import common.util.Facing;
import common.vars.Vars;
import common.world.State; import common.world.State;
import server.vars.SVars; import server.vars.SVars;
import server.world.WorldServer; import server.world.WorldServer;
@ -1603,7 +1604,7 @@ public class StructureVillage
protected void spawnVillagers(WorldServer worldIn, StructureBoundingBox p_74893_2_, int p_74893_3_, int p_74893_4_, int p_74893_5_, int p_74893_6_) protected void spawnVillagers(WorldServer worldIn, StructureBoundingBox p_74893_2_, int p_74893_3_, int p_74893_4_, int p_74893_5_, int p_74893_6_)
{ {
if (this.villagersSpawned < p_74893_6_ && SVars.mobs && SVars.spawnVillager) if (this.villagersSpawned < p_74893_6_ && Vars.mobs && SVars.spawnVillager)
{ {
for (int i = this.villagersSpawned; i < p_74893_6_; ++i) for (int i = this.villagersSpawned; i < p_74893_6_; ++i)
{ {
@ -1920,7 +1921,7 @@ public class StructureVillage
protected void spawnVillager(WorldServer worldIn, StructureBoundingBox p_74893_2_, int x, int y, int z) protected void spawnVillager(WorldServer worldIn, StructureBoundingBox p_74893_2_, int x, int y, int z)
{ {
if (!this.villagerSpawned && SVars.mobs && SVars.spawnCageMobs) if (!this.villagerSpawned && Vars.mobs && SVars.spawnCageMobs)
{ {
int j = this.getXWithOffset(x, z); int j = this.getXWithOffset(x, z);
int k = this.getYWithOffset(y); int k = this.getYWithOffset(y);