char origins

This commit is contained in:
Sen 2025-03-28 14:30:37 +01:00
parent 3316c42ed8
commit e9ede99d84
14 changed files with 516 additions and 373 deletions

View file

@ -427,6 +427,7 @@ public class Game implements IThreadListener {
private String buffer = ""; private String buffer = "";
private boolean crashed; private boolean crashed;
private boolean waitingForFile; private boolean waitingForFile;
private boolean refreshing;
private final int[] tickTimes = new int[240]; private final int[] tickTimes = new int[240];
private final long[] frames = new long[240]; private final long[] frames = new long[240];
@ -1152,6 +1153,7 @@ public class Game implements IThreadListener {
public void displayGuiScreen(Gui gui) public void displayGuiScreen(Gui gui)
{ {
if(!this.refreshing)
this.waitingForFile = false; this.waitingForFile = false;
if(this.thePlayer != null) if(this.thePlayer != null)
this.thePlayer.setScreenClosed(); this.thePlayer.setScreenClosed();
@ -1870,9 +1872,9 @@ public class Game implements IThreadListener {
fb_x = x; fb_x = x;
fb_y = y; fb_y = y;
if(this.open != null) { if(this.open != null) {
boolean flag = this.waitingForFile; this.refreshing = true;
this.displayGuiScreen(this.open); this.displayGuiScreen(this.open);
this.waitingForFile = flag; this.refreshing = false;
} }
if(!fullscreen) { if(!fullscreen) {
xsize = x; xsize = x;
@ -1976,9 +1978,9 @@ public class Game implements IThreadListener {
private void redraw() { private void redraw() {
if(this.open != null) { if(this.open != null) {
boolean flag = this.waitingForFile; this.refreshing = true;
this.displayGuiScreen(this.open); this.displayGuiScreen(this.open);
this.waitingForFile = flag; this.refreshing = false;
} }
} }
@ -2411,6 +2413,11 @@ public class Game implements IThreadListener {
// } // }
} }
public void waitForServer() {
if(this.server != null)
this.displayGuiScreen(GuiLoading.makeIntermittentTask(this.server));
}
private void startSound(boolean load) { private void startSound(boolean load) {
if(load) if(load)
SoundEvent.loadSounds(); SoundEvent.loadSounds();
@ -3331,7 +3338,7 @@ public class Game implements IThreadListener {
FILE_SAVE; 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) if(this.waitingForFile)
return; return;
this.waitingForFile = true; this.waitingForFile = true;
@ -3372,9 +3379,15 @@ public class Game implements IThreadListener {
} }
} }
catch(Throwable e) { 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) {
Game.this.waitingForFile = false;
return; return;
} }
if(output != null) {
if(mode == FileMode.FILE_LOAD_MULTI) { if(mode == FileMode.FILE_LOAD_MULTI) {
final List<File> files = Lists.newArrayList(); final List<File> files = Lists.newArrayList();
for(String out : output.split(":")) { for(String out : output.split(":")) {
@ -3382,8 +3395,10 @@ public class Game implements IThreadListener {
if(file.isFile()) if(file.isFile())
files.add(file); files.add(file);
} }
if(files.isEmpty()) if(files.isEmpty()) {
Game.this.waitingForFile = false;
return; return;
}
Game.this.schedule(new Runnable() { Game.this.schedule(new Runnable() {
public void run() { public void run() {
if(Game.this.waitingForFile) { if(Game.this.waitingForFile) {
@ -3399,20 +3414,28 @@ public class Game implements IThreadListener {
File file = new File(output); File file = new File(output);
switch(mode) { switch(mode) {
case DIRECTORY_LOAD: case DIRECTORY_LOAD:
if(!file.isDirectory()) if(!file.isDirectory()) {
Game.this.waitingForFile = false;
return; return;
}
break; break;
case DIRECTORY_SAVE: case DIRECTORY_SAVE:
if(file.exists() && !file.isDirectory()) if(file.exists() && !file.isDirectory()) {
Game.this.waitingForFile = false;
return; return;
}
break; break;
case FILE_LOAD: case FILE_LOAD:
if(!file.isFile()) if(!file.isFile()) {
Game.this.waitingForFile = false;
return; return;
}
break; break;
case FILE_SAVE: case FILE_SAVE:
if(file.exists() && !file.isFile()) if(file.exists() && !file.isFile()) {
Game.this.waitingForFile = false;
return; return;
}
break; break;
} }
Game.this.schedule(new Runnable() { Game.this.schedule(new Runnable() {
@ -3424,7 +3447,6 @@ public class Game implements IThreadListener {
}); });
} }
} }
}
}, "Zenity listener").start(); }, "Zenity listener").start();
} }
} }

View file

@ -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 done = 0;
int total = Config.distance * 2 + 1; int total = Config.distance * 2 + 1;
total *= total; total *= total;
this.setMessage("Landschaft wird generiert"); this.setMessage("Landschaft wird generiert");
this.startProgress(false, total); this.startProgress(false, total);
WorldServer world = this.getWorld(Config.spawnDim); // WorldServer world = this.getWorld(Config.spawnDim);
world = world == null ? this.space : world; // world = world == null ? this.space : world;
int bx = (int)entity.posX >> 4; bx = bx >> 4;
int bz = (int)entity.posZ >> 4; bz = bz >> 4;
long last = System.currentTimeMillis(); long last = System.currentTimeMillis();
for(int x = -Config.distance; x <= Config.distance && this.running; x++) { for(int x = -Config.distance; x <= Config.distance && this.running; x++) {
for(int z = -Config.distance; z <= Config.distance && this.running; z++) { for(int z = -Config.distance; z <= Config.distance && this.running; z++) {
@ -382,6 +382,14 @@ public final class Server implements Runnable, IThreadListener {
this.setProgress(-1); this.setProgress(-1);
} }
// public void resetProgress() {
// this.setProgress(-1);
// }
//
// public void setDone() {
// this.setProgress(-2);
// }
private void tick() { private void tick() {
// boolean pause = this.paused; // boolean pause = this.paused;
// this.paused = this.pause; // this.paused = this.pause;
@ -614,26 +622,26 @@ public final class Server implements Runnable, IThreadListener {
return Thread.currentThread() == this.serverThread; return Thread.currentThread() == this.serverThread;
} }
private void movePlayerToSpawn(EntityNPC player) { // private void movePlayerToSpawn(EntityNPC player) {
BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ); // BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
int radius = Config.spawnRadius; // int radius = Config.spawnRadius;
if(radius > 0) { // if(radius > 0) {
pos = ((WorldServer)player.worldObj).getTopSolidOrLiquidBlock(pos.add( // 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), 0,
ExtMath.clampi(player.worldObj.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1))); // 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, // player.moveToBlockPosAndAngles(pos, radius > 0 ? (-180.0f + player.worldObj.rand.floatv() * 360.0f) : Config.spawnYaw,
radius > 0 ? 0.0f : Config.spawnPitch); // radius > 0 ? 0.0f : Config.spawnPitch);
while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty() // while(radius >= 0 && !player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox()).isEmpty()
&& player.posY < 511.0D) { // && player.posY < 511.0D) {
player.setPosition(player.posX, player.posY + 1.0D, player.posZ); // player.setPosition(player.posX, player.posY + 1.0D, player.posZ);
} // }
} // }
public Position getRandomSpawnPosition() { public Position getRandomSpawnPosition(WorldPos origin) {
WorldServer world = this.getWorld(Config.spawnDim); WorldServer world = this.getWorld(origin.getDimension());
world = world == null ? this.space : world; world = world == null ? this.space : world;
BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ); BlockPos pos = origin;
int radius = Config.spawnRadius; int radius = Config.spawnRadius;
if(radius > 0) { if(radius > 0) {
pos = world.getTopSolidOrLiquidBlock(pos.add( pos = world.getTopSolidOrLiquidBlock(pos.add(
@ -703,8 +711,8 @@ public final class Server implements Runnable, IThreadListener {
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": " + 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() + "'") + ")"); + 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())) if(Config.preloadLocal && conn.isLocal() && this.players.size() == 1)
this.preload(player); 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 SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem)); conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
@ -807,6 +815,7 @@ public final class Server implements Runnable, IThreadListener {
old.getServerWorld().removePlayer(old); old.getServerWorld().removePlayer(old);
old.getServerWorld().removePlayerEntityDangerously(old); old.getServerWorld().removePlayerEntityDangerously(old);
WorldPos bed = old.getSpawnPoint(); WorldPos bed = old.getSpawnPoint();
WorldPos origin = old.getOrigin();
BlockPos spawn = null; BlockPos spawn = null;
String message = null; String message = null;
WorldServer world = bed == null ? this.space : this.getWorld(bed.getDimension()); WorldServer world = bed == null ? this.space : this.getWorld(bed.getDimension());
@ -824,19 +833,22 @@ public final class Server implements Runnable, IThreadListener {
} }
} }
if(bed == null) { if(bed == null) {
world = this.getWorld(Config.spawnDim); world = this.getWorld(origin.getDimension());
world = world == null ? this.space : world; world = world == null ? this.space : world;
} }
EntityNPC nplayer = conn.createPlayer(world, EntityRegistry.getEntityString(old)); EntityNPC nplayer = conn.createPlayer(world, EntityRegistry.getEntityString(old));
conn.clonePlayer(old); conn.clonePlayer(old);
nplayer.setId(old.getId()); nplayer.setId(old.getId());
nplayer.setOrigin(origin);
if(bed != null) { if(bed != null) {
nplayer.setLocationAndAngles((double)((float)spawn.getX() + 0.5F), (double)((float)spawn.getY() + 0.1F), nplayer.setLocationAndAngles((double)((float)spawn.getX() + 0.5F), (double)((float)spawn.getY() + 0.1F),
(double)((float)spawn.getZ() + 0.5F), 0.0F, 0.0F); (double)((float)spawn.getZ() + 0.5F), 0.0F, 0.0F);
nplayer.setSpawnPoint(bed); nplayer.setSpawnPoint(bed);
} }
else { 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); world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) { if(bed != null ? Config.checkBed : Config.spawnRadius >= 0) {
@ -1027,7 +1039,7 @@ public final class Server implements Runnable, IThreadListener {
if(this.endpoint != null) if(this.endpoint != null)
this.unsetLanEndpoint(); this.unsetLanEndpoint();
// throw new IllegalStateException("Eingangspunkt bereits gesetzt"); // 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<Channel>() { this.endpoint = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(NioServerSocketChannel.class)).childHandler(new ChannelInitializer<Channel>() {
protected void initChannel(Channel channel) throws Exception { protected void initChannel(Channel channel) throws Exception {
try { try {
@ -1035,7 +1047,7 @@ public final class Server implements Runnable, IThreadListener {
} }
catch(ChannelException e) { 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)"splitter", (ChannelHandler)(new PacketSplitter()))
.addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true))) .addLast((String)"decoder", (ChannelHandler)(new PacketDecoder(true)))
.addLast((String)"prepender", (ChannelHandler)(new PacketPrepender())) .addLast((String)"prepender", (ChannelHandler)(new PacketPrepender()))

View file

@ -3,17 +3,13 @@ package game.command.commands;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import game.command.CommandEnvironment; import game.command.CommandEnvironment;
import game.collect.Lists;
import game.command.Command; import game.command.Command;
import game.command.Executor; import game.command.Executor;
import game.command.RunException; import game.command.RunException;
import game.command.StringCompleter; import game.command.StringCompleter;
import game.entity.Entity; import game.entity.Entity;
import game.init.Config;
import game.init.UniverseRegistry; import game.init.UniverseRegistry;
import game.world.BlockPos;
import game.world.Position; import game.world.Position;
import game.world.WorldServer;
public class CommandWarp extends Command { public class CommandWarp extends Command {
public CommandWarp() { public CommandWarp() {
@ -21,9 +17,9 @@ public class CommandWarp extends Command {
this.addString("warp", true, new StringCompleter() { this.addString("warp", true, new StringCompleter() {
public Collection<String> complete(CommandEnvironment env) { public Collection<String> complete(CommandEnvironment env) {
List<String> warps = Lists.newArrayList("spawn"); // List<String> warps = Lists.newArrayList("spawn");
warps.addAll(env.getServer().getWarps().keySet()); // warps.addAll(env.getServer().getWarps().keySet());
return warps; return env.getServer().getWarps().keySet();
} }
}); });
@ -31,23 +27,23 @@ public class CommandWarp extends Command {
} }
public Object exec(CommandEnvironment env, Executor exec, String warp, List<Entity> entities) { public Object exec(CommandEnvironment env, Executor exec, String warp, List<Entity> entities) {
Position pos; Position // pos;
if(warp.equals("spawn")) { // if(warp.equals("spawn")) {
WorldServer world = env.getServer().getWorld(Config.spawnDim); // WorldServer world = env.getServer().getWorld(Config.spawnDim);
world = world == null ? env.getServer().getSpace() : world; // world = world == null ? env.getServer().getSpace() : world;
int y = Config.spawnY; // int y = Config.spawnY;
while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511) // while(world.getState(new BlockPos(Config.spawnX, y, Config.spawnZ)).getBlock().getMaterial().blocksMovement() && y < 511)
y++; // y++;
pos = new Position(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d, // pos = new Position(Config.spawnX + 0.5d, (double)y, Config.spawnZ + 0.5d,
Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId()); // Config.spawnYaw, Config.spawnPitch, world.dimension.getDimensionId());
} // }
else { // else {
pos = env.getServer().getWarps().get(warp); pos = env.getServer().getWarps().get(warp);
if(pos == null) if(pos == null)
throw new RunException("Warp '%s' existiert nicht", warp); throw new RunException("Warp '%s' existiert nicht", warp);
else if(env.getServer().getWorld(pos.dim) == null) else if(env.getServer().getWorld(pos.dim) == null)
throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim); throw new RunException("Warp '%s' hat kein Level (%s)", warp, pos.dim);
} // }
for(Entity entity : entities) { for(Entity entity : entities) {
entity.teleport(pos); 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)); 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));

View file

@ -24,6 +24,7 @@ import game.ai.EntityAIWatchClosest2;
import game.audio.MovingSoundMinecartRiding; import game.audio.MovingSoundMinecartRiding;
import game.block.Block; import game.block.Block;
import game.block.BlockBed; import game.block.BlockBed;
import game.dimension.Space;
import game.enchantment.Enchantment; import game.enchantment.Enchantment;
import game.enchantment.EnchantmentHelper; import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource; import game.entity.DamageSource;
@ -218,6 +219,7 @@ public abstract class EntityNPC extends EntityLiving
public double chasingPosX; public double chasingPosX;
public double chasingPosY; public double chasingPosY;
public double chasingPosZ; public double chasingPosZ;
private WorldPos originPos = new WorldPos(0, 64, 0, Space.INSTANCE.getDimensionId());
private WorldPos spawnPos; private WorldPos spawnPos;
// private BlockPos startMinecartRidingCoordinate; // private BlockPos startMinecartRidingCoordinate;
public int experienceLevel; public int experienceLevel;
@ -3542,6 +3544,12 @@ public abstract class EntityNPC extends EntityLiving
// this.spawnForced = tagCompund.getBoolean("SpawnForced"); // 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.foodStats.readNBT(tagCompund);
// this.readCapabilitiesFromNBT(tagCompund); // this.readCapabilitiesFromNBT(tagCompund);
this.flying = tagCompund.getBoolean("flying") && (this.hasEffect(Potion.FLYING) || this.canNaturallyFly()); this.flying = tagCompund.getBoolean("flying") && (this.hasEffect(Potion.FLYING) || this.canNaturallyFly());
@ -3664,6 +3672,14 @@ public abstract class EntityNPC extends EntityLiving
// tagCompound.setBoolean("SpawnForced", this.spawnForced); // 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.foodStats.writeNBT(tagCompound);
// this.writeCapabilitiesToNBT(tagCompound); // this.writeCapabilitiesToNBT(tagCompound);
tagCompound.setBoolean("flying", this.flying); tagCompound.setBoolean("flying", this.flying);
@ -3964,6 +3980,16 @@ public abstract class EntityNPC extends EntityLiving
this.spawnPos = pos; this.spawnPos = pos;
} }
public WorldPos getOrigin()
{
return this.originPos;
}
public void setOrigin(WorldPos pos)
{
this.originPos = pos;
}
// /** // /**
// * Will trigger the specified trigger. // * Will trigger the specified trigger.
// */ // */

View file

@ -15,8 +15,11 @@ import org.lwjgl.opengl.GL13;
import game.Game; import game.Game;
import game.Game.FileMode; import game.Game.FileMode;
import game.dimension.DimType;
import game.dimension.Dimension;
import game.entity.npc.Alignment; import game.entity.npc.Alignment;
import game.entity.npc.CharacterInfo; import game.entity.npc.CharacterInfo;
import game.entity.npc.EntityHuman;
import game.entity.npc.EntityNPC; import game.entity.npc.EntityNPC;
import game.entity.npc.SpeciesInfo; import game.entity.npc.SpeciesInfo;
import game.entity.types.EntityLiving; import game.entity.types.EntityLiving;
@ -28,9 +31,12 @@ import game.gui.element.Label;
import game.gui.element.ListEntry; import game.gui.element.ListEntry;
import game.gui.element.Slider; import game.gui.element.Slider;
import game.gui.element.Textbox; import game.gui.element.Textbox;
import game.gui.element.TransparentBox;
import game.gui.element.Textbox.Action; import game.gui.element.Textbox.Action;
import game.init.EntityEggInfo;
import game.init.EntityRegistry; import game.init.EntityRegistry;
import game.init.SpeciesRegistry; import game.init.SpeciesRegistry;
import game.init.UniverseRegistry;
import game.init.SpeciesRegistry.ModelType; import game.init.SpeciesRegistry.ModelType;
import game.log.Log; import game.log.Log;
import game.network.Player; import game.network.Player;
@ -43,9 +49,11 @@ import game.renderer.ItemRenderer;
import game.renderer.entity.RenderManager; import game.renderer.entity.RenderManager;
import game.renderer.texture.EntityTexManager; import game.renderer.texture.EntityTexManager;
import game.renderer.texture.TextureUtil; import game.renderer.texture.TextureUtil;
import game.rng.Random;
import game.util.FileCallback; import game.util.FileCallback;
import game.util.FileUtils; import game.util.FileUtils;
import game.util.SkinConverter; import game.util.SkinConverter;
import game.util.Util;
import game.window.Button; import game.window.Button;
public class GuiChar extends GuiList<GuiChar.SkinEntry> public class GuiChar extends GuiList<GuiChar.SkinEntry>
@ -284,9 +292,12 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
// private ActButton convertButton2; // private ActButton convertButton2;
private ActButton templateButton; private ActButton templateButton;
private DragAdjust adjust; private DragAdjust adjust;
private ActButton dimButton;
private TransparentBox descLines;
private float yaw = -15.0f; private float yaw = -15.0f;
private float pitch = -15.0f; private float pitch = -15.0f;
private boolean waiting = true; private boolean waiting = true;
private int dimension;
private GuiChar() { private GuiChar() {
} }
@ -304,7 +315,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
this.load(null, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel()); this.load(null, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel());
this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() { this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) { 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) { public void selected(File file) {
if(SkinConverter.convertSkin(file, new File("skins"), false)) if(SkinConverter.convertSkin(file, new File("skins"), false))
GuiChar.this.gm.displayGuiScreen(GuiChar.this); GuiChar.this.gm.displayGuiScreen(GuiChar.this);
@ -314,7 +325,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
}, "Importieren: Standard")); }, "Importieren: Standard"));
this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() { this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) { 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) { public void selected(File file) {
if(SkinConverter.convertSkin(file, new File("skins"), true)) if(SkinConverter.convertSkin(file, new File("skins"), true))
GuiChar.this.gm.displayGuiScreen(GuiChar.this); GuiChar.this.gm.displayGuiScreen(GuiChar.this);
@ -370,7 +381,7 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
this.add(new ActButton(width - 396 + (z % 2) * 198, 36 + 28 * (z / 2), 194, 24, new ActButton.Callback() { 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) { public void use(ActButton elem, Mode action) {
if(GuiChar.this.gm.thePlayer != null) { 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))); GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(species.clazz)));
// for(ActButton btn : speciesBtns) { // for(ActButton btn : speciesBtns) {
// btn.enabled = btn != elem; // btn.enabled = btn != elem;
@ -410,8 +421,12 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true)); 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() { this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() {
public void use(ActButton elem, Mode action) { public void use(ActButton elem, Mode action) {
if(GuiChar.this.gm.thePlayer != null) if(GuiChar.this.gm.thePlayer != null) {
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR)); 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")); }, "Charakter erstellen"));
Textbox nameField = this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, Player.MAX_NICK_LENGTH, true, new Textbox.Callback() { 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<GuiChar.SkinEntry>
// this.convertButton1.enabled = false; // this.convertButton1.enabled = false;
// this.convertButton2.enabled = false; // this.convertButton2.enabled = false;
this.templateButton.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) public void selectSkin(BufferedImage img, ModelType model)
@ -437,6 +488,18 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
this.gm.getNetHandler().addToSendQueue(new CPacketSkin(img, model)); 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() public void onGuiClosed()
{ {
this.unload(); this.unload();

View file

@ -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) { public static GuiLoading makeSaveTask(final Server server) {
return new GuiLoading("Speichere Welt ...", new Callback() { return new GuiLoading("Speichere Welt ...", new Callback() {
public void poll(Game gm, GuiLoading gui) { public void poll(Game gm, GuiLoading gui) {

View file

@ -3,9 +3,6 @@ package game.gui.world;
import java.io.File; import java.io.File;
import game.color.TextColor; import game.color.TextColor;
import game.dimension.DimType;
import game.dimension.Dimension;
import game.dimension.Space;
import game.gui.Gui; import game.gui.Gui;
import game.gui.element.ActButton; import game.gui.element.ActButton;
import game.gui.element.ActButton.Mode; import game.gui.element.ActButton.Mode;
@ -13,169 +10,157 @@ import game.gui.element.Label;
import game.gui.element.NavButton; import game.gui.element.NavButton;
import game.gui.element.Textbox; import game.gui.element.Textbox;
import game.gui.element.Textbox.Action; 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.network.Player;
import game.rng.Random;
import game.util.Util;
import game.world.Region; import game.world.Region;
import game.world.World;
public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback
{ {
public static final GuiCreate INSTANCE = new GuiCreate(); public static final GuiCreate INSTANCE = new GuiCreate();
private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3"; // private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!"; // private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_"; // private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
private Textbox worldNameField; private Textbox worldNameField;
private Textbox worldSeedField; // private Textbox worldSeedField;
private Textbox worldUserField; private Textbox worldUserField;
private ActButton dimButton;
private ActButton createButton; private ActButton createButton;
private Label actionLabel; private Label actionLabel;
private Label nameLabel; private Label nameLabel;
private Label userLabel; private Label userLabel;
private Label seed; // private Label seed;
private Label decoded; // private Label decoded;
private TransparentBox descLines;
private boolean alreadyGenerated; private boolean alreadyGenerated;
private boolean fileExists; private boolean fileExists;
private int dimension;
private static long getSeed(String str) { // private static long getSeed(String str) {
if(str == null || str.isEmpty()) // if(str == null || str.isEmpty())
return (new Random()).longv(); // return (new Random()).longv();
try { // try {
return Long.parseLong(str); // return Long.parseLong(str);
} // }
catch(NumberFormatException e) { // catch(NumberFormatException e) {
} // }
long seed = 0L; // long seed = 0L;
if(str.length() <= 9) { // if(str.length() <= 9) {
for(int z = 0; z < str.length(); z++) { // for(int z = 0; z < str.length(); z++) {
seed <<= 7; // seed <<= 7;
char c = str.charAt(z); // char c = str.charAt(z);
if(c >= 0x80) { // if(c >= 0x80) {
seed = -1L; // seed = -1L;
break; // break;
} // }
seed |= (long)c; // seed |= (long)c;
} // }
} // }
else if(str.length() == 10) { // else if(str.length() == 10) {
String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS; // String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS;
for(int z = 0; z < str.length(); z++) { // for(int z = 0; z < str.length(); z++) {
seed <<= 6; // seed <<= 6;
int idx = ch.indexOf(str.charAt(z)); // int idx = ch.indexOf(str.charAt(z));
if(idx == -1) { // if(idx == -1) {
seed = -1L; // seed = -1L;
break; // break;
} // }
seed |= (long)idx; // seed |= (long)idx;
} // }
if(seed != -1L) // if(seed != -1L)
seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L; // seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L;
} // }
else if(str.length() <= 12) { // else if(str.length() <= 12) {
for(int z = 0; z < str.length(); z++) { // for(int z = 0; z < str.length(); z++) {
seed <<= 5; // seed <<= 5;
int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z))); // int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z)));
if(idx == -1) { // if(idx == -1) {
seed = -1L; // seed = -1L;
break; // break;
} // }
seed |= (long)idx; // seed |= (long)idx;
} // }
if(seed != -1L) // if(seed != -1L)
seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L; // seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L;
} // }
else { // else {
seed = -1L; // seed = -1L;
} // }
if(seed == -1L) { // if(seed == -1L) {
seed = 0L; // seed = 0L;
for(int z = 0; z < str.length(); z++) { // for(int z = 0; z < str.length(); z++) {
seed <<= 7; // seed <<= 7;
seed |= (long)((char)(str.charAt(z) & 0x7f)); // seed |= (long)((char)(str.charAt(z) & 0x7f));
} // }
seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L; // seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L;
} // }
return seed; // return seed;
} // }
//
private static String decodeSeed(long seed, String def) { // private static String decodeSeed(long seed, String def) {
if(seed == 0L) // if(seed == 0L)
return (def == null ? ("" + seed) : def); // return (def == null ? ("" + seed) : def);
if((seed & 0x8000000000000000L) == 0L) { // if((seed & 0x8000000000000000L) == 0L) {
String str = ""; // String str = "";
long value = seed; // long value = seed;
while(value != 0L) { // while(value != 0L) {
char c = (char)(value & 0x7fL); // char c = (char)(value & 0x7fL);
if(c < 32 || c > 126) // if(c < 32 || c > 126)
return (def == null ? ("" + seed) : def); // return (def == null ? ("" + seed) : def);
str = c + str; // str = c + str;
value >>= 7; // value >>= 7;
} // }
try { // try {
Long.parseLong(str); // Long.parseLong(str);
} // }
catch(NumberFormatException e) { // catch(NumberFormatException e) {
return str; // return str;
} // }
return (def == null ? ("" + seed) : def); // return (def == null ? ("" + seed) : def);
} // }
String chset; // String chset;
int len; // int len;
int shift; // int shift;
long mask; // long mask;
long type = (seed >> 60) & 0xf; // long type = (seed >> 60) & 0xf;
switch((int)type) { // switch((int)type) {
case 0x8: // case 0x8:
chset = MBASE32_CHARS; // chset = MBASE32_CHARS;
len = 11; // len = 11;
shift = 5; // shift = 5;
mask = 0x1fL; // mask = 0x1fL;
break; // break;
case 0x9: // case 0x9:
chset = MBASE32_CHARS; // chset = MBASE32_CHARS;
len = 12; // len = 12;
shift = 5; // shift = 5;
mask = 0x1fL; // mask = 0x1fL;
break; // break;
case 0xa: // case 0xa:
chset = MBASE64A_CHARS; // chset = MBASE64A_CHARS;
len = 10; // len = 10;
shift = 6; // shift = 6;
mask = 0x3fL; // mask = 0x3fL;
break; // break;
case 0xb: // case 0xb:
chset = MBASE64B_CHARS; // chset = MBASE64B_CHARS;
len = 10; // len = 10;
shift = 6; // shift = 6;
mask = 0x3fL; // mask = 0x3fL;
break; // break;
default: // default:
return (def == null ? ("" + seed) : def); // return (def == null ? ("" + seed) : def);
} // }
String str = ""; // String str = "";
for(int z = 0; z < len; z++) { // for(int z = 0; z < len; z++) {
str = chset.charAt((int)(seed & mask)) + str; // str = chset.charAt((int)(seed & mask)) + str;
seed >>= shift; // seed >>= shift;
} // }
try { // try {
Long.parseLong(str); // Long.parseLong(str);
} // }
catch(NumberFormatException e) { // catch(NumberFormatException e) {
return str; // return str;
} // }
return (def == null ? ("" + seed) : def); // return (def == null ? ("" + seed) : def);
} // }
private GuiCreate() private GuiCreate()
{ {
@ -183,22 +168,22 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba
public void updateScreen() public void updateScreen()
{ {
String text = this.worldSeedField.getText(); // String text = this.worldSeedField.getText();
if(text.isEmpty()) { // if(text.isEmpty()) {
this.seed.setText("Startwert [Zufällig]"); // this.seed.setText("Startwert [Zufällig]");
this.decoded.setText("Dekodiert: -"); // this.decoded.setText("Dekodiert: -");
} // }
else { // else {
this.seed.setText("Startwert [" + getSeed(text) + "]"); // this.seed.setText("Startwert [" + getSeed(text) + "]");
try { // try {
this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-")); // this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-"));
} // }
catch(NumberFormatException e) { // catch(NumberFormatException e) {
this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-")); // this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-"));
} // }
} // }
this.fileExists = false; this.fileExists = false;
text = this.worldNameField.getText().trim(); String text = this.worldNameField.getText().trim();
this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty(); this.createButton.enabled = !text.isEmpty() && !this.worldUserField.getText().isEmpty();
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists())) if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
this.createButton.enabled = false; 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) public void init(int width, int height)
{ {
UniverseRegistry.clear(); // UniverseRegistry.clear();
this.alreadyGenerated = false; this.alreadyGenerated = false;
this.dimension = Integer.MAX_VALUE;
this.createButton = this.add(new ActButton(0, 340, 160, 24, this, "Welt erstellen")); 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.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 = this.add(new Textbox(20, 40, 284, 24, 256, true, this, GuiWorlds.VALID_FILE, ""));
this.worldNameField.setSelected(); 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.worldUserField = this.add(new Textbox(20, 90, 284, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, ""));
this.createButton.enabled = false; this.createButton.enabled = false;
this.actionLabel = this.add(new Label(20, 20, 284, 20, this.getFolderDesc(), true)); 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.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true));
this.seed = this.add(new Label(20, 120, 284, 20, "", true)); // this.seed = this.add(new Label(20, 120, 284, 20, "", true));
this.decoded = this.add(new Label(20, 164, 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.shift(); this.shift();
this.setDimButton();
} }
public String getTitle() { public String getTitle() {
return "Neue Welt erstellen"; 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) public void use(ActButton button, Mode mode)
{ {
if (button == this.createButton) // if (button == this.createButton)
{ // {
// this.gm.displayGuiScreen(null); // this.gm.displayGuiScreen(null);
if(this.alreadyGenerated) if(this.alreadyGenerated)
return; return;
this.alreadyGenerated = true; this.alreadyGenerated = true;
Config.clear(); // Config.clear();
UniverseRegistry.clear(); // UniverseRegistry.clear();
Dimension dim = this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : // dim.setSeed(getSeed(this.worldSeedField.getText()));
UniverseRegistry.getBaseDimensions().get(this.dimension);
dim.setSeed(getSeed(this.worldSeedField.getText()));
File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim()); File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim());
Dimension[] dims = UniverseRegistry.registerPreset(dim); // Dimension[] dims = UniverseRegistry.registerPreset(dim);
Config.set("spawnDim", "" + dims[0].getDimensionId(), null); // Config.set("spawnDim", "" + dims[0].getDimensionId(), null);
Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText()); // Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText());
for(Dimension sdim : dims) { // for(Dimension sdim : dims) {
NBTTagCompound data = new NBTTagCompound(); // NBTTagCompound data = new NBTTagCompound();
data.setTag("Generator", sdim.toNbt(true)); // data.setTag("Generator", sdim.toNbt(true));
File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName()); // File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName());
chunkDir.mkdirs(); // chunkDir.mkdirs();
File file = new File(chunkDir, "data.nbt"); // File file = new File(chunkDir, "data.nbt");
try { // try {
NBTLoader.writeGZip(data, file); // NBTLoader.writeGZip(data, file);
} // }
catch(Exception e) { // catch(Exception e) {
Log.IO.error(e, "Konnte Weltdaten nicht speichern"); // Log.IO.error(e, "Konnte Weltdaten nicht speichern");
} // }
} // }
this.gm.startServer(dir, this.worldUserField.getText()); 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();
}
} }
public void use(Textbox elem, Action action) { public void use(Textbox elem, Action action) {

View file

@ -24,11 +24,11 @@ import game.gui.element.GuiList;
import game.gui.element.ListEntry; import game.gui.element.ListEntry;
import game.gui.element.NavButton; import game.gui.element.NavButton;
import game.gui.world.GuiEdit.Callback; import game.gui.world.GuiEdit.Callback;
import game.init.Config;
import game.init.UniverseRegistry; import game.init.UniverseRegistry;
import game.log.Log; import game.log.Log;
import game.nbt.NBTLoader; import game.nbt.NBTLoader;
import game.nbt.NBTTagCompound; import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.renderer.Drawing; import game.renderer.Drawing;
import game.util.CharValidator; import game.util.CharValidator;
import game.util.FileCallback; import game.util.FileCallback;
@ -45,12 +45,14 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry { protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
private final String file; private final String file;
private final String name; private final String name;
private final String dim;
private final long seed; private final long seed;
private final FolderInfo info; 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.file = file;
this.name = name; this.name = name;
this.dim = dim;
this.seed = seed; this.seed = seed;
this.info = info; this.info = info;
} }
@ -60,7 +62,11 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
} }
public String getName() { public String getName() {
return this.name == null ? "<?>" : this.name; return this.name;
}
public String getDim() {
return this.dim == null ? "<?>" : this.dim;
} }
public String getUser() { public String getUser() {
@ -118,8 +124,9 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover) public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
{ {
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" : Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
(TextColor.GRAY + " - " + TextColor.RESET + this.getUser())), x + 2, y, 0xffffffff); (TextColor.GRAY + " - " + TextColor.RESET + this.getUser() + (this.getName() != null ? TextColor.GRAY + " (" + TextColor.RESET + this.getName() + TextColor.GRAY + ")" : ""))),
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getName()) x + 2, y, 0xffffffff);
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : this.getDim())
, x + 2, y + 18, 0xff808080); , x + 2, y + 18, 0xff808080);
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" : Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") + "Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
@ -177,11 +184,31 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
if(info == null) if(info == null)
info = Converter.convertMapFormat(file, null); info = Converter.convertMapFormat(file, null);
if(info == 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))); 0L, new FolderInfo(World.START_TIME, null, file.lastModified(), null, null)));
continue; 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) { if(dim != null) {
File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"), File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"),
dim.getDimensionName()), "data.nbt"); dim.getDimensionName()), "data.nbt");
@ -191,7 +218,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
catch(Exception e) { 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)); dim == null ? 0L : dim.getSeed(), info));
} }
// this.saveList = list; // this.saveList = list;
@ -222,7 +249,7 @@ public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.
public void use(ActButton elem, ActButton.Mode action) { public void use(ActButton elem, ActButton.Mode action) {
if(GuiWorlds.this.gm.theWorld != null) if(GuiWorlds.this.gm.theWorld != null)
return; 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) { public void selected(File file) {
File parent = file.getParentFile(); File parent = file.getParentFile();
if(parent != null && Region.SAVE_DIR.getAbsoluteFile().equals(parent.getAbsoluteFile())) { if(parent != null && Region.SAVE_DIR.getAbsoluteFile().equals(parent.getAbsoluteFile())) {

View file

@ -14,7 +14,6 @@ import java.util.TreeMap;
import game.Server; import game.Server;
import game.packet.SPacketWorld; import game.packet.SPacketWorld;
import game.util.ExtMath; import game.util.ExtMath;
import game.world.World;
import game.world.WorldServer; import game.world.WorldServer;
public abstract class Config { public abstract class Config {
@ -353,8 +352,8 @@ public abstract class Config {
public static boolean auth = false; public static boolean auth = false;
// @Var(name = "teleportForAll") // @Var(name = "teleportForAll")
// public static boolean teleportAllowed = false; // public static boolean teleportAllowed = false;
@Var(name = "preload_chunks_all") // Vorsicht Lag!! // @Var(name = "preload_chunks_all") // Vorsicht Lag!!
public static boolean preloadAll = false; // public static boolean preloadAll = false;
// @Var(name = "maxPolygonalPoints") // @Var(name = "maxPolygonalPoints")
// public static int polygonalPoints = -1; // public static int polygonalPoints = -1;
@ -377,6 +376,8 @@ public abstract class Config {
public static int igniteChance = 100; public static int igniteChance = 100;
@Var(name = "spawnRadius") @Var(name = "spawnRadius")
public static int spawnRadius = 10; public static int spawnRadius = 10;
@Var(name = "originRadius", min = 0, max = 262144)
public static int originRadius = 16384;
@Var(name = "respawnTime") @Var(name = "respawnTime")
public static int respawnTime = 0; public static int respawnTime = 0;
@Var(name = "hurtCooldown") @Var(name = "hurtCooldown")
@ -451,15 +452,17 @@ public abstract class Config {
public static int maxMobs = 120; public static int maxMobs = 120;
@Var(name = "eggLayTime") @Var(name = "eggLayTime")
public static int eggTimer = 6000; 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) // @Var(name = "spawnX", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1)
public static int spawnX = 0; // public static int spawnX = 0;
@Var(name = "spawnY", min = -1, max = 511) // @Var(name = "spawnY", min = -1, max = 511)
public static int spawnY = 64; // public static int spawnY = 64;
@Var(name = "spawnZ", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1) // @Var(name = "spawnZ", min = -World.MAX_SIZE + 1, max = World.MAX_SIZE - 1)
public static int spawnZ = 0; // public static int spawnZ = 0;
@Var(name = "spawnDim") // @Var(name = "spawnDim")
public static int spawnDim = 0; // public static int spawnDim = 0;
@Var(name = "gravity", callback = WorldCallback.class) @Var(name = "gravity", callback = WorldCallback.class)
public static float gravity = 1.0f; public static float gravity = 1.0f;

View file

@ -752,7 +752,7 @@ public abstract class UniverseRegistry {
dtag.merge(ptag); dtag.merge(ptag);
dim.fromNbt(dtag); dim.fromNbt(dtag);
dim.setCustomName(name); dim.setCustomName(name);
BASE_DIMS.add(dim); // BASE_DIMS.add(dim);
return dim; return dim;
} }

View file

@ -1530,6 +1530,10 @@ public class ClientPlayer extends NetHandler
this.characterList.put(data.getKey(), data.getValue()); this.characterList.put(data.getKey(), data.getValue());
} }
this.selectedCharacter = packet.getSelected(); this.selectedCharacter = packet.getSelected();
if(this.gameController.charEditor && this.selectedCharacter >= 0) {
this.gameController.charEditor = false;
this.gameController.displayGuiScreen(null);
}
} }
public void handleKeepAlive(SPacketKeepAlive packetIn) public void handleKeepAlive(SPacketKeepAlive packetIn)

View file

@ -125,6 +125,7 @@ import game.world.Region;
import game.world.State; import game.world.State;
import game.world.Vec3i; import game.world.Vec3i;
import game.world.World; import game.world.World;
import game.world.WorldPos;
import game.world.WorldServer; import game.world.WorldServer;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
@ -2493,13 +2494,18 @@ public class Player extends NetHandler implements ICrafting, Executor
NetHandler.checkThread(packetIn, this, this.server); NetHandler.checkThread(packetIn, this, this.server);
CPacketAction.Action action = packetIn.getAction(); 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; return;
// }
switch (action) switch (action)
{ {
case OPEN_EDITOR: case OPEN_EDITOR:
this.charEditor = true; this.charEditor = true;
// if(this.local)
// this.server.resetProgress();
NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class); NBTTagCompound tag = this.server.swapPlayer(this, null, EntityHuman.class);
if(!this.characters.isEmpty() && this.selected >= 0) if(!this.characters.isEmpty() && this.selected >= 0)
this.characters.set(this.selected, tag); this.characters.set(this.selected, tag);
@ -2507,13 +2513,24 @@ public class Player extends NetHandler implements ICrafting, Executor
this.sendPacket(new SPacketCharacterList(this.selected)); this.sendPacket(new SPacketCharacterList(this.selected));
break; break;
case CLOSE_EDITOR: case CLOSE_EDITOR: {
this.charEditor = false; this.charEditor = false;
this.selected = this.characters.size(); this.selected = this.characters.size();
this.characters.add(new NBTTagCompound()); 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))); 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; break;
}
case SELECT_CHARACTER: case SELECT_CHARACTER:
int index = packetIn.getAuxData(); int index = packetIn.getAuxData();

View file

@ -277,8 +277,8 @@ public abstract class Splashes {
"Erfüllt Erwartungen!", "Erfüllt Erwartungen!",
"Spielen am PC seit 1873!", "Spielen am PC seit 1873!",
"Ghoughpteighbteau tchoghs!", "Ghoughpteighbteau tchoghs!",
"Déjà vu!", "Deja vu!",
"Déjà vu!", "Deja vu!",
"Hab deine Nase!", "Hab deine Nase!",
"Haley liebt Elan!", "Haley liebt Elan!",
"Hat keine Angst vor der großen, schwarzen Fledermaus!", "Hat keine Angst vor der großen, schwarzen Fledermaus!",

View file

@ -1332,10 +1332,6 @@ public final class Converter {
// Config.setVar("noRespawn", "" + nbt.getBoolean("hardcore"), false); // Config.setVar("noRespawn", "" + nbt.getBoolean("hardcore"), false);
// int id = nbt.getInteger("GameType"); // int id = nbt.getInteger("GameType");
// Config.set("defaultNoCreative", "" + (id == 2 || id == 0), false); // 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 ..."); Log.JNI.info("Speichere neue level.nbt ...");
Region.saveWorldInfo(dir, wtime, user); Region.saveWorldInfo(dir, wtime, user);
if(tag.hasKey("Player", 10)) { if(tag.hasKey("Player", 10)) {
@ -1371,13 +1367,23 @@ public final class Converter {
player.setInteger("SpawnDim", 1); player.setInteger("SpawnDim", 1);
// player.setBoolean("SpawnForced", force); // 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) // if(mode >= 0)
// player.setBoolean("creative", mode == 1); // player.setBoolean("creative", mode == 1);
Log.JNI.info("Speichere neue Spielerdaten " + user.toLowerCase() + ".nbt ..."); Log.JNI.info("Speichere neue Spielerdaten " + user.toLowerCase() + ".nbt ...");
File pdat = new File(new File(dir, "players"), user.toLowerCase() + ".nbt"); File pdat = new File(new File(dir, "players"), user.toLowerCase() + ".nbt");
try { try {
pdat.getParentFile().mkdirs(); pdat.getParentFile().mkdirs();
NBTLoader.writeGZip(player, pdat); NBTLoader.writeGZip(plr, pdat);
} }
catch(Exception e) { catch(Exception e) {
Log.JNI.error(e, "Fehler beim Schreiben von " + pdat); Log.JNI.error(e, "Fehler beim Schreiben von " + pdat);