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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue