From c126bdd8b063f9a23e1464b7053a6a5b39003734 Mon Sep 17 00:00:00 2001 From: Sen Date: Sat, 12 Jul 2025 12:23:56 +0200 Subject: [PATCH] fix datamap saving --- client/src/main/java/client/Client.java | 162 +++++++++--------- .../src/main/java/server/network/Player.java | 4 +- server/src/main/java/server/world/Region.java | 7 +- 3 files changed, 86 insertions(+), 87 deletions(-) diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 31f48479..c24ad419 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -509,9 +509,28 @@ public class Client implements IThreadListener { private int soundBufferSize = 16384; @Variable(name = "snd_frame_size", category = CVarCategory.SOUND, min = 2, max = 8192, display = "Intervall") private int soundFrameSize = 32; - public static final Client CLIENT = new Client(); + + public static void main(String[] args) { + long time = System.currentTimeMillis(); + Util.checkPlatform(); + Thread.currentThread().setName("Render thread"); + Locale.setDefault(Locale.ROOT); + Util.setupHandlers(); + Log.init(); + Log.SYSTEM.info("Java " + System.getProperty("java.version")); + Log.SYSTEM.info("Starte " + VERSION + " (Protokoll #" + Util.PROTOCOL + ")"); + if(Util.DEVMODE) + Log.SYSTEM.warn("Entwicklungsmodus aktiv - Debugging-Features sind verfügbar"); + Window.init(); + ModelBlock.setAsProvider(); + Registry.register(); + UniverseRegistry.register(); + Log.setSync(CLIENT); + CLIENT.run(time); + Window.end(); + } private Client() { } @@ -916,7 +935,7 @@ public class Client implements IThreadListener { GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); } - private static int stats(int x, int y, String name, int value, int max, int color) { + private int drawStat(int x, int y, String name, int value, int max, int color) { int w = (int)(246.0f * (float)value / (float)max); Drawing.drawTextboxRight(name, x + 250, y, 0x3f000000); Drawing.drawTextbox(String.format(TextColor.GREEN + "%d " + TextColor.GRAY + "/ " + TextColor.NEON + "%d", value, max), x, y, 0x3f000000); @@ -925,7 +944,7 @@ public class Client implements IThreadListener { return y + 40; } - private static int bar(int x, int y, String name, float fill, int color) { + private int drawBar(int x, int y, String name, float fill, int color) { Drawing.drawTextbox(name, x, y, 0x3f000000); Drawing.drawRectBorder(x, y + 20, 250, 10, 0xff000000, 0xff202020, 0xffcfcfcf, 0xff6f6f6f); Drawing.drawGradient(x + 2, y + 20 + 2, (int)(246.0f * fill), 6, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000)); @@ -1011,41 +1030,41 @@ public class Client implements IThreadListener { y = this.fbY - 40 - stats * 40; int hp = entity.getHealth(); int max = entity.getMaxHealth(); - y = stats(x, y, TextColor.RED + "Schaden", hp, max, 0xff0000); + y = this.drawStat(x, y, TextColor.RED + "Schaden", hp, max, 0xff0000); if(absorb > 0) - y = stats(x, y, TextColor.YELLOW + "Schadenspuffer", absorb, 1024, 0xffff00); + y = this.drawStat(x, y, TextColor.YELLOW + "Schadenspuffer", absorb, 1024, 0xffff00); if(entity instanceof EntityWaterNPC npc) { int moist = npc.getMoisture(); int maxm = npc.getMaxMoisture(); - y = stats(x, y, TextColor.BLUE + "Feuchtigkeit", moist, maxm, 0x4f4fff); + y = this.drawStat(x, y, TextColor.BLUE + "Feuchtigkeit", moist, maxm, 0x4f4fff); } if(armor > 0) - y = stats(x, y, TextColor.GRAY + "Rüstung", armor, 1024, 0x707070); + y = this.drawStat(x, y, TextColor.GRAY + "Rüstung", armor, 1024, 0x707070); if(entity.vehicle instanceof EntityLiving living) { int vh = living.getHealth(); int vhMax = living.getMaxHealth(); - y = stats(x, y, living.getDisplayName(), vh, vhMax, 0xff6060); + y = this.drawStat(x, y, living.getDisplayName(), vh, vhMax, 0xff6060); } if(entity.getManaPoints() > 0) { int mana = entity.getManaPoints(); int maxm = entity.getMaxMana(); - y = stats(x, y, TextColor.CYAN + "Mana", mana, maxm, 0x0000ff); + y = this.drawStat(x, y, TextColor.CYAN + "Mana", mana, maxm, 0x0000ff); } for(int z = 0; z < Energy.values().length; z++) { Energy type = Energy.values()[z]; int energy = entity.getEnergy(type); if(energy > 0) { int emax = entity.getEnergyCap(type); - y = stats(x, y, TextColor.LGRAY + type.display, energy, emax, entity.hasEnergyEffect(type) ? type.effect : type.color); + y = this.drawStat(x, y, TextColor.LGRAY + type.display, energy, emax, entity.hasEnergyEffect(type) ? type.effect : type.color); } } x = 40; y = this.fbY - 40 - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40; if(this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f) // { - y = bar(x, y, String.format(TextColor.NEON + "Sprungkraft: " + TextColor.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)), + y = this.drawBar(x, y, String.format(TextColor.NEON + "Sprungkraft: " + TextColor.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)), this.player.getHorseJumpPower(), 0x4040ff); - y = bar(x, y, String.format(TextColor.ACID + "EXP: " + TextColor.GREEN + "Level %d, %d/%d", this.player.experienceLevel, (int)((float)this.player.xpBarCap() * this.player.experience), this.player.xpBarCap()), this.player.experience, 0x40ff40); + y = this.drawBar(x, y, String.format(TextColor.ACID + "EXP: " + TextColor.GREEN + "Level %d, %d/%d", this.player.experienceLevel, (int)((float)this.player.xpBarCap() * this.player.experience), this.player.xpBarCap()), this.player.experience, 0x40ff40); } GlState.bindTexture(0); @@ -2618,77 +2637,6 @@ public class Client implements IThreadListener { } return func != null; } - - - - public static void main(String[] args) { - long time = System.currentTimeMillis(); - Util.checkPlatform(); - Thread.currentThread().setName("Render thread"); - Locale.setDefault(Locale.ROOT); - Util.setupHandlers(); - Log.init(); - Log.SYSTEM.info("Java " + System.getProperty("java.version")); - Log.SYSTEM.info("Starte " + VERSION + " (Protokoll #" + Util.PROTOCOL + ")"); - if(Util.DEVMODE) - Log.SYSTEM.warn("Entwicklungsmodus aktiv - Debugging-Features sind verfügbar"); - Window.init(); - ModelBlock.setAsProvider(); - Registry.register(); - UniverseRegistry.register(); - Log.setSync(CLIENT); - CLIENT.run(time); - Window.end(); - } - - - private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) { - byte[] data = new byte[w * h * 4]; - byte[] color = new byte[24]; - color1 = (color1 << 8) | (color1 >> 24); - color2 = (color2 << 8) | (color2 >> 24); - color3 = (color3 << 8) | (color3 >> 24); - color4 = (color4 << 8) | (color4 >> 24); - color5 = (color5 << 8) | (color5 >> 24); - color6 = (color6 << 8) | (color6 >> 24); - for(int z = 0; z < 4; z++) { - color[z] = (byte)((color1 >> ((3 - z) * 8)) & 0xff); - color[z+4] = (byte)((color2 >> ((3 - z) * 8)) & 0xff); - color[z+8] = (byte)((color3 >> ((3 - z) * 8)) & 0xff); - color[z+12] = (byte)((color4 >> ((3 - z) * 8)) & 0xff); - color[z+16] = (byte)((color5 >> ((3 - z) * 8)) & 0xff); - color[z+20] = (byte)((color6 >> ((3 - z) * 8)) & 0xff); - } - for(int y = 0; y < h; y++) { - int offs = ((y / 2 == h / 16) || (y / 2 == (h / 2 - h / 16) - 1)) ? 16 : (((y / 2 == h / 16 + 1) || (y / 2 == (h / 2 - h / 16) - 2)) ? 20 : 0); - for(int x = 0; x < w; x++) { - System.arraycopy(color, offs, data, (y*w+x) << 2, 4); - } - } - for(int x = 0; x < w; x++) { - float fx = (float)(w / 4 + x); - float fp = (float)((w * 3) / 4); - float fa = (float)(((h * 3) / 4) / 2); - int y = ((x < w / 8) || (x >= w - w / 8)) ? (h / 2) : (h / 2 + (int)(((4.0f * fa) / fp) * ExtMath.absf(((fx - fp / 4.0f) % fp) - fp / 2.0f) - fa)); - System.arraycopy(color, 0, data, ((y-8)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y-7)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y-6)*w+x) << 2, 4); - System.arraycopy(color, 4, data, ((y-5)*w+x) << 2, 4); - System.arraycopy(color, 4, data, ((y-4)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y-3)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y-2)*w+x) << 2, 4); - System.arraycopy(color, 8, data, ((y-1)*w+x) << 2, 4); - System.arraycopy(color, 8, data, ((y+0)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y+1)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y+2)*w+x) << 2, 4); - System.arraycopy(color, 12, data, ((y+3)*w+x) << 2, 4); - System.arraycopy(color, 12, data, ((y+4)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y+5)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y+6)*w+x) << 2, 4); - System.arraycopy(color, 0, data, ((y+7)*w+x) << 2, 4); - } - return data; - } public T getVar(String name) { return (T)this.cvars.get(name); @@ -3303,4 +3251,52 @@ public class Client implements IThreadListener { Log.NETWORK.debug("Variable %s = %s", name, value); } } + + private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) { + byte[] data = new byte[w * h * 4]; + byte[] color = new byte[24]; + color1 = (color1 << 8) | (color1 >> 24); + color2 = (color2 << 8) | (color2 >> 24); + color3 = (color3 << 8) | (color3 >> 24); + color4 = (color4 << 8) | (color4 >> 24); + color5 = (color5 << 8) | (color5 >> 24); + color6 = (color6 << 8) | (color6 >> 24); + for(int z = 0; z < 4; z++) { + color[z] = (byte)((color1 >> ((3 - z) * 8)) & 0xff); + color[z+4] = (byte)((color2 >> ((3 - z) * 8)) & 0xff); + color[z+8] = (byte)((color3 >> ((3 - z) * 8)) & 0xff); + color[z+12] = (byte)((color4 >> ((3 - z) * 8)) & 0xff); + color[z+16] = (byte)((color5 >> ((3 - z) * 8)) & 0xff); + color[z+20] = (byte)((color6 >> ((3 - z) * 8)) & 0xff); + } + for(int y = 0; y < h; y++) { + int offs = ((y / 2 == h / 16) || (y / 2 == (h / 2 - h / 16) - 1)) ? 16 : (((y / 2 == h / 16 + 1) || (y / 2 == (h / 2 - h / 16) - 2)) ? 20 : 0); + for(int x = 0; x < w; x++) { + System.arraycopy(color, offs, data, (y*w+x) << 2, 4); + } + } + for(int x = 0; x < w; x++) { + float fx = (float)(w / 4 + x); + float fp = (float)((w * 3) / 4); + float fa = (float)(((h * 3) / 4) / 2); + int y = ((x < w / 8) || (x >= w - w / 8)) ? (h / 2) : (h / 2 + (int)(((4.0f * fa) / fp) * ExtMath.absf(((fx - fp / 4.0f) % fp) - fp / 2.0f) - fa)); + System.arraycopy(color, 0, data, ((y-8)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y-7)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y-6)*w+x) << 2, 4); + System.arraycopy(color, 4, data, ((y-5)*w+x) << 2, 4); + System.arraycopy(color, 4, data, ((y-4)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y-3)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y-2)*w+x) << 2, 4); + System.arraycopy(color, 8, data, ((y-1)*w+x) << 2, 4); + System.arraycopy(color, 8, data, ((y+0)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y+1)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y+2)*w+x) << 2, 4); + System.arraycopy(color, 12, data, ((y+3)*w+x) << 2, 4); + System.arraycopy(color, 12, data, ((y+4)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y+5)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y+6)*w+x) << 2, 4); + System.arraycopy(color, 0, data, ((y+7)*w+x) << 2, 4); + } + return data; + } } diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 6561dcb6..246d945f 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -1578,13 +1578,13 @@ public class Player extends User implements Executor, IPlayer } }); this.connection.disableAutoRead(); - Futures.getUnchecked(this.server.schedule(new Runnable() + this.server.schedule(new Runnable() { public void run() { Player.this.connection.checkDisconnected(); } - })); + }); } public void onDisconnect(String reason) diff --git a/server/src/main/java/server/world/Region.java b/server/src/main/java/server/world/Region.java index 2b9b1ca1..2de88353 100755 --- a/server/src/main/java/server/world/Region.java +++ b/server/src/main/java/server/world/Region.java @@ -74,7 +74,8 @@ public class Region { missing.add(id); } } - for(Entry entry : states.entrySet()) { + for(Iterator> iter = states.entrySet().iterator(); iter.hasNext();) { + Entry entry = iter.next(); char bid = entry.getKey(); String oid = entry.getValue(); State state = BlockRegistry.byName(oid, null); @@ -83,7 +84,9 @@ public class Region { mapping.put(bid, id); highest = bid > highest ? bid : highest; missing.remove(id); - Log.IO.debug((id.equals(oid) ? "Mehrfache" : "Geänderte") + " Block-ID %d = %s -> %s", (int)bid, oid, id); + if(id.equals(oid)) + iter.remove(); + Log.IO.debug((id.equals(oid) ? "Mehrfache" : "Geänderte") + " Block-ID %d = %s" + (id.equals(oid) ? "" : " -> %s"), (int)bid, oid, id); } else { Log.IO.debug("Entfernte Block-ID %d = %s", (int)bid, oid);