add variable sync
This commit is contained in:
parent
b6242d5de1
commit
aee94aa14d
33 changed files with 392 additions and 200 deletions
|
@ -174,7 +174,9 @@ import common.util.Facing;
|
|||
import common.util.HitPosition;
|
||||
import common.util.LazyLoader;
|
||||
import common.util.Util;
|
||||
import common.util.Var;
|
||||
import common.util.HitPosition.ObjectType;
|
||||
import common.vars.Vars;
|
||||
import common.world.LightType;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
@ -301,6 +303,7 @@ public class Client implements IThreadListener {
|
|||
private final Map<Integer, Long> bars = Maps.newTreeMap();
|
||||
private final Thread clThread = Thread.currentThread();
|
||||
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 List<Message> console = Lists.newArrayList();
|
||||
private final List<Message> chat = Lists.newArrayList();
|
||||
|
@ -327,7 +330,6 @@ public class Client implements IThreadListener {
|
|||
public boolean xrayActive;
|
||||
public boolean tileOverlay;
|
||||
public boolean itemCheat;
|
||||
public boolean dayCycle = true;
|
||||
public boolean debugPlayer;
|
||||
public boolean cameraUsed;
|
||||
public boolean charEditor;
|
||||
|
@ -337,7 +339,6 @@ public class Client implements IThreadListener {
|
|||
private int chunkLoadTimer;
|
||||
|
||||
public int thirdPersonView;
|
||||
public int timeFactor = 1;
|
||||
public int chunksUpdated;
|
||||
public int selectedCharacter = -1;
|
||||
|
||||
|
@ -350,7 +351,6 @@ public class Client implements IThreadListener {
|
|||
public float moveStrafe;
|
||||
public float moveForward;
|
||||
public float zoomLevel;
|
||||
public float gravity = 1.0f;
|
||||
|
||||
private long tmr_timer;
|
||||
private long tmr_start;
|
||||
|
@ -625,9 +625,6 @@ public class Client implements IThreadListener {
|
|||
this.player.noclip = true;
|
||||
this.player.addEffect(new StatusEffect(Effect.FLYING, Integer.MAX_VALUE, 1));
|
||||
this.player.setHeight(2.0f);
|
||||
world.setGravity(this.gravity = 1.0f);
|
||||
world.setTimeFactor(this.timeFactor = 1);
|
||||
this.dayCycle = true;
|
||||
}
|
||||
|
||||
public void unloadWorld() {
|
||||
|
@ -700,6 +697,19 @@ public class Client implements IThreadListener {
|
|||
this.renderGlobal.onReload();
|
||||
EntityTexManager.loadNpcTextures();
|
||||
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()
|
||||
|
@ -1115,6 +1125,21 @@ public class Client implements IThreadListener {
|
|||
// 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();
|
||||
ItemRenderer.disableStandardItemLighting();
|
||||
|
@ -1948,7 +1973,7 @@ public class Client implements IThreadListener {
|
|||
this.world.getDarkness()
|
||||
) + "\n" +
|
||||
String.format("Zeitfaktor: %dx, Schwerkraft: %.2f m/s²",
|
||||
this.timeFactor, this.world.gravity * 10.0
|
||||
Vars.timeFlow, this.world.gravity * 10.0
|
||||
) + "\n" +
|
||||
String.format("Letzte Zeitsynch.: + %d.%d s",
|
||||
ticked / 1000L, (ticked / 100L) % 10L
|
||||
|
@ -3508,4 +3533,29 @@ public class Client implements IThreadListener {
|
|||
}
|
||||
}, "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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,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;
|
||||
|
@ -106,6 +106,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;
|
||||
|
@ -116,13 +117,13 @@ import common.packet.SPacketTimeUpdate;
|
|||
import common.packet.SPacketTrades;
|
||||
import common.packet.SPacketUpdateDisplay;
|
||||
import common.packet.SPacketUpdateHealth;
|
||||
import common.packet.SPacketWorld;
|
||||
import common.rng.Random;
|
||||
import common.sound.Sound;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.tileentity.TileEntityDevice;
|
||||
import common.tileentity.TileEntityDisplay;
|
||||
import common.tileentity.TileEntitySign;
|
||||
import common.util.Pair;
|
||||
import common.village.MerchantRecipeList;
|
||||
import common.world.Explosion;
|
||||
import common.world.Weather;
|
||||
|
@ -215,6 +216,13 @@ public class ClientPlayer implements IClientPlayer
|
|||
// 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)
|
||||
{
|
||||
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,
|
||||
* beacons, skulls, flowerpot
|
||||
*/
|
||||
public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn)
|
||||
public void handleUpdateTileEntity(SPacketUpdateDevice packetIn)
|
||||
{
|
||||
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) {
|
||||
NetHandler.checkThread(packetIn, this, this.gm, this.world);
|
||||
if(this.world.dimension.isCustom()) {
|
||||
|
|
|
@ -33,6 +33,7 @@ import common.block.tile.BlockSign;
|
|||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
import common.collect.Sets;
|
||||
import common.dimension.DimType;
|
||||
import common.entity.Entity;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntityBox;
|
||||
|
@ -108,14 +109,16 @@ public class RenderGlobal
|
|||
return this.time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 float[] SUN_COLOR = new float[4];
|
||||
|
||||
private final Client gm;
|
||||
private final TextureManager renderEngine;
|
||||
private final RenderManager renderManager;
|
||||
private final Random rand = new Random();
|
||||
private WorldClient theWorld;
|
||||
private Set<RenderChunk> chunksToUpdate = new LinkedHashSet<RenderChunk>();
|
||||
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);
|
||||
GL11.glPushMatrix();
|
||||
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(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;
|
||||
this.renderEngine.bindTexture(SUN_TEX);
|
||||
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
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();
|
||||
worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex();
|
||||
worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
if(this.gm.world.dimension.getType().moon) {
|
||||
float size = 20.0F;
|
||||
this.renderEngine.bindTexture(MOON_TEX);
|
||||
int i = this.theWorld.getMoonPhase();
|
||||
int k = i % 4;
|
||||
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), -100.0D, (double)size).tex((double)f24, (double)f14).endVertex();
|
||||
worldrenderer.pos((double)size, -100.0D, (double)size).tex((double)f22, (double)f14).endVertex();
|
||||
worldrenderer.pos((double)size, -100.0D, (double)(-size)).tex((double)f22, (double)f23).endVertex();
|
||||
worldrenderer.pos((double)(-size), -100.0D, (double)(-size)).tex((double)f24, (double)f23).endVertex();
|
||||
Tessellator.draw();
|
||||
int color = this.gm.world.dimension.getSunColor();
|
||||
if(color != 0xffffffff) {
|
||||
Vec3 ncolor = new Vec3(color).normalize();
|
||||
GlState.color((float)ncolor.xCoord, (float)ncolor.yCoord, (float)ncolor.zCoord, f16);
|
||||
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
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();
|
||||
worldrenderer.pos((double)size, 100.0D, (double)size).tex(1.0D, 1.0D).endVertex();
|
||||
worldrenderer.pos((double)(-size), 100.0D, (double)size).tex(0.0D, 1.0D).endVertex();
|
||||
Tessellator.draw();
|
||||
}
|
||||
size = 20.0F;
|
||||
this.renderEngine.bindTexture(this.gm.world.dimension.getType() == DimType.MOON ? PLANET_TEX : MOON_TEX);
|
||||
int[] colors = this.gm.world.dimension.getMoonColors();
|
||||
this.rand.setSeed(this.gm.world.dimension.getSeed());
|
||||
int mx = 0;
|
||||
int mz = 0;
|
||||
for(int z = 0; z < colors.length; z++) {
|
||||
Vec3 ncolor = new Vec3(colors[z]).normalize();
|
||||
GlState.color((float)ncolor.xCoord, (float)ncolor.yCoord, (float)ncolor.zCoord, f16);
|
||||
int i = this.theWorld.getMoonPhase(z);
|
||||
int k = i % 4;
|
||||
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();
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import common.util.ExtMath;
|
|||
import common.util.LongHashMap;
|
||||
import common.util.ParticleType;
|
||||
import common.util.Vec3;
|
||||
import common.vars.Vars;
|
||||
import common.util.BlockPos.MutableBlockPos;
|
||||
import common.world.AWorldClient;
|
||||
import common.world.State;
|
||||
|
@ -57,8 +58,7 @@ public class WorldClient extends AWorldClient
|
|||
this.emptyChunk = new ChunkEmpty(this, this.gm.debugWorld);
|
||||
this.calculateInitialSkylight();
|
||||
this.calculateInitialWeather();
|
||||
this.setGravity(this.gm.gravity);
|
||||
this.setTimeFactor(this.gm.timeFactor);
|
||||
this.updatePhysics();
|
||||
// this.setDifficulty(this.gm.difficulty);
|
||||
}
|
||||
|
||||
|
@ -97,12 +97,13 @@ public class WorldClient extends AWorldClient
|
|||
|
||||
public void tick()
|
||||
{
|
||||
this.updatePhysics();
|
||||
this.markReload();
|
||||
// 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)
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 6.7 KiB |
BIN
client/src/main/resources/textures/world/planet_phases.png
Executable file
BIN
client/src/main/resources/textures/world/planet_phases.png
Executable file
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 |
Loading…
Add table
Add a link
Reference in a new issue