diff --git a/java/src/game/Game.java b/java/src/game/Game.java index d32293f..07dbb47 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -427,6 +427,7 @@ public class Game implements IThreadListener { private String buffer = ""; private boolean crashed; private boolean waitingForFile; + private boolean refreshing; private final int[] tickTimes = new int[240]; private final long[] frames = new long[240]; @@ -1152,7 +1153,8 @@ public class Game implements IThreadListener { public void displayGuiScreen(Gui gui) { - this.waitingForFile = false; + if(!this.refreshing) + this.waitingForFile = false; if(this.thePlayer != null) this.thePlayer.setScreenClosed(); if (this.open != null) @@ -1870,9 +1872,9 @@ public class Game implements IThreadListener { fb_x = x; fb_y = y; if(this.open != null) { - boolean flag = this.waitingForFile; + this.refreshing = true; this.displayGuiScreen(this.open); - this.waitingForFile = flag; + this.refreshing = false; } if(!fullscreen) { xsize = x; @@ -1976,9 +1978,9 @@ public class Game implements IThreadListener { private void redraw() { if(this.open != null) { - boolean flag = this.waitingForFile; + this.refreshing = true; this.displayGuiScreen(this.open); - this.waitingForFile = flag; + this.refreshing = false; } } @@ -2410,6 +2412,11 @@ public class Game implements IThreadListener { // if(server != null) { // } } + + public void waitForServer() { + if(this.server != null) + this.displayGuiScreen(GuiLoading.makeIntermittentTask(this.server)); + } private void startSound(boolean load) { if(load) @@ -3331,7 +3338,7 @@ public class Game implements IThreadListener { FILE_SAVE; } - public void showDirDialog(final FileMode mode, final String title, final File def, final FileCallback callback) { + public void showFileDialog(final FileMode mode, final String title, final File def, final FileCallback callback) { if(this.waitingForFile) return; this.waitingForFile = true; @@ -3372,57 +3379,72 @@ public class Game implements IThreadListener { } } catch(Throwable e) { + Log.SYSTEM.error(e, "Konnte Zenity nicht starten"); + Game.this.logFeed(TextColor.RED + "Konnte Dateibrowser nicht öffnen"); + Game.this.waitingForFile = false; return; } - if(output != null) { - if(mode == FileMode.FILE_LOAD_MULTI) { - final List files = Lists.newArrayList(); - for(String out : output.split(":")) { - File file = new File(out); - if(file.isFile()) - files.add(file); - } - if(files.isEmpty()) - return; - Game.this.schedule(new Runnable() { - public void run() { - if(Game.this.waitingForFile) { - for(File file : files) { - callback.selected(file); - } - } - Game.this.waitingForFile = false; - } - }); + if(output == null) { + Game.this.waitingForFile = false; + return; + } + if(mode == FileMode.FILE_LOAD_MULTI) { + final List files = Lists.newArrayList(); + for(String out : output.split(":")) { + File file = new File(out); + if(file.isFile()) + files.add(file); } - else { - File file = new File(output); - switch(mode) { - case DIRECTORY_LOAD: - if(!file.isDirectory()) - return; - break; - case DIRECTORY_SAVE: - if(file.exists() && !file.isDirectory()) - return; - break; - case FILE_LOAD: - if(!file.isFile()) - return; - break; - case FILE_SAVE: - if(file.exists() && !file.isFile()) - return; - break; - } - Game.this.schedule(new Runnable() { - public void run() { - if(Game.this.waitingForFile) + if(files.isEmpty()) { + Game.this.waitingForFile = false; + return; + } + Game.this.schedule(new Runnable() { + public void run() { + if(Game.this.waitingForFile) { + for(File file : files) { callback.selected(file); - Game.this.waitingForFile = false; + } } - }); + Game.this.waitingForFile = false; + } + }); + } + else { + File file = new File(output); + switch(mode) { + case DIRECTORY_LOAD: + if(!file.isDirectory()) { + Game.this.waitingForFile = false; + return; + } + break; + case DIRECTORY_SAVE: + if(file.exists() && !file.isDirectory()) { + Game.this.waitingForFile = false; + return; + } + break; + case FILE_LOAD: + if(!file.isFile()) { + Game.this.waitingForFile = false; + return; + } + break; + case FILE_SAVE: + if(file.exists() && !file.isFile()) { + Game.this.waitingForFile = false; + return; + } + break; } + Game.this.schedule(new Runnable() { + public void run() { + if(Game.this.waitingForFile) + callback.selected(file); + Game.this.waitingForFile = false; + } + }); } } }, "Zenity listener").start(); diff --git a/java/src/game/Server.java b/java/src/game/Server.java index 8293287..1910984 100755 --- a/java/src/game/Server.java +++ b/java/src/game/Server.java @@ -354,16 +354,16 @@ public final class Server implements Runnable, IThreadListener { } } - private void preload(Entity entity) { + public void preload(WorldServer world, int bx, int bz) { int done = 0; int total = Config.distance * 2 + 1; total *= total; this.setMessage("Landschaft wird generiert"); this.startProgress(false, total); - WorldServer world = this.getWorld(Config.spawnDim); - world = world == null ? this.space : world; - int bx = (int)entity.posX >> 4; - int bz = (int)entity.posZ >> 4; +// WorldServer world = this.getWorld(Config.spawnDim); +// world = world == null ? this.space : world; + bx = bx >> 4; + bz = bz >> 4; long last = System.currentTimeMillis(); for(int x = -Config.distance; x <= Config.distance && this.running; x++) { for(int z = -Config.distance; z <= Config.distance && this.running; z++) { @@ -381,6 +381,14 @@ public final class Server implements Runnable, IThreadListener { } this.setProgress(-1); } + +// public void resetProgress() { +// this.setProgress(-1); +// } +// +// public void setDone() { +// this.setProgress(-2); +// } private void tick() { // boolean pause = this.paused; @@ -614,26 +622,26 @@ public final class Server implements Runnable, IThreadListener { return Thread.currentThread() == this.serverThread; } - private void movePlayerToSpawn(EntityNPC player) { - BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ); - int radius = Config.spawnRadius; - if(radius > 0) { - pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add( - ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0, - ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1))); - } - player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw, - radius > 0 ? 0.0f : Config.spawnPitch); - while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty() - && player.posY < 511.0D) { - player.setPosition(player.posX, player.posY + 1.0D, player.posZ); - } - } +// private void movePlayerToSpawn(EntityNPC player) { +// BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ); +// int radius = Config.spawnRadius; +// if(radius > 0) { +// pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add( +// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0, +// ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1))); +// } +// player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw, +// radius > 0 ? 0.0f : Config.spawnPitch); +// while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty() +// && player.posY < 511.0D) { +// player.setPosition(player.posX, player.posY + 1.0D, player.posZ); +// } +// } - public Position getRandomSpawnPosition() { - WorldServer world = this.getWorld(Config.spawnDim); + public Position getRandomSpawnPosition(WorldPos origin) { + WorldServer world = this.getWorld(origin.getDimension()); world = world == null ? this.space : world; - BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ); + BlockPos pos = origin; int radius = Config.spawnRadius; if(radius > 0) { pos = world.getTopSolidOrLiquidBlock(pos.add( @@ -703,8 +711,8 @@ public final class Server implements Runnable, IThreadListener { + player.getId() + " auf Level " + world.dimension.getDimensionId() + ": " + String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? " (Charakter-Editor)" : "'" + player.getCommandName() + "'") + ")"); - if(Config.preloadAll || (Config.preloadLocal && conn.isLocal())) - this.preload(player); + if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1) + this.preload(world, (int)player.posX, (int)player.posZ); conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null)); conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); @@ -807,6 +815,7 @@ public final class Server implements Runnable, IThreadListener { old.getServerWorld().removePlayer(old); old.getServerWorld().removePlayerEntityDangerously(old); WorldPos bed = old.getSpawnPoint(); + WorldPos origin = old.getOrigin(); BlockPos spawn = null; String message = null; WorldServer world = bed == null ? this.space : this.getWorld(bed.getDimension()); @@ -824,19 +833,22 @@ public final class Server implements Runnable, IThreadListener { } } if(bed == null) { - world = this.getWorld(Config.spawnDim); + world = this.getWorld(origin.getDimension()); world = world == null ? this.space : world; } EntityNPC nplayer = conn.createPlayer(world, EntityRegistry.getEntityString(old)); conn.clonePlayer(old); nplayer.setId(old.getId()); + nplayer.setOrigin(origin); if(bed != null) { nplayer.setLocationAndAngles((double)((float)spawn.getX() + 0.5F), (double)((float)spawn.getY() + 0.1F), (double)((float)spawn.getZ() + 0.5F), 0.0F, 0.0F); nplayer.setSpawnPoint(bed); } else { - this.movePlayerToSpawn(nplayer); + Position rpos = this.getRandomSpawnPosition(origin); + nplayer.setLocationAndAngles(rpos.x, rpos.y, rpos.z, rpos.yaw, rpos.pitch); +// this.movePlayerToSpawn(nplayer); } world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4); if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) { @@ -1027,7 +1039,7 @@ public final class Server implements Runnable, IThreadListener { if(this.endpoint != null) this.unsetLanEndpoint(); // throw new IllegalStateException("Eingangspunkt bereits gesetzt"); - Log.JNI.info("Öffne Port " + port + " auf 0.0.0.0"); + Log.JNI.info("Öffne Port %d auf 0.0.0.0 (Timeout %ds)", port, Config.timeout); this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer() { protected void initChannel(Channel channel) throws Exception { try { @@ -1035,7 +1047,7 @@ public final class Server implements Runnable, IThreadListener { } catch(ChannelException e) { } - channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))) + channel.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(Config.timeout))) .addLast((String)"splitter", (ChannelHandler)(new PacketSplitter())) .addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true))) .addLast((String)"prepender", (ChannelHandler)(new PacketPrepender())) diff --git a/java/src/game/command/commands/CommandWarp.java b/java/src/game/command/commands/CommandWarp.java index 04f8a03..8f102ef 100644 --- a/java/src/game/command/commands/CommandWarp.java +++ b/java/src/game/command/commands/CommandWarp.java @@ -3,17 +3,13 @@ package game.command.commands; import java.util.Collection; import java.util.List; import game.command.CommandEnvironment; -import game.collect.Lists; import game.command.Command; import game.command.Executor; import game.command.RunException; import game.command.StringCompleter; import game.entity.Entity; -import game.init.Config; import game.init.UniverseRegistry; -import game.world.BlockPos; import game.world.Position; -import game.world.WorldServer; public class CommandWarp extends Command { public CommandWarp() { @@ -21,9 +17,9 @@ public class CommandWarp extends Command { this.addString("warp", true, new StringCompleter() { public Collection complete(CommandEnvironment env) { - List warps = Lists.newArrayList("spawn"); - warps.addAll(env.getServer().getWarps().keySet()); - return warps; +// List warps = Lists.newArrayList("spawn"); +// warps.addAll(env.getServer().getWarps().keySet()); + return env.getServer().getWarps().keySet(); } }); @@ -31,23 +27,23 @@ public class CommandWarp extends Command { } public Object exec(CommandEnvironment env, Executor exec, String warp, List entities) { - Position pos; - if(warp.equals("spawn")) { - WorldServer world = env.getServer().getWorld(Config.spawnDim); - world = world == null ? env.getServer().getSpace() : world; - int y = Config.spawnY; - while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511) - y++; - pos = new Position(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d, - Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId()); - } - else { - pos = env.getServer().getWarps().get(warp); - if(pos == null) - throw new RunException("Warp '%s' existiert nicht", warp); - else if(env.getServer().getWorld(pos.dim) == null) - throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim); - } + Position // pos; +// if(warp.equals("spawn")) { +// WorldServer world = env.getServer().getWorld(Config.spawnDim); +// world = world == null ? env.getServer().getSpace() : world; +// int y = Config.spawnY; +// while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511) +// y++; +// pos = new Position(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d, +// Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId()); +// } +// else { + pos = env.getServer().getWarps().get(warp); + if(pos == null) + throw new RunException("Warp '%s' existiert nicht", warp); + else if(env.getServer().getWorld(pos.dim) == null) + throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim); +// } for(Entity entity : entities) { entity.teleport(pos); exec.logConsole("%s nach %d, %d, %d in %s teleportiert", entity.getCommandName(), (int)pos.x, (int)pos.y, (int)pos.z, UniverseRegistry.getDimension(pos.dim).getFormattedName(false)); diff --git a/java/src/game/entity/npc/EntityNPC.java b/java/src/game/entity/npc/EntityNPC.java index 1d7afb7..6457f08 100755 --- a/java/src/game/entity/npc/EntityNPC.java +++ b/java/src/game/entity/npc/EntityNPC.java @@ -24,6 +24,7 @@ import game.ai.EntityAIWatchClosest2; import game.audio.MovingSoundMinecartRiding; import game.block.Block; import game.block.BlockBed; +import game.dimension.Space; import game.enchantment.Enchantment; import game.enchantment.EnchantmentHelper; import game.entity.DamageSource; @@ -218,6 +219,7 @@ public abstract class EntityNPC extends EntityLiving public double chasingPosX; public double chasingPosY; public double chasingPosZ; + private WorldPos originPos = new WorldPos(0, 64, 0, Space.INSTANCE.getDimensionId()); private WorldPos spawnPos; // private BlockPos startMinecartRidingCoordinate; public int experienceLevel; @@ -3541,6 +3543,12 @@ public abstract class EntityNPC extends EntityLiving tagCompund.getInteger("SpawnZ"), tagCompund.getInteger("SpawnDim")); // this.spawnForced = tagCompund.getBoolean("SpawnForced"); } + + if (tagCompund.hasKey("OriginX", 99) && tagCompund.hasKey("OriginY", 99) && tagCompund.hasKey("OriginZ", 99)) + { + this.originPos = new WorldPos(tagCompund.getInteger("OriginX"), tagCompund.getInteger("OriginY"), + tagCompund.getInteger("OriginZ"), tagCompund.getInteger("OriginDim")); + } // this.foodStats.readNBT(tagCompund); // this.readCapabilitiesFromNBT(tagCompund); @@ -3664,6 +3672,14 @@ public abstract class EntityNPC extends EntityLiving // tagCompound.setBoolean("SpawnForced", this.spawnForced); } + if (this.originPos != null) + { + tagCompound.setInteger("OriginX", this.originPos.getX()); + tagCompound.setInteger("OriginY", this.originPos.getY()); + tagCompound.setInteger("OriginZ", this.originPos.getZ()); + tagCompound.setInteger("OriginDim", this.originPos.getDimension()); + } + // this.foodStats.writeNBT(tagCompound); // this.writeCapabilitiesToNBT(tagCompound); tagCompound.setBoolean("flying", this.flying); @@ -3964,6 +3980,16 @@ public abstract class EntityNPC extends EntityLiving this.spawnPos = pos; } + public WorldPos getOrigin() + { + return this.originPos; + } + + public void setOrigin(WorldPos pos) + { + this.originPos = pos; + } + // /** // * Will trigger the specified trigger. // */ diff --git a/java/src/game/gui/GuiChar.java b/java/src/game/gui/GuiChar.java index 54d96ab..0a53ec7 100755 --- a/java/src/game/gui/GuiChar.java +++ b/java/src/game/gui/GuiChar.java @@ -15,8 +15,11 @@ import org.lwjgl.opengl.GL13; import game.Game; import game.Game.FileMode; +import game.dimension.DimType; +import game.dimension.Dimension; import game.entity.npc.Alignment; import game.entity.npc.CharacterInfo; +import game.entity.npc.EntityHuman; import game.entity.npc.EntityNPC; import game.entity.npc.SpeciesInfo; import game.entity.types.EntityLiving; @@ -28,9 +31,12 @@ import game.gui.element.Label; import game.gui.element.ListEntry; import game.gui.element.Slider; import game.gui.element.Textbox; +import game.gui.element.TransparentBox; import game.gui.element.Textbox.Action; +import game.init.EntityEggInfo; import game.init.EntityRegistry; import game.init.SpeciesRegistry; +import game.init.UniverseRegistry; import game.init.SpeciesRegistry.ModelType; import game.log.Log; import game.network.Player; @@ -43,9 +49,11 @@ import game.renderer.ItemRenderer; import game.renderer.entity.RenderManager; import game.renderer.texture.EntityTexManager; import game.renderer.texture.TextureUtil; +import game.rng.Random; import game.util.FileCallback; import game.util.FileUtils; import game.util.SkinConverter; +import game.util.Util; import game.window.Button; public class GuiChar extends GuiList @@ -284,9 +292,12 @@ public class GuiChar extends GuiList // private ActButton convertButton2; private ActButton templateButton; private DragAdjust adjust; + private ActButton dimButton; + private TransparentBox descLines; private float yaw = -15.0f; private float pitch = -15.0f; private boolean waiting = true; + private int dimension; private GuiChar() { } @@ -304,7 +315,7 @@ public class GuiChar extends GuiList this.load(null, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel()); this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() { public void use(ActButton elem, Mode action) { - GuiChar.this.gm.showDirDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", new File("skins"), new FileCallback() { + GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", new File("skins"), new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, new File("skins"), false)) GuiChar.this.gm.displayGuiScreen(GuiChar.this); @@ -314,7 +325,7 @@ public class GuiChar extends GuiList }, "Importieren: Standard")); this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() { public void use(ActButton elem, Mode action) { - GuiChar.this.gm.showDirDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", new File("skins"), new FileCallback() { + GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", new File("skins"), new FileCallback() { public void selected(File file) { if(SkinConverter.convertSkin(file, new File("skins"), true)) GuiChar.this.gm.displayGuiScreen(GuiChar.this); @@ -370,7 +381,7 @@ public class GuiChar extends GuiList this.add(new ActButton(width - 396 + (z % 2) * 198, 36 + 28 * (z / 2), 194, 24, new ActButton.Callback() { public void use(ActButton elem, Mode action) { if(GuiChar.this.gm.thePlayer != null) { - GuiChar.this.gm.displayGuiScreen(null); +// GuiChar.this.gm.displayGuiScreen(null); GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(species.clazz))); // for(ActButton btn : speciesBtns) { // btn.enabled = btn != elem; @@ -410,8 +421,12 @@ public class GuiChar extends GuiList this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true)); this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() { public void use(ActButton elem, Mode action) { - if(GuiChar.this.gm.thePlayer != null) - GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR)); + if(GuiChar.this.gm.thePlayer != null) { + GuiChar.this.gm.waitForServer(); + Dimension dim = // GuiChar.this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : + UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension); + GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, dim.getDimensionId())); + } } }, "Charakter erstellen")); Textbox nameField = this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, Player.MAX_NICK_LENGTH, true, new Textbox.Callback() { @@ -430,6 +445,42 @@ public class GuiChar extends GuiList // this.convertButton1.enabled = false; // this.convertButton2.enabled = false; this.templateButton.enabled = false; + this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); + EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.gm.thePlayer == null ? EntityRegistry.getEntityString(EntityHuman.class) : EntityRegistry.getEntityString(this.gm.thePlayer)); + if(egg != null && egg.origin != null) { + Dimension dim = UniverseRegistry.getDimension(egg.origin); + if(dim != null) { + for(int z = 0; z < UniverseRegistry.getBaseDimensions().size(); z++) { + if(UniverseRegistry.getBaseDimensions().get(z).getDimensionId() == dim.getDimensionId()) { + this.dimension = z; + break; + } + } + } + } + this.dimButton = this.add(new ActButton(width - 396, height - 300, 392, 24, new ActButton.Callback() { + public void use(ActButton elem, Mode mode) { + if(mode == Mode.TERTIARY) { + GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size()); + } +// else if(GuiChar.this.dimension == Integer.MAX_VALUE) { +// GuiChar.this.dimension = mode == Mode.SECONDARY ? UniverseRegistry.getBaseDimensions().size() - 1 : 0; +// } +// else { + if(mode == Mode.SECONDARY) { + if(--GuiChar.this.dimension < 0) + GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1; + } + else { + if(++GuiChar.this.dimension >= UniverseRegistry.getBaseDimensions().size()) + GuiChar.this.dimension = 0; + } +// } + GuiChar.this.setDimButton(); + } + }, "")); + this.descLines = this.add(new TransparentBox(width - 396, height - 300 + 24, 392, 160, "", false)); + this.setDimButton(); } public void selectSkin(BufferedImage img, ModelType model) @@ -437,6 +488,18 @@ public class GuiChar extends GuiList this.gm.getNetHandler().addToSendQueue(new CPacketSkin(img, model)); } + private void setDimButton() { + Dimension dim = /* this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : */ UniverseRegistry.getBaseDimensions().get(this.dimension); + this.dimButton.setText( // (dim == Space.INSTANCE ? "" : +// ((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? + /* "Vorlage" : */ (dim.getType() == DimType.PLANET ? "Heimplanet" : "Heimdimension") + ": " + +// (dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() : + dim.getFormattedName(false)); + String name = dim.getFormattedName(true); + int index = name.indexOf(" / "); + this.descLines.setText(index >= 0 ? Util.buildLines(name.substring(index + " / ".length()).split(" / ")) : ""); + } + public void onGuiClosed() { this.unload(); diff --git a/java/src/game/gui/GuiLoading.java b/java/src/game/gui/GuiLoading.java index 5a6d7a3..5ec0ddc 100644 --- a/java/src/game/gui/GuiLoading.java +++ b/java/src/game/gui/GuiLoading.java @@ -43,6 +43,26 @@ public class GuiLoading extends Gui { }); } + public static GuiLoading makeIntermittentTask(final Server server) { + return new GuiLoading("Lade Welt ...", new Callback() { + public void poll(Game gm, GuiLoading gui) { + int progress = server.getProgress(); +// if(progress == -2) { +// gm.displayGuiScreen(null); +// return; +// } + if(progress < 0) { + gui.resetBar(); + } + else { + gui.setBar(null, "Chunks", Math.max(1, server.getTotal())); + gui.setProgress(progress); + } + gui.setTask(server.getMessage()); + } + }); + } + public static GuiLoading makeSaveTask(final Server server) { return new GuiLoading("Speichere Welt ...", new Callback() { public void poll(Game gm, GuiLoading gui) { diff --git a/java/src/game/gui/world/GuiCreate.java b/java/src/game/gui/world/GuiCreate.java index 6643e06..b24974b 100755 --- a/java/src/game/gui/world/GuiCreate.java +++ b/java/src/game/gui/world/GuiCreate.java @@ -3,9 +3,6 @@ package game.gui.world; import java.io.File; import game.color.TextColor; -import game.dimension.DimType; -import game.dimension.Dimension; -import game.dimension.Space; import game.gui.Gui; import game.gui.element.ActButton; import game.gui.element.ActButton.Mode; @@ -13,169 +10,157 @@ import game.gui.element.Label; import game.gui.element.NavButton; import game.gui.element.Textbox; import game.gui.element.Textbox.Action; -import game.gui.element.TransparentBox; -import game.init.Config; -import game.init.UniverseRegistry; -import game.log.Log; -import game.nbt.NBTLoader; -import game.nbt.NBTTagCompound; import game.network.Player; -import game.rng.Random; -import game.util.Util; import game.world.Region; -import game.world.World; public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback { public static final GuiCreate INSTANCE = new GuiCreate(); - private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3"; - private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!"; - private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_"; +// private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3"; +// private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!"; +// private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_"; private Textbox worldNameField; - private Textbox worldSeedField; +// private Textbox worldSeedField; private Textbox worldUserField; - private ActButton dimButton; private ActButton createButton; private Label actionLabel; private Label nameLabel; private Label userLabel; - private Label seed; - private Label decoded; - private TransparentBox descLines; +// private Label seed; +// private Label decoded; private boolean alreadyGenerated; private boolean fileExists; - private int dimension; - private static long getSeed(String str) { - if(str == null || str.isEmpty()) - return (new Random()).longv(); - try { - return Long.parseLong(str); - } - catch(NumberFormatException e) { - } - long seed = 0L; - if(str.length() <= 9) { - for(int z = 0; z < str.length(); z++) { - seed <<= 7; - char c = str.charAt(z); - if(c >= 0x80) { - seed = -1L; - break; - } - seed |= (long)c; - } - } - else if(str.length() == 10) { - String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS; - for(int z = 0; z < str.length(); z++) { - seed <<= 6; - int idx = ch.indexOf(str.charAt(z)); - if(idx == -1) { - seed = -1L; - break; - } - seed |= (long)idx; - } - if(seed != -1L) - seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L; - } - else if(str.length() <= 12) { - for(int z = 0; z < str.length(); z++) { - seed <<= 5; - int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z))); - if(idx == -1) { - seed = -1L; - break; - } - seed |= (long)idx; - } - if(seed != -1L) - seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L; - } - else { - seed = -1L; - } - if(seed == -1L) { - seed = 0L; - for(int z = 0; z < str.length(); z++) { - seed <<= 7; - seed |= (long)((char)(str.charAt(z) & 0x7f)); - } - seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L; - } - return seed; - } - - private static String decodeSeed(long seed, String def) { - if(seed == 0L) - return (def == null ? ("" + seed) : def); - if((seed & 0x8000000000000000L) == 0L) { - String str = ""; - long value = seed; - while(value != 0L) { - char c = (char)(value & 0x7fL); - if(c < 32 || c > 126) - return (def == null ? ("" + seed) : def); - str = c + str; - value >>= 7; - } - try { - Long.parseLong(str); - } - catch(NumberFormatException e) { - return str; - } - return (def == null ? ("" + seed) : def); - } - String chset; - int len; - int shift; - long mask; - long type = (seed >> 60) & 0xf; - switch((int)type) { - case 0x8: - chset = MBASE32_CHARS; - len = 11; - shift = 5; - mask = 0x1fL; - break; - case 0x9: - chset = MBASE32_CHARS; - len = 12; - shift = 5; - mask = 0x1fL; - break; - case 0xa: - chset = MBASE64A_CHARS; - len = 10; - shift = 6; - mask = 0x3fL; - break; - case 0xb: - chset = MBASE64B_CHARS; - len = 10; - shift = 6; - mask = 0x3fL; - break; - default: - return (def == null ? ("" + seed) : def); - } - String str = ""; - for(int z = 0; z < len; z++) { - str = chset.charAt((int)(seed & mask)) + str; - seed >>= shift; - } - try { - Long.parseLong(str); - } - catch(NumberFormatException e) { - return str; - } - return (def == null ? ("" + seed) : def); - } +// private static long getSeed(String str) { +// if(str == null || str.isEmpty()) +// return (new Random()).longv(); +// try { +// return Long.parseLong(str); +// } +// catch(NumberFormatException e) { +// } +// long seed = 0L; +// if(str.length() <= 9) { +// for(int z = 0; z < str.length(); z++) { +// seed <<= 7; +// char c = str.charAt(z); +// if(c >= 0x80) { +// seed = -1L; +// break; +// } +// seed |= (long)c; +// } +// } +// else if(str.length() == 10) { +// String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS; +// for(int z = 0; z < str.length(); z++) { +// seed <<= 6; +// int idx = ch.indexOf(str.charAt(z)); +// if(idx == -1) { +// seed = -1L; +// break; +// } +// seed |= (long)idx; +// } +// if(seed != -1L) +// seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L; +// } +// else if(str.length() <= 12) { +// for(int z = 0; z < str.length(); z++) { +// seed <<= 5; +// int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z))); +// if(idx == -1) { +// seed = -1L; +// break; +// } +// seed |= (long)idx; +// } +// if(seed != -1L) +// seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L; +// } +// else { +// seed = -1L; +// } +// if(seed == -1L) { +// seed = 0L; +// for(int z = 0; z < str.length(); z++) { +// seed <<= 7; +// seed |= (long)((char)(str.charAt(z) & 0x7f)); +// } +// seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L; +// } +// return seed; +// } +// +// private static String decodeSeed(long seed, String def) { +// if(seed == 0L) +// return (def == null ? ("" + seed) : def); +// if((seed & 0x8000000000000000L) == 0L) { +// String str = ""; +// long value = seed; +// while(value != 0L) { +// char c = (char)(value & 0x7fL); +// if(c < 32 || c > 126) +// return (def == null ? ("" + seed) : def); +// str = c + str; +// value >>= 7; +// } +// try { +// Long.parseLong(str); +// } +// catch(NumberFormatException e) { +// return str; +// } +// return (def == null ? ("" + seed) : def); +// } +// String chset; +// int len; +// int shift; +// long mask; +// long type = (seed >> 60) & 0xf; +// switch((int)type) { +// case 0x8: +// chset = MBASE32_CHARS; +// len = 11; +// shift = 5; +// mask = 0x1fL; +// break; +// case 0x9: +// chset = MBASE32_CHARS; +// len = 12; +// shift = 5; +// mask = 0x1fL; +// break; +// case 0xa: +// chset = MBASE64A_CHARS; +// len = 10; +// shift = 6; +// mask = 0x3fL; +// break; +// case 0xb: +// chset = MBASE64B_CHARS; +// len = 10; +// shift = 6; +// mask = 0x3fL; +// break; +// default: +// return (def == null ? ("" + seed) : def); +// } +// String str = ""; +// for(int z = 0; z < len; z++) { +// str = chset.charAt((int)(seed & mask)) + str; +// seed >>= shift; +// } +// try { +// Long.parseLong(str); +// } +// catch(NumberFormatException e) { +// return str; +// } +// return (def == null ? ("" + seed) : def); +// } private GuiCreate() { @@ -183,22 +168,22 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba public void updateScreen() { - String text = this.worldSeedField.getText(); - if(text.isEmpty()) { - this.seed.setText("Startwert [Zufällig]"); - this.decoded.setText("Dekodiert: -"); - } - else { - this.seed.setText("Startwert [" + getSeed(text) + "]"); - try { - this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-")); - } - catch(NumberFormatException e) { - this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-")); - } - } +// String text = this.worldSeedField.getText(); +// if(text.isEmpty()) { +// this.seed.setText("Startwert [Zufällig]"); +// this.decoded.setText("Dekodiert: -"); +// } +// else { +// this.seed.setText("Startwert [" + getSeed(text) + "]"); +// try { +// this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-")); +// } +// catch(NumberFormatException e) { +// this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-")); +// } +// } this.fileExists = false; - text = this.worldNameField.getText().trim(); + String text = this.worldNameField.getText().trim(); this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty(); if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists())) this.createButton.enabled = false; @@ -208,94 +193,56 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba public void init(int width, int height) { - UniverseRegistry.clear(); +// UniverseRegistry.clear(); this.alreadyGenerated = false; - this.dimension = Integer.MAX_VALUE; this.createButton = this.add(new ActButton(0, 340, 160, 24, this, "Welt erstellen")); this.add(new NavButton(164, 340, 160, 24, GuiWorlds.INSTANCE, "Abbrechen")); - this.dimButton = this.add(new ActButton(0, 220, 324, 24, this, "")); this.worldNameField = this.add(new Textbox(20, 40, 284, 24, 256, true, this, GuiWorlds.VALID_FILE, "")); this.worldNameField.setSelected(); - this.worldSeedField = this.add(new Textbox(20, 140, 284, 24, 256, true, this, "")); +// this.worldSeedField = this.add(new Textbox(20, 140, 284, 24, 256, true, this, "")); this.worldUserField = this.add(new Textbox(20, 90, 284, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, "")); this.createButton.enabled = false; this.actionLabel = this.add(new Label(20, 20, 284, 20, this.getFolderDesc(), true)); this.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true)); - this.seed = this.add(new Label(20, 120, 284, 20, "", true)); - this.decoded = this.add(new Label(20, 164, 284, 20, "", true)); - this.descLines = this.add(new TransparentBox(0, 244, 324, 160, "", false)); +// this.seed = this.add(new Label(20, 120, 284, 20, "", true)); +// this.decoded = this.add(new Label(20, 164, 284, 20, "", true)); this.shift(); - this.setDimButton(); } public String getTitle() { return "Neue Welt erstellen"; } - - private void setDimButton() { - Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : UniverseRegistry.getBaseDimensions().get(this.dimension); - this.dimButton.setText((dim == Space.INSTANCE ? "" : - ((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? - "Vorlage" : (dim.getType() == DimType.PLANET ? "Heimplanet" : "Dimension")) + ": ")) + - (dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() : - dim.getFormattedName(false))); - String name = dim.getFormattedName(true); - int index = name.indexOf(" / "); - this.descLines.setText(index >= 0 ? Util.buildLines(name.substring(index + " / ".length()).split(" / ")) : ""); - } public void use(ActButton button, Mode mode) { - if (button == this.createButton) - { +// if (button == this.createButton) +// { // this.gm.displayGuiScreen(null); - if(this.alreadyGenerated) - return; - this.alreadyGenerated = true; - Config.clear(); - UniverseRegistry.clear(); - Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : - UniverseRegistry.getBaseDimensions().get(this.dimension); - dim.setSeed(getSeed(this.worldSeedField.getText())); - File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim()); - Dimension[] dims = UniverseRegistry.registerPreset(dim); - Config.set("spawnDim", "" + dims[0].getDimensionId(), null); - Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText()); - for(Dimension sdim : dims) { - NBTTagCompound data = new NBTTagCompound(); - data.setTag("Generator", sdim.toNbt(true)); - File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName()); - chunkDir.mkdirs(); - File file = new File(chunkDir, "data.nbt"); - try { - NBTLoader.writeGZip(data, file); - } - catch(Exception e) { - Log.IO.error(e, "Konnte Weltdaten nicht speichern"); - } - } - this.gm.startServer(dir, this.worldUserField.getText()); - } - else if (button == this.dimButton) - { - if(mode == Mode.TERTIARY) { - this.dimension = Integer.MAX_VALUE; - } - else if(this.dimension == Integer.MAX_VALUE) { - this.dimension = mode == Mode.SECONDARY ? UniverseRegistry.getBaseDimensions().size() - 1 : 0; - } - else { - if(mode == Mode.SECONDARY) { - if(--this.dimension < 0) - this.dimension = Integer.MAX_VALUE; - } - else { - if(++this.dimension >= UniverseRegistry.getBaseDimensions().size()) - this.dimension = Integer.MAX_VALUE; - } - } - this.setDimButton(); - } + if(this.alreadyGenerated) + return; + this.alreadyGenerated = true; +// Config.clear(); +// UniverseRegistry.clear(); +// dim.setSeed(getSeed(this.worldSeedField.getText())); + File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim()); +// Dimension[] dims = UniverseRegistry.registerPreset(dim); +// Config.set("spawnDim", "" + dims[0].getDimensionId(), null); +// Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText()); +// for(Dimension sdim : dims) { +// NBTTagCompound data = new NBTTagCompound(); +// data.setTag("Generator", sdim.toNbt(true)); +// File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName()); +// chunkDir.mkdirs(); +// File file = new File(chunkDir, "data.nbt"); +// try { +// NBTLoader.writeGZip(data, file); +// } +// catch(Exception e) { +// Log.IO.error(e, "Konnte Weltdaten nicht speichern"); +// } +// } + this.gm.startServer(dir, this.worldUserField.getText()); +// } } public void use(Textbox elem, Action action) { diff --git a/java/src/game/gui/world/GuiWorlds.java b/java/src/game/gui/world/GuiWorlds.java index 45d1568..8c9dcbc 100755 --- a/java/src/game/gui/world/GuiWorlds.java +++ b/java/src/game/gui/world/GuiWorlds.java @@ -24,11 +24,11 @@ import game.gui.element.GuiList; import game.gui.element.ListEntry; import game.gui.element.NavButton; import game.gui.world.GuiEdit.Callback; -import game.init.Config; import game.init.UniverseRegistry; import game.log.Log; import game.nbt.NBTLoader; import game.nbt.NBTTagCompound; +import game.nbt.NBTTagList; import game.renderer.Drawing; import game.util.CharValidator; import game.util.FileCallback; @@ -45,12 +45,14 @@ public class GuiWorlds extends GuiList implements ActButton. protected class SaveInfo implements Comparable, ListEntry { private final String file; private final String name; + private final String dim; private final long seed; private final FolderInfo info; - public SaveInfo(String file, String name, long seed, FolderInfo info) { + public SaveInfo(String file, String name, String dim, long seed, FolderInfo info) { this.file = file; this.name = name; + this.dim = dim; this.seed = seed; this.info = info; } @@ -60,7 +62,11 @@ public class GuiWorlds extends GuiList implements ActButton. } public String getName() { - return this.name == null ? "" : this.name; + return this.name; + } + + public String getDim() { + return this.dim == null ? "" : this.dim; } public String getUser() { @@ -118,8 +124,9 @@ public class GuiWorlds extends GuiList implements ActButton. public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover) { Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" : - (TextColor.GRAY + " - " + TextColor.RESET + this.getUser())), x + 2, y, 0xffffffff); - Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getName()) + (TextColor.GRAY + " - " + TextColor.RESET + this.getUser() + (this.getName() != null ? TextColor.GRAY + " (" + TextColor.RESET + this.getName() + TextColor.GRAY + ")" : ""))), + x + 2, y, 0xffffffff); + Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getDim()) , x + 2, y + 18, 0xff808080); Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" : "Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") + @@ -177,11 +184,31 @@ public class GuiWorlds extends GuiList implements ActButton. if(info == null) info = Converter.convertMapFormat(file, null); if(info == null) { - this.elements.add(new SaveInfo(file.getName(), null, + this.elements.add(new SaveInfo(file.getName(), null, null, 0L, new FolderInfo(World.START_TIME, null, file.lastModified(), null, null))); continue; } - Dimension dim = info.legacy != null ? null : UniverseRegistry.getDimension(Config.spawnDim); + Dimension dim = null; + String name = null; + if(info.legacy == null && info.user != null) { + File dat = new File(new File(new File(Region.SAVE_DIR, file.getName()), "players"), info.user + ".nbt"); + if(dat.exists() && dat.isFile()) { + try { + NBTTagCompound tag = NBTLoader.readGZip(dat); + int selected = tag.getInteger("selected"); + NBTTagList list = tag.getTagList("characters", 10); + selected = Math.min(selected, list.tagCount() - 1); + if(selected >= 0) { + NBTTagCompound etag = list.getCompoundTagAt(selected); + dim = UniverseRegistry.getDimension(etag.getInteger("Dimension")); + if(etag.hasKey("CustomName", 8) && etag.getString("CustomName").length() > 0) + name = etag.getString("CustomName"); + } + } + catch(Exception e) { + } + } + } if(dim != null) { File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"), dim.getDimensionName()), "data.nbt"); @@ -191,7 +218,7 @@ public class GuiWorlds extends GuiList implements ActButton. catch(Exception e) { } } - this.elements.add(new SaveInfo(file.getName(), dim == null ? null : TextColor.stripCodes(dim.getFormattedName(true)), + this.elements.add(new SaveInfo(file.getName(), name, dim == null ? null : TextColor.stripCodes(dim.getFormattedName(true)), dim == null ? 0L : dim.getSeed(), info)); } // this.saveList = list; @@ -222,7 +249,7 @@ public class GuiWorlds extends GuiList implements ActButton. public void use(ActButton elem, ActButton.Mode action) { if(GuiWorlds.this.gm.theWorld != null) return; - GuiWorlds.this.gm.showDirDialog(FileMode.DIRECTORY_LOAD, "Welt importieren", Region.SAVE_DIR, new FileCallback() { + GuiWorlds.this.gm.showFileDialog(FileMode.DIRECTORY_LOAD, "Welt importieren", Region.SAVE_DIR, new FileCallback() { public void selected(File file) { File parent = file.getParentFile(); if(parent != null && Region.SAVE_DIR.getAbsoluteFile().equals(parent.getAbsoluteFile())) { diff --git a/java/src/game/init/Config.java b/java/src/game/init/Config.java index 8b00d69..dfd0a51 100755 --- a/java/src/game/init/Config.java +++ b/java/src/game/init/Config.java @@ -14,7 +14,6 @@ import java.util.TreeMap; import game.Server; import game.packet.SPacketWorld; import game.util.ExtMath; -import game.world.World; import game.world.WorldServer; public abstract class Config { @@ -353,8 +352,8 @@ public abstract class Config { public static boolean auth = false; // @Var(name = "teleportForAll") // public static boolean teleportAllowed = false; - @Var(name = "preload_chunks_all") // Vorsicht Lag!! - public static boolean preloadAll = false; +// @Var(name = "preload_chunks_all") // Vorsicht Lag!! +// public static boolean preloadAll = false; // @Var(name = "maxPolygonalPoints") // public static int polygonalPoints = -1; @@ -377,6 +376,8 @@ public abstract class Config { public static int igniteChance = 100; @Var(name = "spawnRadius") public static int spawnRadius = 10; + @Var(name = "originRadius", min = 0, max = 262144) + public static int originRadius = 16384; @Var(name = "respawnTime") public static int respawnTime = 0; @Var(name = "hurtCooldown") @@ -451,15 +452,17 @@ public abstract class Config { public static int maxMobs = 120; @Var(name = "eggLayTime") public static int eggTimer = 6000; + @Var(name = "connectionTimeout", min = 10, max = 300) + public static int timeout = 30; - @Var(name = "spawnX", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1) - public static int spawnX = 0; - @Var(name = "spawnY", min = -1, max = 511) - public static int spawnY = 64; - @Var(name = "spawnZ", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1) - public static int spawnZ = 0; - @Var(name = "spawnDim") - public static int spawnDim = 0; +// @Var(name = "spawnX", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1) +// public static int spawnX = 0; +// @Var(name = "spawnY", min = -1, max = 511) +// public static int spawnY = 64; +// @Var(name = "spawnZ", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1) +// public static int spawnZ = 0; +// @Var(name = "spawnDim") +// public static int spawnDim = 0; @Var(name = "gravity", callback = WorldCallback.class) public static float gravity = 1.0f; diff --git a/java/src/game/init/UniverseRegistry.java b/java/src/game/init/UniverseRegistry.java index 6b80708..da0571e 100755 --- a/java/src/game/init/UniverseRegistry.java +++ b/java/src/game/init/UniverseRegistry.java @@ -752,7 +752,7 @@ public abstract class UniverseRegistry { dtag.merge(ptag); dim.fromNbt(dtag); dim.setCustomName(name); - BASE_DIMS.add(dim); +// BASE_DIMS.add(dim); return dim; } diff --git a/java/src/game/network/ClientPlayer.java b/java/src/game/network/ClientPlayer.java index 9bbbebe..8333332 100755 --- a/java/src/game/network/ClientPlayer.java +++ b/java/src/game/network/ClientPlayer.java @@ -1530,6 +1530,10 @@ public class ClientPlayer extends NetHandler this.characterList.put(data.getKey(), data.getValue()); } this.selectedCharacter = packet.getSelected(); + if(this.gameController.charEditor && this.selectedCharacter >= 0) { + this.gameController.charEditor = false; + this.gameController.displayGuiScreen(null); + } } public void handleKeepAlive(SPacketKeepAlive packetIn) diff --git a/java/src/game/network/Player.java b/java/src/game/network/Player.java index 6514dc0..833b878 100755 --- a/java/src/game/network/Player.java +++ b/java/src/game/network/Player.java @@ -125,6 +125,7 @@ import game.world.Region; import game.world.State; import game.world.Vec3i; import game.world.World; +import game.world.WorldPos; import game.world.WorldServer; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; @@ -2493,13 +2494,18 @@ public class Player extends NetHandler implements ICrafting, Executor NetHandler.checkThread(packetIn, this, this.server); CPacketAction.Action action = packetIn.getAction(); - if(this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR)) + if(this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR)) // { +// if(this.local && action == Action.CLOSE_EDITOR) +// this.server.setDone(); return; +// } switch (action) { case OPEN_EDITOR: this.charEditor = true; +// if(this.local) +// this.server.resetProgress(); NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class); if(!this.characters.isEmpty() && this.selected >= 0) this.characters.set(this.selected, tag); @@ -2507,13 +2513,24 @@ public class Player extends NetHandler implements ICrafting, Executor this.sendPacket(new SPacketCharacterList(this.selected)); break; - case CLOSE_EDITOR: + case CLOSE_EDITOR: { this.charEditor = false; this.selected = this.characters.size(); this.characters.add(new NBTTagCompound()); - this.entity.teleport(this.server.getRandomSpawnPosition()); + WorldServer world = this.server.getWorld(packetIn.getAuxData()); + world = world == null ? this.server.getSpace() : world; + WorldPos origin = new WorldPos(world.rand.range(-Config.originRadius, Config.originRadius), 64, world.rand.range(-Config.originRadius, Config.originRadius), + world.dimension.getDimensionId()); + this.entity.setOrigin(origin); + Position pos = this.server.getRandomSpawnPosition(origin); + if(Config.preloadLocal && this.local && this.server.getPlayers().size() == 1) + this.server.preload(world, (int)pos.x, (int)pos.z); + this.entity.teleport(pos); this.sendPacket(new SPacketCharacterList(this.selected, this.selected, new PlayerCharacter(this.entity.getCustomNameTag(), this.entity.getDescription(), this.entity.getAlignment(), this.entity.worldObj.dimension.getFormattedName(false), this.entity.getPosition(), EntityRegistry.getEntityName(EntityRegistry.getEntityString(this.entity)), this.entity.experienceLevel))); +// if(this.local) +// this.server.setDone(); break; + } case SELECT_CHARACTER: int index = packetIn.getAuxData(); diff --git a/java/src/game/util/Splashes.java b/java/src/game/util/Splashes.java index c35c9df..47a33c6 100644 --- a/java/src/game/util/Splashes.java +++ b/java/src/game/util/Splashes.java @@ -277,8 +277,8 @@ public abstract class Splashes { "Erfüllt Erwartungen!", "Spielen am PC seit 1873!", "Ghoughpteighbteau tchoghs!", - "Déjà vu!", - "Déjà vu!", + "Deja vu!", + "Deja vu!", "Hab deine Nase!", "Haley liebt Elan!", "Hat keine Angst vor der großen, schwarzen Fledermaus!", diff --git a/java/src/game/world/Converter.java b/java/src/game/world/Converter.java index 1677d69..319ae2a 100755 --- a/java/src/game/world/Converter.java +++ b/java/src/game/world/Converter.java @@ -1332,10 +1332,6 @@ public final class Converter { // Config.setVar("noRespawn", "" + nbt.getBoolean("hardcore"), false); // int id = nbt.getInteger("GameType"); // Config.set("defaultNoCreative", "" + (id == 2 || id == 0), false); - Config.set("spawnX", "" + tag.getInteger("SpawnX"), null); - Config.set("spawnY", "" + tag.getInteger("SpawnY"), null); - Config.set("spawnZ", "" + tag.getInteger("SpawnZ"), null); - Config.set("spawnDim", "" + 1, null); Log.JNI.info("Speichere neue level.nbt ..."); Region.saveWorldInfo(dir, wtime, user); if(tag.hasKey("Player", 10)) { @@ -1371,13 +1367,23 @@ public final class Converter { player.setInteger("SpawnDim", 1); // player.setBoolean("SpawnForced", force); } + player.setInteger("OriginX", tag.getInteger("SpawnX")); + player.setInteger("OriginY", tag.getInteger("SpawnY")); + player.setInteger("OriginZ", tag.getInteger("SpawnZ")); + player.setInteger("OriginDim", 1); + player.setString("CustomName", user.substring(0, 1).toUpperCase() + user.substring(1)); + NBTTagCompound plr = new NBTTagCompound(); + plr.setInteger("selected", 0); + NBTTagList list = new NBTTagList(); + list.appendTag(player); + plr.setTag("characters", list); // if(mode >= 0) // player.setBoolean("creative", mode == 1); Log.JNI.info("Speichere neue Spielerdaten " + user.toLowerCase() + ".nbt ..."); File pdat = new File(new File(dir, "players"), user.toLowerCase() + ".nbt"); try { pdat.getParentFile().mkdirs(); - NBTLoader.writeGZip(player, pdat); + NBTLoader.writeGZip(plr, pdat); } catch(Exception e) { Log.JNI.error(e, "Fehler beim Schreiben von " + pdat);