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

@ -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<GuiChar.SkinEntry>
@ -284,9 +292,12 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
// 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<GuiChar.SkinEntry>
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<GuiChar.SkinEntry>
}, "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<GuiChar.SkinEntry>
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<GuiChar.SkinEntry>
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<GuiChar.SkinEntry>
// 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<GuiChar.SkinEntry>
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();

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

View file

@ -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) {

View file

@ -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<GuiWorlds.SaveInfo> implements ActButton.
protected class SaveInfo implements Comparable<SaveInfo>, 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<GuiWorlds.SaveInfo> 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<GuiWorlds.SaveInfo> 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<GuiWorlds.SaveInfo> 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<GuiWorlds.SaveInfo> 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<GuiWorlds.SaveInfo> 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())) {