diff --git a/java/src/game/Game.java b/java/src/game/Game.java index 3f6fa89..072e9e2 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -294,7 +294,7 @@ public class Game implements IThreadListener { public EntityNPC thePlayer; public HitPosition pointed; - @Variable(name = "chunk_view_distance", category = CVarCategory.WORLD, min = 2, max = 128, callback = DistanceFunction.class, display = "Sichtweite", unit = "Chunks") + @Variable(name = "chunk_view_distance", category = CVarCategory.WORLD, min = 2, max = 16 /* 128 */, callback = DistanceFunction.class, display = "Sichtweite", unit = "Chunks") public int renderDistance = 8; @Variable(name = "chunk_build_time", category = CVarCategory.WORLD, min = 1, max = 100, display = "Max. Zeit für Chunk-Bau pro Frame", unit = "ms") public int maxBuildTime = 8; @@ -2293,6 +2293,9 @@ public class Game implements IThreadListener { } } } + else { + this.displayGuiScreen(GuiMenu.INSTANCE); + } server = null; } diff --git a/java/src/game/Temp1.java b/java/src/game/Temp1.java index 7b4974d..59f9d10 100644 --- a/java/src/game/Temp1.java +++ b/java/src/game/Temp1.java @@ -1,21 +1,5 @@ - -//private static final String[] DISTANCES = new String[] {"Gruselig", "Winzig", "Gering", "Normal", "Weit"}; - - - - - - - - - - - - - - package game.gui.server; import game.SKC; diff --git a/java/src/game/command/ScriptArgs.java b/java/src/game/command/ScriptArgs.java index 6015240..88fcbdf 100644 --- a/java/src/game/command/ScriptArgs.java +++ b/java/src/game/command/ScriptArgs.java @@ -14,6 +14,7 @@ import game.entity.npc.EntityNPC; import game.entity.types.EntityLiving; import game.item.Item; import game.item.ItemStack; +import game.nbt.NBTTagCompound; import game.world.BlockPos; import game.world.State; import game.world.Vec3; @@ -403,4 +404,8 @@ public class ScriptArgs { public WorldServer getWorld(String name) { return this.getUnchecked(name); } + + public NBTTagCompound getTag(String name) { + return this.getUnchecked(name); + } } diff --git a/java/src/game/command/ScriptExecutable.java b/java/src/game/command/ScriptExecutable.java index 858ac7c..c8e2032 100644 --- a/java/src/game/command/ScriptExecutable.java +++ b/java/src/game/command/ScriptExecutable.java @@ -1,10 +1,14 @@ package game.command; +import java.util.Collection; import java.util.Map; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import game.command.DoubleParser.DefType; +import game.world.World; + public abstract class ScriptExecutable implements Executable { private final String name; private final Map parameters = Maps.newHashMap(); @@ -31,6 +35,62 @@ public abstract class ScriptExecutable implements Executable { return this; } + protected ScriptExecutable addParameter(ArgumentParser parser) { + return this.addParameter(parser.getName(), parser); + } + + protected ScriptExecutable addParameter(char shortName, ArgumentParser parser) { + return this.addParameter(parser.getName(), shortName, parser); + } + + protected ScriptExecutable addVector(String name, boolean defaulted) { + return this.addParameter(name, new DoubleParser("x", defaulted ? DefType.X : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE), new DoubleParser("y", defaulted ? DefType.Y : null, 0.0, (double)World.HEIGHT), new DoubleParser("z", defaulted ? DefType.Z : null, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE)); + } + + protected ScriptExecutable addWorld(String name, boolean defaulted) { + return this.addParameter(new WorldParser(name, false, defaulted)); + } + + protected ScriptExecutable addInt(String name, char shortName, int min, int max, int def) { + return this.addParameter(shortName, new IntParser(name, false, def, min, max, def)); + } + + protected ScriptExecutable addInt(String name, int min, int max, int def) { + return this.addParameter(new IntParser(name, false, def, min, max, def)); + } + + protected ScriptExecutable addFlag(String name, char shortName) { + return this.addParameter(name, shortName); + } + + protected ScriptExecutable addFlag(String name) { + return this.addParameter(name, name.charAt(0)); + } + + protected ScriptExecutable addEnum(String name, Object ... values) { + return this.addParameter(new EnumParser(name, null, values)); + } + + protected ScriptExecutable addEnumDef(String name, Object def, Object ... values) { + return this.addParameter(new EnumParser(name, null, values)); + } + + protected ScriptExecutable addEnum(String name, Collection values) { + return this.addEnum(name, (Object[])values.toArray(new String[values.size()])); + } + + protected ScriptExecutable addEnumDef(String name, Object def, Collection values) { + return this.addEnumDef(name, def, (Object[])values.toArray(new String[values.size()])); + } + + protected ScriptExecutable addTag(String name) { + return this.addParameter(new TagParser(name, null)); + } + + protected ScriptExecutable addTag(String name, char shortName) { + return this.addParameter(shortName, new TagParser(name, null)); + } + public Object exec(ScriptEnvironment env, ScriptArgs args) { return null; } diff --git a/java/src/game/command/TagParser.java b/java/src/game/command/TagParser.java new file mode 100644 index 0000000..e05cec6 --- /dev/null +++ b/java/src/game/command/TagParser.java @@ -0,0 +1,22 @@ +package game.command; + +import game.nbt.NBTException; +import game.nbt.NBTParser; +import game.nbt.NBTTagCompound; + +public class TagParser extends DefaultingParser { + public TagParser(String name, NBTTagCompound def, Object ... completions) { + super(name, def, completions); + } + + public NBTTagCompound parse(ScriptEnvironment env, String input) { + NBTTagCompound value; + try { + value = NBTParser.parseTag(input); + } + catch(NBTException e) { + throw new ScriptException(e, "Ungültiger NBT-Tag '%s'", input); + } + return value; + } +} diff --git a/java/src/game/command/commands/CommandSpawn.java b/java/src/game/command/commands/CommandSpawn.java index b6cb8d6..f5035f5 100644 --- a/java/src/game/command/commands/CommandSpawn.java +++ b/java/src/game/command/commands/CommandSpawn.java @@ -4,20 +4,15 @@ import java.util.Set; import com.google.common.collect.Sets; -import game.command.DoubleParser; -import game.command.DoubleParser.DefType; -import game.command.EnumParser; -import game.command.IntParser; import game.command.ScriptArgs; import game.command.ScriptEnvironment; import game.command.ScriptException; import game.command.ScriptExecutable; -import game.command.WorldParser; import game.entity.Entity; import game.entity.types.EntityLiving; import game.init.EntityRegistry; +import game.nbt.NBTTagCompound; import game.world.Vec3; -import game.world.World; import game.world.WorldServer; public class CommandSpawn extends ScriptExecutable { @@ -27,13 +22,14 @@ public class CommandSpawn extends ScriptExecutable { for(Class clazz : EntityRegistry.getAllClasses()) { names.add(EntityRegistry.getEntityString(clazz)); } - this.addParameter("type", new EnumParser("type", null, (Object[])names.toArray(new String[names.size()]))); + this.addEnum("type", names); this.setParamsOptional(); - this.addParameter("position", new DoubleParser("x", DefType.X, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE), new DoubleParser("y", DefType.Y, 0.0, (double)World.HEIGHT), new DoubleParser("z", DefType.Z, (double)(-World.MAX_SIZE), (double)World.MAX_SIZE)); - this.addParameter("dim", new WorldParser("dim", false, true)); - - this.addParameter("noinit", 'n'); - this.addParameter("count", 'c', new IntParser("count", false, 1, 1, 1024)); + this.addVector("position", true); + this.addWorld("dim", true); + this.addTag("tag"); + this.addFlag("noinit"); + this.addInt("count", 'c', 1, 1024, 1); + this.addTag("postTag", 'p'); } public Object exec(ScriptEnvironment env, ScriptArgs args) { @@ -42,14 +38,28 @@ public class CommandSpawn extends ScriptExecutable { Vec3 pos = args.getVector("position"); int count = args.getInt("count"); boolean init = !args.has("noinit"); + NBTTagCompound tag = args.getTag("tag"); + NBTTagCompound postTag = args.getTag("postTag"); for(int z = 0; z < count; z++) { Entity entity = EntityRegistry.createEntityByName(type, world); if(entity == null) throw new ScriptException("Objekt konnte nicht erzeugt werden"); entity.setLocationAndAngles(pos.xCoord, pos.yCoord, pos.zCoord, world.rand.floatv() * 360.0f, 0.0f); + if(tag != null) { + NBTTagCompound ent = new NBTTagCompound(); + entity.writeToNBT(ent); + ent.merge(tag); + entity.readFromNBT(ent); + } if(init && (entity instanceof EntityLiving)) ((EntityLiving)entity).onInitialSpawn(null); world.spawnEntityInWorld(entity); + if(postTag != null) { + NBTTagCompound ent = new NBTTagCompound(); + entity.writeToNBT(ent); + ent.merge(postTag); + entity.readFromNBT(ent); + } } env.getExecutor().logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false)); return null; diff --git a/java/src/game/gui/GuiDisplay.java b/java/src/game/gui/GuiDisplay.java index 44ded66..87f0d9c 100644 --- a/java/src/game/gui/GuiDisplay.java +++ b/java/src/game/gui/GuiDisplay.java @@ -2,14 +2,20 @@ package game.gui; import game.color.TextColor; import game.gui.element.Dropdown; +import game.gui.element.Element; import game.gui.element.Fill; import game.gui.element.Slider; import game.gui.element.Toggle; import game.util.Formatter; +import game.window.Button; import game.window.DisplayMode; import game.window.Window; public class GuiDisplay extends GuiOptions { + private static final String[] DISTANCES = new String[] {"Gruselig", "Winzig", "Gering", "Normal", "Weit"}; + + private Element distanceSlider; + protected GuiDisplay() { } @@ -66,7 +72,7 @@ public class GuiDisplay extends GuiOptions { this.addSelector("con_position", 30, 280, 440, 24); this.addSelector("gl_fov", 30, 360, 440, 24); - this.addSelector("chunk_view_distance", 30, 400, 440, 24); + this.distanceSlider = this.addSelector("chunk_view_distance", 30, 400, 440, 24); this.addSelector("chunk_build_time", 490, 400, 440, 24); super.init(width, height); } @@ -74,4 +80,18 @@ public class GuiDisplay extends GuiOptions { public String getTitle() { return "Grafik und Anzeige"; } + + private String getDistanceName() { + int distance = this.gm.renderDistance; + distance = distance > 16 ? 16 : distance; + String str = distance < 0 ? DISTANCES[0] : DISTANCES[(distance + 1) / 4]; + if(distance > 2 && (((distance + 1) / 2) & 1) == 1) + str = str + "+"; + return String.format("Sichtweite: %d Chunks [%d Blöcke, %s]", this.gm.renderDistance, this.gm.renderDistance * 16, str); + } + + public void updateScreen() { + if(!Button.isMouseDown()) + this.distanceSlider.setText(this.getDistanceName()); + } } diff --git a/java/src/game/gui/GuiMenu.java b/java/src/game/gui/GuiMenu.java index f0acffd..75bfa51 100644 --- a/java/src/game/gui/GuiMenu.java +++ b/java/src/game/gui/GuiMenu.java @@ -137,7 +137,7 @@ public class GuiMenu extends Gui { GuiMenu.this.gm.unload(true); // GuiMenu.this.gm.displayGuiScreen(INSTANCE); } - }, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen")); + }, this.gm.isRemote() ? "Server verlassen und Verbindung trennen" : "Welt speichern und schließen")); this.shift(); } } diff --git a/java/src/game/gui/GuiSkin.java b/java/src/game/gui/GuiSkin.java index 391f08a..899bfaf 100755 --- a/java/src/game/gui/GuiSkin.java +++ b/java/src/game/gui/GuiSkin.java @@ -139,8 +139,7 @@ public class GuiSkin extends GuiList } else { - this.drawTextureAt(x, y, EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? - this.charinfo.skin.substring(1) : this.charinfo.skin)); + this.drawTextureAt(x, y, EntityTexManager.getNpcSkin(this.charinfo.skin, this.model)); } } @@ -153,7 +152,7 @@ public class GuiSkin extends GuiList EntityTexManager.altTexture = tex; EntityTexManager.altLayer = this.dynId; EntityTexManager.altNpcLayer = this.dynId == -1 && this.charinfo != null ? this.charinfo.skin : null; - drawEntity(x + 32, y + 56, 28.0f + drawEntity(x + 32, y + 60, 28.0f / GuiSkin.this.gm.thePlayer.getHeight(), -45.0f, -20.0f, GuiSkin.this.gm.thePlayer); Render.drawNames = true; EntityTexManager.altTexture = null; @@ -233,90 +232,6 @@ public class GuiSkin extends GuiList return this.charinfo != null; } } - - - public static BufferedImage loadSkin(File file) - { - BufferedImage img = null; - try { - img = ImageIO.read(file); - } - catch(IOException e) { - return null; - } - if(img == null) { - return null; - } -// if(img.getWidth() != 64 || img.getHeight() != 64) { // || img.getType() != BufferedImage.TYPE_INT_ARGB) { -// return null; -// } - return img; - } - - public void load(String currentSkin, ModelType model) - { - this.unload(); - File[] files = new File("skins").listFiles(new FileFilter() { - public boolean accept(File pathname) { - return pathname.isFile() && pathname.getName().endsWith(".png"); - } - }); - int pos = 0; -// for(ModelType model : ModelType.values()) { - this.elements.add(new SkinEntry("default", null, null, null, model)); - if("default".equals(currentSkin)) - this.setSelected(pos); - pos++; -// } - if(files != null) { - Arrays.sort(files); - for(File file : files) - { - BufferedImage img = loadSkin(file); - if(img != null) { -// for(ModelType model : ModelType.values()) { - if(img.getWidth() == model.texWidth && img.getHeight() == model.texHeight) { - this.elements.add(new SkinEntry(file.getName(), file, null, img, model)); - if(file.getName().equals(currentSkin)) - this.setSelected(pos); - pos++; - } -// } - } - } - } - for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { - for(CharacterInfo charinfo : species.chars) { - if(charinfo.species.renderer == model) { - // for(Entry entry : SpeciesRegistry.SKINS.entrySet()) { - this.elements.add(new SkinEntry(charinfo.skin, null, charinfo, null, charinfo.species.renderer)); - if(charinfo.skin.equals(currentSkin)) - this.setSelected(pos); - pos++; - } - } - } - } - - public void unload() - { - for (SkinEntry entry : this.elements) - { - entry.deleteTexture(); - } - - this.elements.clear(); - } - - public int getListWidth() - { - return 254; - } - - public int getSlotHeight() - { - return 64 + 4; - } private class DragAdjust extends Element { private int mouseX; @@ -367,8 +282,8 @@ public class GuiSkin extends GuiList private ActButton convertButton2; private ActButton templateButton; private DragAdjust adjust; - private float yaw; - private float pitch; + private float yaw = -15.0f; + private float pitch = -15.0f; private GuiSkin() { } @@ -376,28 +291,28 @@ public class GuiSkin extends GuiList public void init(int width, int height) { super.init(width, height); - this.setDimensions(274, height, 52, height - 52); + this.setDimensions(400, height, 52, height - 52); this.load(null, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel()); - this.convertButton1 = this.add(new ActButton(4, 4, 266, 20, new ActButton.Callback() { + this.convertButton1 = this.add(new ActButton(10, height - 48, 200, 20, new ActButton.Callback() { public void use(ActButton elem, Mode action) { SkinEntry skin = GuiSkin.this.getSelected(); if(skin != null && skin.getFile() != null && SkinConverter.convertSkin(skin.getFile(), new File("skins"), false)) GuiSkin.this.gm.displayGuiScreen(GuiSkin.this); } }, "Konvertieren: Standard")); - this.convertButton2 = this.add(new ActButton(4, 28, 266, 20, new ActButton.Callback() { + this.convertButton2 = this.add(new ActButton(10, height - 24, 200, 20, new ActButton.Callback() { public void use(ActButton elem, Mode action) { SkinEntry skin = GuiSkin.this.getSelected(); if(skin != null && skin.getFile() != null && SkinConverter.convertSkin(skin.getFile(), new File("skins"), true)) GuiSkin.this.gm.displayGuiScreen(GuiSkin.this); } }, "Konvertieren: Schlank")); - this.add(new ActButton(4, height - 48, 266, 20, new ActButton.Callback() { + this.add(new ActButton(240, height - 48, 150, 20, new ActButton.Callback() { public void use(ActButton elem, Mode action) { GuiSkin.this.gm.displayGuiScreen(GuiSkin.this); } }, "Neu laden")); - this.templateButton = this.add(new ActButton(4, height - 24, 266, 20, new ActButton.Callback() { + this.templateButton = this.add(new ActButton(240, height - 24, 150, 20, new ActButton.Callback() { public void use(ActButton elem, Mode action) { SkinEntry skin = GuiSkin.this.getSelected(); if(skin != null && skin.getLocation() != null) { @@ -431,12 +346,32 @@ public class GuiSkin extends GuiList } } }, "Vorlage kopieren")); - this.adjust = this.add(new DragAdjust(274 + 10, 64, width - 274 - 274 - 20, height - 128)); + this.adjust = this.add(new DragAdjust(400 + 10, 64, width - 400 - 400 - 20, height - 128)); + +// final ActButton[] speciesBtns = new ActButton[SpeciesRegistry.SPECIMEN.size()]; + for(int z = 0; z < SpeciesRegistry.SPECIMEN.size(); z++) { + final SpeciesInfo species = SpeciesRegistry.SPECIMEN.get(z); +// speciesBtns[z] = + this.add(new ActButton(width - 400 + (z % 2) * 196, 4 + 23 * (z / 2), 194, 20, new ActButton.Callback() { + public void use(ActButton elem, Mode action) { + if(GuiSkin.this.gm.thePlayer != null) { + GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE); + GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(species.clazz))); +// for(ActButton btn : speciesBtns) { +// btn.enabled = btn != elem; +// } + } + } + }, EntityRegistry.getEntityName(EntityRegistry.getEntityString(species.clazz)))) // ; +// speciesBtns[z] + .enabled = this.gm.thePlayer == null || this.gm.thePlayer.getClass() != species.clazz; + } + final ActButton[] alignBtns = new ActButton[Alignment.values().length]; for (int z = 0; z < Alignment.values().length; z++) { final Alignment align = Alignment.values()[z]; - alignBtns[z] = this.add(new ActButton(width - 274 + (z % 3) * 89, height - 158 + 23 * (z / 3), 86, 20, new ActButton.Callback() { + alignBtns[z] = this.add(new ActButton(width - 400 + (z % 3) * 131, height - 198 + 23 * (z / 3), 129, 20, new ActButton.Callback() { public void use(ActButton elem, Mode action) { if(GuiSkin.this.gm.thePlayer != null) { GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal())); @@ -448,15 +383,15 @@ public class GuiSkin extends GuiList }, align.color + align.display)); alignBtns[z].enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != align; } - this.add(new Slider(width - 274, height - 28 - 54, 264, 20, 1, 120, 320, 180, this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().size * this.gm.thePlayer.getHeight() * 100.0f + 0.5f), new Slider.Callback() { + this.add(new Slider(width - 400, height - 28 - 84, 390, 20, 1, 120, 320, 180, this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().size * this.gm.thePlayer.getHeight() * 100.0f + 0.5f), new Slider.Callback() { public void use(Slider elem, int value) { if(GuiSkin.this.gm.thePlayer != null) GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, value)); } }, "Spieler-Größe", "cm")); - this.add(new Label(width - 274 + 2, height + 2 - 28 - 24 - 10, 200, 20, "Anzeigename", true)); - this.add(new ActButton(width - 274 + 154, height - 28, 264 - 154, 20, GuiMenu.INSTANCE, "Fertig")); - Textbox nameField = this.add(new Textbox(width - 274 + 2, height + 2 - 28 - 24, 260, 16, NetHandlerPlayServer.MAX_NICK_LENGTH, true, new Textbox.Callback() { + this.add(new Label(width - 400, height + 2 - 28 - 24 - 30, 390, 20, "Anzeigename", true)); + this.add(new ActButton(width - 274 + 154, height - 24, 264 - 154, 20, GuiMenu.INSTANCE, "Fertig")); + Textbox nameField = this.add(new Textbox(width - 400, height + 2 - 28 - 34, 390, 20, NetHandlerPlayServer.MAX_NICK_LENGTH, true, new Textbox.Callback() { public void use(Textbox elem, Action value) { if(value == Action.SEND || value == Action.UNFOCUS) { String name = elem.getText(); @@ -484,7 +419,7 @@ public class GuiSkin extends GuiList public void drawOverlays() { - drawEntity(274 + (this.gm.fb_x - 274 - 274) / 2, this.gm.fb_y / 2 + 160, 160.0f + drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y / 2 + 160, 160.0f / this.gm.thePlayer.getHeight(), this.yaw, this.pitch, this.gm.thePlayer); } @@ -492,7 +427,88 @@ public class GuiSkin extends GuiList return "Charakter anpassen"; } - + public static BufferedImage loadSkin(File file) + { + BufferedImage img = null; + try { + img = ImageIO.read(file); + } + catch(IOException e) { + return null; + } + if(img == null) { + return null; + } +// if(img.getWidth() != 64 || img.getHeight() != 64) { // || img.getType() != BufferedImage.TYPE_INT_ARGB) { +// return null; +// } + return img; + } + + public void load(String currentSkin, ModelType model) + { + this.unload(); + File[] files = new File("skins").listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.isFile() && pathname.getName().endsWith(".png"); + } + }); + int pos = 0; +// for(ModelType model : ModelType.values()) { + this.elements.add(new SkinEntry("default", null, null, null, model)); + if("default".equals(currentSkin)) + this.setSelected(pos); + pos++; +// } + if(files != null) { + Arrays.sort(files); + for(File file : files) + { + BufferedImage img = loadSkin(file); + if(img != null) { +// for(ModelType model : ModelType.values()) { + if(img.getWidth() == model.texWidth && img.getHeight() == model.texHeight) { + this.elements.add(new SkinEntry(file.getName(), file, null, img, model)); + if(file.getName().equals(currentSkin)) + this.setSelected(pos); + pos++; + } +// } + } + } + } + for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { + for(CharacterInfo charinfo : species.chars) { + if(charinfo.species.renderer == model) { + // for(Entry entry : SpeciesRegistry.SKINS.entrySet()) { + this.elements.add(new SkinEntry(charinfo.skin, null, charinfo, null, charinfo.species.renderer)); + if(charinfo.skin.equals(currentSkin)) + this.setSelected(pos); + pos++; + } + } + } + } + + public void unload() + { + for (SkinEntry entry : this.elements) + { + entry.deleteTexture(); + } + + this.elements.clear(); + } + + public int getListWidth() + { + return 400 - 20; + } + + public int getSlotHeight() + { + return 64 + 4; + } // public static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, EntityLiving ent) diff --git a/java/src/game/init/EntityRegistry.java b/java/src/game/init/EntityRegistry.java index 4b9d6ed..fbbc49d 100755 --- a/java/src/game/init/EntityRegistry.java +++ b/java/src/game/init/EntityRegistry.java @@ -262,6 +262,15 @@ public abstract class EntityRegistry { return integer == null ? 0 : integer.intValue(); } + public static int getEntityID(Class clazz) { + Integer integer = CLASS_TO_ID.get(clazz); + return integer == null ? 0 : integer.intValue(); + } + + public static Class getEntityClass(int id) { + return ID_TO_CLASS.get(id); + } + public static String getEntityString(Entity entityIn) { return CLASS_TO_STRING.get(entityIn.getClass()); } diff --git a/java/src/game/network/NetConnection.java b/java/src/game/network/NetConnection.java index 09c5ef6..05eb221 100755 --- a/java/src/game/network/NetConnection.java +++ b/java/src/game/network/NetConnection.java @@ -287,7 +287,8 @@ public class NetConnection extends SimpleChannelInboundHandler // { // ((ITickable)this.packetListener).update(); // } - this.channel.flush(); + if(this.channel != null) + this.channel.flush(); } // /** diff --git a/java/src/game/network/NetHandlerPlayServer.java b/java/src/game/network/NetHandlerPlayServer.java index 22ab7d8..7660eb2 100755 --- a/java/src/game/network/NetHandlerPlayServer.java +++ b/java/src/game/network/NetHandlerPlayServer.java @@ -57,6 +57,8 @@ import game.item.ItemStack; import game.log.Log; import game.material.Material; import game.nbt.NBTTagCompound; +import game.nbt.NBTTagDouble; +import game.nbt.NBTTagFloat; import game.nbt.NBTTagList; import game.nbt.NBTTagString; import game.packet.CPacketAction; @@ -1480,6 +1482,13 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting, Scrip public List getCharacters() { return this.characters; } + + public NBTTagCompound addCharacter(String id) { + NBTTagCompound tag = new NBTTagCompound(); + this.characters.add(tag); + tag.setString("id", id); + return tag; + } public NBTTagCompound getSelectedCharacter(boolean create) { NBTTagCompound tag = this.characters.isEmpty() || this.selected < 0 ? null : this.characters.get(this.selected); @@ -2800,6 +2809,27 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting, Scrip } } break; + + case SET_SPECIES: + Class clazz = EntityRegistry.getEntityClass(packetIn.getAuxData()); + if(EntityNPC.class.isAssignableFrom(clazz)) { + NBTTagCompound tag = this.addCharacter(EntityRegistry.getEntityString(clazz)); + tag.setInteger("Dimension", this.entity.worldObj.dimension.getDimensionId()); + NBTTagList pos = new NBTTagList(); + pos.appendTag(new NBTTagDouble(this.entity.posX)); + pos.appendTag(new NBTTagDouble(this.entity.posY)); + pos.appendTag(new NBTTagDouble(this.entity.posZ)); + tag.setTag("Pos", pos); + NBTTagList rot = new NBTTagList(); + rot.appendTag(new NBTTagFloat(this.entity.rotYaw)); + rot.appendTag(new NBTTagFloat(this.entity.rotPitch)); + tag.setTag("Rotation", rot); + tag.setString("CustomName", this.entity.getCustomNameTag()); + tag.setString("Align", this.entity.getAlignment().name); + tag.setFloat("Height", this.entity.getHeight()); + this.server.swapPlayer(this, tag); + } + break; default: throw new IllegalArgumentException("Ungültige Aktion!"); diff --git a/java/src/game/packet/CPacketAction.java b/java/src/game/packet/CPacketAction.java index d798f06..0fefb23 100755 --- a/java/src/game/packet/CPacketAction.java +++ b/java/src/game/packet/CPacketAction.java @@ -70,6 +70,7 @@ public class CPacketAction implements Packet // REQUEST_STATS, // SET_MODELPARTS, SET_HEIGHT, + SET_SPECIES, SELECT_TRADE, // SET_BEACON, INTERACT,