//private static final String[] DISTANCES = new String[] {"Gruselig", "Winzig", "Gering", "Normal", "Weit"}; package game.gui; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Set; import javax.imageio.ImageIO; import game.Game; import game.SKC; import game.audio.SoundManager; import game.collect.Lists; import game.collect.Sets; import game.entity.npc.Alignment; import game.entity.npc.CharacterInfo; import game.entity.npc.EntityNPC; import game.entity.npc.SpeciesInfo; import game.gui.element.Button; import game.gui.inventory.GuiInventory; import game.init.EntityRegistry; import game.init.SpeciesRegistry; import game.init.SpeciesRegistry.ModelType; import game.io.FileUtils; import game.network.NetHandlerPlayServer; import game.packet.CPacketAction; import game.packet.CPacketMessage; import game.packet.CPacketSkin; import game.renderer.GlState; import game.renderer.texture.DynamicTexture; import game.renderer.texture.EntityTexManager; import game.renderer.texture.TextureUtil; import java.util.function.Predicate; public class GuiSkin extends GuiList { private class SkinEntry implements IGuiListEntry { private static final String SKINS_BUTTONS = "textures/gui/server_selection.png"; // private final GuiSkin owner; // private final Game gm; private final File skinFile; private final String id; private final ModelType model; private final CharacterInfo charinfo; private final BufferedImage skinImage; private final String icon; private DynamicTexture dyntex; private long clickTime; protected SkinEntry(String id, File file, CharacterInfo charinfo, BufferedImage image, ModelType model) { // this.owner = parent; this.skinFile = file; this.charinfo = charinfo; this.id = id; this.model = model; // this.gm = Game.getGame(); if(this.skinFile != null) // { this.skinImage = image; // this.skin = skin.getName().substring(0, skin.getName().length() - 4); // } else // { this.skinImage = null; // this.skin = null; // } if(this.skinImage != null) { this.icon = "skins/" + this.id + "/icon"; this.dyntex = new DynamicTexture(this.skinImage); GuiSkin.this.gm.getTextureManager().loadTexture(this.icon, this.dyntex); } else { this.icon = null; this.dyntex = null; } } public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { // FontRenderer.drawString(this.skin == null ? "---" : this.skin, x + 32 + 3, y + 1, 16777215); String str = // List list = FontRenderer.listFormattedStringToWidth( (this.skinFile != null ? this.skinFile.getName() : (this.charinfo == null ? "Standard" : ( (this.charinfo.species.prefix && this.charinfo.spclass != null && this.charinfo.spclass.type != null ? this.charinfo.spclass.type.toString() : EntityRegistry.getEntityName(this.charinfo.species.id)) + (this.charinfo.name.isEmpty() ? "" : (" " + this.charinfo.name)) + " (" + this.charinfo.skin + ")"))); // + TextColor.LIGHT_GRAY + " (" + TextColor.GREEN + // this.model.display + TextColor.LIGHT_GRAY +")" // , listWidth - 16 - 2); // // for (int i = 0; i < Math.min(list.size(), 2); ++i) // { SKC.drawString(str, x + 16 + 3, y, this.charinfo == null ? (this.skinFile != null ? 0xffffff : 0xc0c0c0) : this.charinfo.color1 | this.charinfo.color2); // } GlState.color(1.0F, 1.0F, 1.0F, 1.0F); // if(this.model != ModelType.HUMANOID) { // this.drawTextureAt(x, y, EntitySkinManager.HEAD_DEF); // } if (this.dyntex != null) { this.drawTextureAt(x, y, this.icon); } else if(this.charinfo == null) { this.drawTextureAt(x, y, EntityTexManager.getDefault(this.model)); } else { this.drawTextureAt(x, y, EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) : this.charinfo.skin)); } if (/* this.gm.touchscreen || */ isSelected) { GuiSkin.this.gm.getTextureManager().bindTexture(SKINS_BUTTONS); Gui.drawRect(x, y, x + 16, y + 16, -1601138544); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); int k1 = mouseX - x; int l1 = mouseY - y; if (k1 < 16 && k1 > 0) { Gui.drawScaledCustomSizeModalRect(x, y, 0.0F, 32.0F, 32, 32, 16, 16, 256.0F, 256.0F); } } } protected void drawTextureAt(int x, int y, String tex) { GuiSkin.this.gm.getTextureManager().bindTexture(tex); GlState.enableBlend(); GuiSkin.this.gm.getRenderManager().getRenderObject(this.model).renderHead(x, y, this.model.texWidth, this.model.texHeight, 2); GlState.disableBlend(); } public void deleteTexture() { if(this.dyntex != null) { GuiSkin.this.gm.getTextureManager().deleteTexture(this.icon); this.dyntex = null; } } /** * Returns true if the mouse has been pressed on this control. */ public boolean mousePressed(int slotIndex, int mx, int my) { if(GuiSkin.this.adjust.dragging) return false; if (System.currentTimeMillis() - this.clickTime < 250L) { GuiSkin.this.close(); return true; } else { BufferedImage img = this.skinImage; boolean slim = false; if(this.charinfo != null) { try { img = TextureUtil.readImage(FileUtils.getStream( EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) : this.charinfo.skin))); } catch(IOException e) { if(e instanceof FileNotFoundException) Log.JNI.warn("Textur für Skin ist nicht vorhanden: " + EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) : this.charinfo.skin)); else Log.JNI.error(e, "Konnte Textur nicht laden"); return false; } slim = this.charinfo.skin.startsWith("~"); } else if(this.skinFile != null) { slim = this.skinFile.getName().startsWith("slim_"); } GuiSkin.this.selectEntry(slotIndex, slim); GuiSkin.this.selectSkin(this.id, img, slim, this.model); if(mx < 16 && mx > 0) GuiSkin.this.close(); this.clickTime = System.currentTimeMillis(); return false; } } // public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) // { // } /** * Fired when the mouse button is released. Arguments: index, x, y, mouseEvent, relativeX, relativeY */ // public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) // { // } public File getFile() { return this.skinFile; } public boolean canConvert() { return this.skinFile != null && this.model == ModelType.HUMANOID; } public String getLocation() { return this.charinfo == null ? null : (this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) : this.charinfo.skin); } public boolean canCopy() { return this.charinfo != null; } // public boolean mouseScrolled(int slotIndex, int mouseX, int mouseY, int offset, int relaX, int relaY) { // return false; // } } // private static class SkinSelector extends GuiList // { // private final GuiSkin owner; private final List skinList = Lists.newArrayList(); private int selectedSlotIndex = -1; // public SkinSelector(GuiSkin ownerIn, ModelType model, String currentSkin, Game gmIn, int widthIn, int heightIn, int topIn, int bottomIn, int slotHeightIn) // { // super(gmIn, widthIn, heightIn, topIn, bottomIn, slotHeightIn); // this.owner = ownerIn; //// this.setBackgroundDrawing(false); // this.load(currentSkin, model); // } /** * Gets the IGuiListEntry object for the given index */ public SkinEntry getListEntry(int index) { return this.skinList.get(index); } public int getSize() { return this.skinList.size(); } public void setSelectedSlotIndex(int selectedSlotIndexIn) { this.selectedSlotIndex = selectedSlotIndexIn; } /** * Returns true if the element passed in is currently selected */ protected boolean isSelected(int slotIndex) { return slotIndex == this.selectedSlotIndex; } public int getSelectedIndex() { return this.selectedSlotIndex; } 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.skinList.add(new SkinEntry("default", null, null, null, model)); if("default".equals(currentSkin)) this.setSelectedSlotIndex(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.skinList.add(new SkinEntry(file.getName(), file, null, img, model)); if(file.getName().equals(currentSkin)) this.setSelectedSlotIndex(pos); pos++; } // } } } } for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { for(CharacterInfo charinfo : species.chars) { if(charinfo.species.renderer == model) { // for(Entry entry : SpeciesRegistry.SKINS.entrySet()) { this.skinList.add(new SkinEntry(charinfo.skin, null, charinfo, null, charinfo.species.renderer)); if(charinfo.skin.equals(currentSkin)) this.setSelectedSlotIndex(pos); pos++; } } } } public void unload() { for (SkinEntry entry : this.skinList) { entry.deleteTexture(); } this.skinList.clear(); } protected int getScrollBarX() { return 0; } /** * Gets the width of the list */ public int getListWidth() { return 274 - 20; } public int getSlotHeight() { return 20; } protected boolean isInList(int x, int y) { return x >= 6; } // } private class DragAdjust extends Button { private int mouseX; private int mouseY; private float yawOffset; private float pitchOffset; public boolean dragging; public DragAdjust(int id, int x, int y, int w, int h) { super(id, x, y, w, h, ""); } public void drawButton(Game gm, int mouseX, int mouseY) { if(this.visible && this.dragging) { GuiSkin.this.yaw = this.yawOffset + (this.mouseX - mouseX) * 2.0f; GuiSkin.this.pitch = this.pitchOffset + (this.mouseY - mouseY) * 2.0f; } if(this.visible) drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, 0x20ffffff); } public boolean mousePressed(Game gm, int mouseX, int mouseY) { if(super.mousePressed(gm, mouseX, mouseY)) { this.mouseX = mouseX; this.mouseY = mouseY; this.yawOffset = GuiSkin.this.yaw; this.pitchOffset = GuiSkin.this.pitch; this.dragging = true; return true; } else { return false; } } public void mouseReleased(int mouseX, int mouseY) { this.dragging = false; } public void playPressSound(SoundManager soundHandlerIn) { } } private class ButtonPart extends Button { private final ModelPart part; private ButtonPart(int id, int x, int y, int width, int height, ModelPart part) { super(id, x, y, width, height, GuiSkin.this.formatPart(part)); this.part = part; } } private class ButtonAlign extends Button { private final Alignment align; private ButtonAlign(int id, int x, int y, int width, int height, Alignment align) { super(id, x, y, width, height, align.color + align.display); this.align = align; } } private class HeightReceiver implements SliderReceiver { private int height; private HeightReceiver(int value) { this.height = value; } public float getValue(Game gm) { return this.height; } public void setValue(Game gm, float value) { this.height = (int)value; if(gm.thePlayer != null) gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, this.height)); } public String formatValue(Game gm) { return "Spieler-Größe: " + (int)this.height + " cm"; } } // private final Set parts = Sets.newHashSet(ModelPart.values()); private Button convertButton; private Button templateButton; // private Button modelButton; private DragAdjust adjust; private float yaw; private float pitch; // public GuiSkin(GuiScreen parentScreen) // { // this.parentScreen = parentScreen; // } public void initGui() { this.load(this.gm.skinId.isEmpty() ? null : this.gm.skinId, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel()); this.buttonList.add(new Button(8, 164, this.height - 28, 274 - 164, 20, "Neu laden")); int flags = this.gm.thePlayer == null ? ~ModelPart.ARMS_SLIM.getMask() : this.gm.thePlayer.getModelParts(); this.parts.clear(); for(ModelPart part : ModelPart.values()) { if((flags & part.getMask()) == part.getMask()) this.parts.add(part); } this.buttonList.add(this.convertButton = new Button(9, 10, this.height - 28, 150, 20, "Konvertieren: " + (this.parts.contains(ModelPart.ARMS_SLIM) ? "Schlank" : "Standard"))); this.buttonList.add(this.templateButton = new Button(10, this.width - 274, this.height - 28, 150, 20, "Vorlage kopieren")); this.buttonList.add(this.adjust = new DragAdjust(20, 274 + 10, 64, this.width - 274 - 274 - 20, this.height - 128)); for (int z = 0; z < ModelPart.values().length; z++) { ModelPart part = ModelPart.values()[z]; Button button = new ButtonPart(z + 500, this.width - 274 + (z & 1) * 134, 32 + 24 * (z >> 1), 130, 20, part); if(part == ModelPart.ARMS_SLIM) this.modelButton = button; this.buttonList.add(button); } for (int z = 0; z < Alignment.values().length; z++) { Button button; this.buttonList.add(button = new ButtonAlign(z + 600, this.width - 274 + (z % 3) * 89, this.height - 158 + 23 * (z / 3), 86, 20, Alignment.values()[z])); button.enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != Alignment.values()[z]; } new HeightReceiver(this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().size * this.gm.thePlayer.getHeight() * 100.0f + 0.5f)), 120.0f, 320.0f, 1.0f) } private void sendNameToServer() { String name = this.nameField.getText(); if(name.isEmpty()) this.nameField.setText(this.gm.thePlayer == null ? "..." : this.gm.thePlayer.getCustomNameTag()); else if(this.gm.thePlayer != null) this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.DISPLAY, name)); } public void selectSkin(BufferedImage img, ModelType model) { this.gm.getNetHandler().addToSendQueue(new CPacketSkin(img, model)); } public void onGuiClosed() { // Keyboard.enableRepeatEvents(false); this.unload(); } protected void actionPerformed(Button button) { if (button.enabled) { if (button.id == 0) { this.gm.displayGuiScreen(this.parentScreen); } else if (button.id == 8) { this.refreshList(); } else if (button.id == 9) { if(this.getSelectedIndex() >= 0) { SkinEntry entry = this.getListEntry(this.getSelectedIndex()); if(entry.getFile() != null && SkinConverter.convertSkin(entry.getFile(), new File("skins"), slim)) { this.refreshList(); } } } else if (button.id == 10) { if(this.getSelectedIndex() >= 0) { SkinEntry entry = this.getListEntry(this.getSelectedIndex()); if(entry.getLocation() != null) { String loc = (this.parts.contains(ModelPart.ARMS_SLIM) ? "slim_" : "") + entry.getLocation(); File file = new File(new File("skins"), loc + ".png"); int z = 1; while(file.exists()) { file = new File(new File("skins"), loc + "_" + (++z) + ".png"); } InputStream in = null; try { in = FileUtils.getStream(EntityNPC.getSkinTexture(entry.getLocation())); Files.copy(in, file.toPath()); } catch(Exception e) { if(e instanceof FileNotFoundException) Log.JNI.warn("Textur ist nicht zum Kopieren vorhanden: " + EntityNPC.getSkinTexture(entry.getLocation())); else Log.JNI.error(e, "Konnte Textur nicht kopieren"); } finally { FileUtils.closeQuietly(in); } this.refreshList(); } } } else if (button.id == 30) { // this.update = 2; } // else if (button instanceof ButtonPart) // { // ModelPart part = ((ButtonPart)button).part; //// this.switchModelPartEnabled(part); // if(!this.parts.contains(part)) // this.parts.add(part); // else // this.parts.remove(part); // if(this.gm.thePlayer != null) { // int n = 0; // for(ModelPart p : this.parts) { // n |= p.getMask(); // } // this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_MODELPARTS, n)); // } // button.display = this.formatPart(part); //// this.update = 2; //// if(part == ModelPart.ARMS_SLIM) //// this.convertButton.display = "Konvertieren: " + //// (this.parts.contains(ModelPart.ARMS_SLIM) ? "Schlank" : "Standard"); // } else if (button instanceof ButtonAlign) { if(this.gm.thePlayer != null) { this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, ((ButtonAlign)button).align.ordinal())); for(Button btn : this.buttonList) { if(btn instanceof ButtonAlign) btn.enabled = ((ButtonAlign)button).align != ((ButtonAlign)btn).align; } } } } } public boolean canClose() { return false; } public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawBackground(); super.drawScreen(mouseX, mouseY, partialTicks); SKC.drawCentered("Charakter anpassen", this.width / 2, 20, 0xffffff); SKC.drawString("Anzeigename", this.width - 274 + 2, this.height + 2 - 28 - 24 - 10, 10526880); GuiInventory.drawEntity(274 + (this.width - 274 - 274) / 2, this.height / 2 + 80, 80.0f / this.gm.thePlayer.getHeight(), this.yaw, this.pitch, this.gm.thePlayer); } // private String formatPart(ModelPart part) // { // return part.getName() + ": " + ( // this.parts.contains(part) ? (part == ModelPart.ARMS_SLIM ? "Schlank" : "An") : // (part == ModelPart.ARMS_SLIM ? "Standard" : "Aus")); // } } package game.gui.world; import java.io.File; import game.SKC; import game.color.TextColor; import game.gui.GuiScreen; import game.gui.element.Button; import game.gui.element.TextField; import game.network.NetHandlerPlayServer; import java.util.function.Predicate; import game.world.Region; public class GuiEdit extends GuiScreen { public static interface Callback { void confirm(String name); } private final GuiWorlds parent; private final String original; private final boolean player; private final String title; private final String action; private final String desc; private final Callback callback; private TextField nameField; private Button actionButton; private boolean fileExists; private boolean noChange; public GuiEdit(GuiWorlds parent, String original, boolean player, String title, String action, String desc, Callback callback) { this.parent = parent; this.original = original; this.player = player; this.title = title; this.action = action; this.desc = desc; this.callback = callback; } public void updateScreen() { // this.nameField.updateCursorCounter(); this.fileExists = false; this.noChange = false; String text = this.nameField.getText().trim(); if(text.isEmpty() || (this.noChange = (text.equals(this.original) || (!this.player && !text.replaceAll("[\\./\"]", "_") .equals(text))))) { this.actionButton.enabled = false; return; } if(this.player) return; // { // if(!StringValidator.isValidUser(text)) // this.actionButton.enabled = false; // } // else { // for(String n : GuiCreate.DISALLOWED_FILES) { // if(text.equalsIgnoreCase(n)) { // this.actionButton.enabled = false; // return; // } // } // if(GuiCreate.DISALLOWED_FILES.contains(text.toUpperCase())) { // this.actionButton.enabled = false; // return; // } if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists())) this.actionButton.enabled = false; // } } public void initGui() { // Keyboard.enableRepeatEvents(true); this.buttonList.clear(); this.buttonList.add(this.actionButton = new Button(0, this.width / 2 - 100, this.height / 4 + 96 + 12, 200, 20, this.action)); this.buttonList.add(new Button(1, this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20, "Abbrechen")); this.nameField = new TextField(this.width / 2 - 100, 60, 200, 20); this.nameField.setFocused(true); if(this.player) { this.nameField.setMaxStringLength(16); this.nameField.setValidator(new Predicate() { public boolean test(String name) { return NetHandlerPlayServer.isValidUser(name); } }); } else { this.nameField.setValidator(new Predicate() { public boolean test(String name) { for(int z = 0; z < name.length(); z++) { if(GuiCreate.DISALLOWED_CHARS.contains(name.charAt(z))) return false; } return true; } }); } this.nameField.setText(this.original == null ? "" : this.original); this.actionButton.enabled = false; } // public void onGuiClosed() { // Keyboard.enableRepeatEvents(false); // } protected void actionPerformed(Button button) { if(button.enabled) { if(button.id == 1) { this.gm.displayGuiScreen(this.parent); } else if(button.id == 0) { this.callback.confirm(this.nameField.getText().trim()); // this.gm.displayGuiScreen(this.parent); } } } protected void keyTyped(char typedChar, int keyCode) { // this.nameField.textboxKeyTyped(typedChar, keyCode); ((Button)this.buttonList.get(0)).enabled = this.nameField.getText().trim().length() > 0; if(keyCode == 28 || keyCode == 156) { this.actionPerformed((Button)this.buttonList.get(0)); } } public boolean canClose() { return false; } // protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { // super.mouseClicked(mouseX, mouseY, mouseButton); // this.nameField.mouseClicked(mouseX, mouseY, mouseButton); // } public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawBackground(); SKC.drawCentered(this.title, this.width / 2, 20, 16777215); SKC.drawString((this.actionButton.enabled ? "" : TextColor.DARK_RED) + this.desc + (this.fileExists ? " - Existiert bereits" : (this.noChange ? " - Nicht geändert" : "")), this.width / 2 - 100, 47, 10526880); // this.nameField.drawTextBox(); super.drawScreen(mouseX, mouseY, partialTicks); } } package game.gui.world; import java.io.File; import java.util.Set; import game.SKC; import game.collect.Sets; import game.color.TextColor; import game.gui.GuiScreen; import game.gui.element.Button; import game.init.UniverseRegistry; import game.network.NetHandlerPlayServer; import java.util.function.Predicate; import game.world.Region; public class GuiCreate extends GuiScreen { public static final Set DISALLOWED_CHARS = Sets.newHashSet('/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'); private GuiScreen parentScreen; private TextField worldNameField; private TextField worldUserField; private boolean alreadyGenerated; private boolean fileExists; public GuiCreate(GuiScreen parent) { UniverseRegistry.clear(); this.parentScreen = parent; } public void updateScreen() { this.fileExists = false; String text = this.worldNameField.getText().trim(); if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists())) ((Button)this.buttonList.get(0)).enabled = false; } public void initGui() { this.buttonList.add(new Button(0, this.width / 2 - 155, this.height - 28, 150, 20, "Neue Welt erstellen")); this.buttonList.add(new Button(1, this.width / 2 + 5, this.height - 28, 150, 20, "Abbrechen")); this.worldNameField = new TextField(this.width / 2 - 100, 60, 200, 20); this.worldNameField.setFocused(true); this.worldNameField.setValidator(new Predicate() { public boolean test(String name) { for(int z = 0; z < name.length(); z++) { if(DISALLOWED_CHARS.contains(name.charAt(z))) return false; } return true; } }); this.worldUserField = new TextField(this.width / 2 - 100, 98, 200, 20); this.worldUserField.setMaxStringLength(16); this.worldUserField.setValidator(new Predicate() { public boolean test(String name) { return NetHandlerPlayServer.isValidUser(name); } }); this.buttonList.get(0).enabled = false; } protected void actionPerformed(Button button) { if (button.enabled) { if (button.id == 1) { this.gm.displayGuiScreen(this.parentScreen); } else if (button.id == 0) { this.gm.displayGuiScreen(null); if(this.alreadyGenerated) return; this.alreadyGenerated = true; this.gm.launchIntegratedServer(this.worldNameField.getText().trim(), this.worldUserField.getText()); } } } protected void keyTyped(char typedChar, int keyCode) { if (keyCode == 28 || keyCode == 156) { this.actionPerformed((Button)this.buttonList.get(0)); } ((Button)this.buttonList.get(0)).enabled = this.worldNameField.getText().length() > 0 && this.worldUserField.getText().length() > 0; } public boolean canClose() { return false; } public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawBackground(); SKC.drawCentered("Neue Welt erstellen", this.width / 2, 20, -1); SKC.drawString((this.worldNameField.getText().trim().isEmpty() || this.fileExists /* || this.fileInvalid */ ? TextColor.DARK_RED : "") + "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : ""), this.width / 2 - 100, 49, -6250336); SKC.drawString((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336); super.drawScreen(mouseX, mouseY, partialTicks); } } package game.gui.server; import game.SKC; import game.color.TextColor; import game.gui.GuiScreen; import game.gui.element.Button; import game.gui.server.GuiMultiplayer.ServerEntry; import game.network.NetHandlerPlayServer; import java.util.function.Predicate; public class GuiServer extends GuiScreen { private final GuiScreen parentScreen; private final ServerEntry serverData; private TextField serverIPField; private TextField serverNameField; private TextField serverUserField; private TextField serverPassField; private TextField serverAccessField; public GuiServer(GuiScreen parent, ServerEntry server) { this.parentScreen = parent; this.serverData = server; } public void initGui() { this.buttonList.clear(); this.buttonList.add(new Button(0, this.width / 2 - 100, this.height / 4 + 96 + 100 + 18, 200, 20, "Fertig")); this.buttonList.add(new Button(1, this.width / 2 - 100, this.height / 4 + 120 + 100 + 18, 200, 20, "Abbrechen")); this.serverNameField = new TextField(this.width / 2 - 100, 66, 200, 20); this.serverNameField.setFocused(true); this.serverNameField.setText(this.serverData.name); this.serverIPField = new TextField(this.width / 2 - 100, 106, 200, 20); this.serverIPField.setMaxStringLength(128); this.serverIPField.setText(this.serverData.address); this.serverUserField = new TextField(this.width / 2 - 100, 146, 200, 20); this.serverUserField.setMaxStringLength(16); this.serverUserField.setText(this.serverData.user); this.serverUserField.setValidator(new Predicate() { public boolean test(String name) { return NetHandlerPlayServer.isValidUser(name); } }); this.serverPassField = new TextField(this.width / 2 - 100, 186, 200, 20); this.serverPassField.setMaxStringLength(64); this.serverPassField.setText(this.serverData.pass); this.serverAccessField = new TextField(this.width / 2 - 100, 226, 200, 20); this.serverAccessField.setMaxStringLength(64); this.serverAccessField.setText(this.serverData.access); ((Button)this.buttonList.get(0)).enabled = this.serverIPField.getText().length() > 0 && this.serverIPField.getText().split(":").length > 0 && this.serverNameField.getText().length() > 0 && this.serverUserField.getText().length() > 0; } protected void actionPerformed(Button button) { if(button.enabled) { if(button.id == 1) { this.parentScreen.confirmClicked(false); } else if(button.id == 0) { this.serverData.name = this.serverNameField.getText(); this.serverData.address = this.serverIPField.getText(); this.serverData.user = this.serverUserField.getText(); this.serverData.pass = this.serverPassField.getText(); this.serverData.access = this.serverAccessField.getText(); this.parentScreen.confirmClicked(true); } } } protected void keyTyped(char typedChar, int keyCode) { if(keyCode == 15) { int focus = this.serverNameField.isFocused() ? 0 : (this.serverIPField.isFocused() ? 1 : ((this.serverUserField.isFocused() ? 2 : ((this.serverPassField.isFocused() ? 3 : ((this.serverAccessField.isFocused() ? 4 : -1))))))); focus = focus == -1 ? -1 : ((focus + 5 + (SKC.isShiftKeyDown() ? -1 : 1)) % 5); this.serverNameField.setFocused(focus == 0); this.serverIPField.setFocused(focus == 1); this.serverUserField.setFocused(focus == 2); this.serverPassField.setFocused(focus == 3); this.serverAccessField.setFocused(focus == 4); } if(keyCode == 28 || keyCode == 156) this.actionPerformed((Button)this.buttonList.get(0)); ((Button)this.buttonList.get(0)).enabled = this.serverIPField.getText().length() > 0 && this.serverIPField.getText().split(":").length > 0 && this.serverNameField.getText().length() > 0 && this.serverUserField.getText().length() > 0; } public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawBackground(); SKC.drawCentered("Serverinformationen bearbeiten", this.width / 2, 17, 16777215); SKC.drawString((this.serverNameField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Servername", this.width / 2 - 100, 54, 10526880); SKC.drawString((this.serverIPField.getText().isEmpty() || this.serverIPField.getText().split(":").length == 0 ? TextColor.DARK_RED : "") + "Serveradresse", this.width / 2 - 100, 94, 10526880); SKC.drawString((this.serverUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Nutzername", this.width / 2 - 100, 134, 10526880); SKC.drawString("Passwort", this.width / 2 - 100, 174, 10526880); SKC.drawString("Zugangspasswort", this.width / 2 - 100, 214, 10526880); super.drawScreen(mouseX, mouseY, partialTicks); } } private void loadList() { this.servers.clear(); // List list = Lists.newArrayList(); try { if(!SERVERS_FILE.exists()) return; List lines = FileUtils.readLines(SERVERS_FILE); for(String line : lines) { if(line.isEmpty()) continue; // ServerData server = ServerData.fromString(line); String[] svr = line.split("=", 2); if(svr.length != 2) continue; String[] tok = svr[1].split("@", 2); if(tok.length != 2 || tok[0].startsWith(":")) continue; String[] addr = tok[1].split("#", 2); ServerEntry server = new ServerEntry(); server.name = svr[0]; server.address = addr[0]; if(addr.length == 2) server.access = addr[1]; String[] login = tok[0].split(":", 2); if(login.length == 2) server.pass = login[1]; server.user = login[0]; // return ? null : server; if(!server.name.isEmpty() && !server.address.isEmpty() && !server.user.isEmpty()) this.servers.add(server); } } catch(Exception e) { Log.JNI.error(e, "Konnte Serverliste nicht laden"); } // return list; } private void saveList() { try { StringBuilder sb = new StringBuilder(); for(ServerEntry server : this.servers) { sb.append((sb.length() == 0 ? "" : "\n") + server.name + "=" + server.user + (server.pass.isEmpty() ? "" : (":" + server.pass)) + "@" + server.address + (server.access.isEmpty() ? "" : ("#" + server.access))); } FileUtils.safeWrite(sb.toString(), SERVERS_FILE); } catch(Exception e) { Log.JNI.error(e, "Konnte Serverliste nicht speichern"); } } private boolean deleteWorld(int id, final boolean pruneOnly) { File worldDir = new File(Region.SAVE_DIR, this.getSaveAt(id)); if (!worldDir.exists()) { return true; } Log.JNI.info((pruneOnly ? "Leere" : "Lösche") + " Welt " + worldDir); boolean flag = false; for (int i = 1; i <= 5; ++i) { Log.JNI.info("Versuch " + i + "..."); if (FileUtils.deleteFiles(worldDir.listFiles(new FileFilter() { public boolean accept(File file) { return !pruneOnly || (file.isDirectory() ? file.getName().equals("chunk") : file.getName().equals("signs.nbt")); } }))) { flag = true; break; } Log.JNI.warn("Konnte Inhalt nicht löschen."); if (i < 5) { try { Thread.sleep(500L); } catch (InterruptedException e) { ; } } } return pruneOnly ? flag : worldDir.delete(); } private static boolean copyFiles(File source, File dest, File[] files) { dest.mkdirs(); if(files == null || !dest.isDirectory()) { Log.JNI.warn("Konnte Ordner " + source + " nicht nach " + dest + " kopieren"); return false; } boolean flag = true; for (int i = 0; i < files.length; ++i) { File file = files[i]; File nfile = new File(dest, file.getName()); Log.JNI.info("Kopiere " + file + " nach " + nfile); if (file.isDirectory()) { flag &= copyFiles(file, nfile, file.listFiles()); continue; } try { Files.copy(file.toPath(), nfile.toPath(), StandardCopyOption.REPLACE_EXISTING); // Files.copy(file, nfile); } catch(IOException e) { Log.JNI.error(e, "Konnte Datei " + file + " nicht nach " + nfile + " kopieren"); flag = false; } } return flag; } private void copyWorld(String name) { File oldDir = new File(Region.SAVE_DIR, this.getSaveAt(this.selectedIndex)); // String name = this.getSaveAt(this.selectedIndex); // while(new File(Region.SAVE_DIR, name).exists()) { // name = name + "-"; // } File newDir = new File(Region.SAVE_DIR, name); Log.JNI.info("Kopiere Welt " + oldDir + " nach " + newDir); if(!copyFiles(oldDir, newDir, oldDir.listFiles())) { this.warningTimer = 120; this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!"; } // try // { // this.loadLevelList(); // } // catch (Exception anvilconverterexception) // { // Log.error((String)"Konnte Weltliste nicht laden", (Throwable)anvilconverterexception); // } this.gm.displayGuiScreen(this); } private void moveWorld(String dest) { File oldDir = new File(Region.SAVE_DIR, this.getSaveAt(this.selectedIndex)); File newDir = new File(Region.SAVE_DIR, dest); Log.JNI.info("Kopiere Welt " + oldDir + " nach " + newDir); if(!copyFiles(oldDir, newDir, oldDir.listFiles())) { this.warningTimer = 120; this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!"; return; } if(!this.deleteWorld(this.selectedIndex, false)) { this.warningTimer = 120; this.warningMessage = "Fehler beim Löschen der Welt!"; } this.gm.displayGuiScreen(this); } private void changeUser(String user) { File file = new File(new File(Region.SAVE_DIR, this.getSaveAt(this.selectedIndex)), "level.nbt"); if(file.exists()) { try { NBTTagCompound tag = NBTLoader.readGZip(file); tag.setString("Owner", user); NBTLoader.writeGZip(tag, file); } catch(Exception e) { Log.JNI.error(e, "Fehler beim Verarbeiten von " + file); } } this.gm.displayGuiScreen(this); } private void playWorld(String user) { this.gm.displayGuiScreen(null); if (!this.starting) { this.starting = true; int index = this.selectedIndex; if(user == null) user = this.saveList.get(index).getUser(); String dir = this.getSaveAt(index); if(new File(Region.SAVE_DIR, dir).isDirectory()) { if(user == null) { this.gm.displayGuiScreen(new GuiEdit(this, "", true, "Spieler für '" + dir + "' festlegen", "Festlegen", "Spielername", new Callback() { public void confirm(String name) { GuiWorlds.this.playWorld(name); } })); this.starting = false; } else { } } } } this.gm.displayGuiScreen(new GuiEdit(this, this.saveList.get(this.selectedIndex).getUser(), true, "Spieler für '" + this.getSaveAt(this.selectedIndex) + "' ändern", "Ändern", "Spielername", new Callback() { public void confirm(String name) { GuiWorlds.this.changeUser(name); } })); } else if (button.id == 0) { this.gm.displayGuiScreen(this.parentScreen); } else if (button.id == 7) { } else if (button.id == 9) { this.gm.displayGuiScreen(new GuiEdit(this, "", false, "Welt '" + this.getSaveAt(this.selectedIndex) + "' kopieren", "Kopieren", "Ordner der Welt", new Callback() { public void confirm(String name) { GuiWorlds.this.copyWorld(name); GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this); } })); } else if (button.id == 10) { this.gm.displayGuiScreen(new GuiEdit(this, this.getSaveAt(this.selectedIndex), false, "Welt '" + this.getSaveAt(this.selectedIndex) + "' verschieben", "Verschieben", "Ordner der Welt", new Callback() { public void confirm(String name) { GuiWorlds.this.moveWorld(name); GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this); } })); try { if(!Region.SAVE_DIR.exists() || !Region.SAVE_DIR.isDirectory()) throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!"); java.util.List list = Lists.newArrayList(); File[] files = Region.SAVE_DIR.listFiles(); if(files == null) throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!"); for(File file : files) { if(!file.isDirectory()) continue; if(Region.loadWorldInfo(new File(Region.SAVE_DIR, file.getName())) == -1L && Converter.getLegacyWorldInfo(new File(Region.SAVE_DIR, file.getName())) == null) { list.add(new SaveInfo(file.getName(), "???", null, file.lastModified(), 0L, true, false, true, true)); continue; } Dimension dim = Region.version < 0 ? null : UniverseRegistry.getDimension(Config.spawnDim); if(dim != null) { File dat = new File(new File(new File(new File(Region.SAVE_DIR, file.getName()), "chunk"), dim.getDimensionName()), "data.nbt"); try { dim.fromNbt(NBTLoader.readGZip(dat).getCompoundTag("Generator")); } catch(Exception e) { } } list.add(new SaveInfo(file.getName(), dim == null ? "???" : TextColor.stripCodes(dim.getFormattedName(true)), Region.owner, Region.lastPlayed, dim == null ? 0L : dim.getSeed(), Region.version < 0, Region.version <= -3, Region.version == -1, Region.version == -4)); } this.saveList = list; Collections.sort(this.saveList); } catch (Exception e) { Log.JNI.error(e, "Konnte Weltliste nicht laden"); this.saveList = Lists.newArrayList(); create = false; this.warningTimer = 120; this.warningMessage = "Welten-Ordner nicht lesbar!"; } private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); public boolean mousePressed(int slotIndex, int mouseX, int mouseY) { GuiWorlds.this.selectedIndex = slotIndex; boolean sel = GuiWorlds.this.selectedIndex >= 0 && GuiWorlds.this.selectedIndex < GuiWorlds.this.getSize(); boolean use = sel && !GuiWorlds.this.saveList.get(GuiWorlds.this.selectedIndex).isIncompatible(); boolean cur = use && !GuiWorlds.this.saveList.get(GuiWorlds.this.selectedIndex).mustConvert(); GuiWorlds.this.selectButton.display = sel && (!use || !cur) ? "Konvertieren" : "Welt spielen"; GuiWorlds.this.selectButton.enabled = use; GuiWorlds.this.deleteButton.enabled = sel; GuiWorlds.this.pruneButton.enabled = cur; GuiWorlds.this.copyButton.enabled = use; GuiWorlds.this.moveButton.enabled = use; GuiWorlds.this.seedButton.enabled = cur; GuiWorlds.this.userButton.enabled = cur; GuiWorlds.this.dupeButton.enabled = cur; if (System.currentTimeMillis() - this.lastClick < 250L && use) { GuiWorlds.this.playWorld(null); } this.lastClick = System.currentTimeMillis(); // if (isDoubleClick && use) // { // // } return true; } public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { SaveInfo info = (SaveInfo)GuiWorlds.this.saveList.get(slotIndex); SKC.drawString((info.isIncompatible() ? TextColor.DARK_RED : "") + info.getFile() + (info.mustConvert() ? "" : (TextColor.LIGHT_GRAY + " - " + TextColor.RESET + (info.getUser() == null ? "???" : info.getUser()))), x + 2, y + 1, 16777215); SKC.drawString(info.mustConvert() ? (info.isIncompatible() ? TextColor.BLOOD_RED + "Version: Release 1.13 +" : (info.isNewerRelease() ? "Version: Release 1.9 - Release 1.12.2" : (info.isOlderRelease() ? "Version: Alpha 1.0 - Beta 1.2" : "Version: Beta 1.3 - Release 1.8.9"))) : info.getName(), x + 2, y + 12, 8421504); SKC.drawString(info.mustConvert() ? (info.isIncompatible() ? TextColor.BLOOD_RED + "Kann nicht konvertiert werden!" : "Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") + "Zuletzt gespielt: " + DATE_FORMAT.format(new Date(info.getLastPlayed()))), x + 2, y + 12 + 10, 8421504); } public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) { SKC.drawString(this.name, x + 16 + 3, y + 1, 16777215); SKC.drawString(/* (this.gm.hideServerAddress ? "[***]" : */ this.address + (this.access.isEmpty() ? "" : (" / " + this.access.replaceAll(".", "*"))), x + 16 + 3, y + 12, 8421504); SKC.drawString(this.user + (this.pass.isEmpty() ? "" : (" / " + this.pass.replaceAll(".", "*"))), x + 16 + 3, y + 12 + 9, 8421504); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); if (/* this.gm.touchscreen || */ isSelected) { GuiMultiplayer.this.gm.getTextureManager().bindTexture(SERVER_SELECTION_BUTTONS); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); int k1 = mouseX - x; int l1 = mouseY - y; if (GuiMultiplayer.this.canMoveUp(slotIndex)) { if (k1 < 16 && l1 < 16) { drawModalRectWithCustomSizedTexture(x, y, 96.0F, 32.0F, 32, 32, 256.0F, 256.0F); } else { drawModalRectWithCustomSizedTexture(x, y, 96.0F, 0.0F, 32, 32, 256.0F, 256.0F); } } if (GuiMultiplayer.this.canMoveDown(slotIndex)) { if (k1 < 16 && l1 > 16) { drawModalRectWithCustomSizedTexture(x, y, 64.0F, 32.0F, 32, 32, 256.0F, 256.0F); } else { drawModalRectWithCustomSizedTexture(x, y, 64.0F, 0.0F, 32, 32, 256.0F, 256.0F); } } } } int n = SKC.getStringWidth(this.splashText); drawRect(0, logoY + 44 + 10 - 1, this.width / 2 - n / 2 - 10, logoY + 44 + 10 + 9 - 1, 0x7f7f00ff); drawRect(this.width / 2 + n / 2 + 10, logoY + 44 + 10 - 1, this.width, logoY + 44 + 10 + 9 - 1, 0x7f7f00ff); SKC.drawCentered(this.splashText, this.width / 2, logoY + 44 + 10, 0xff7f00ff); SKC.drawString(this.animBack, this.width - SKC.getStringWidth(this.animBack) - 2, this.height - 10, -1); SKC.drawString(this.animStr, this.width - SKC.getStringWidth(this.animStr) - ((this.animWidth - this.animPos - 4) * 4), this.height - 12, private static final Random RANDOM = new Random(); private int animWidth = 32; private int animGrowth = 10; private int[] animGrow = new int[this.animWidth]; private String animStr = ""; private String animBack = ""; private int animPos; private int animLen; private int animDir; private boolean animStep; private void resetAnimation() { this.animStr = ""; this.animBack = ""; this.animPos = 0; this.animLen = 0; this.animDir = 0; this.animStep = false; this.animWidth = Math.max(5, (this.width - 5) / 4); this.animGrowth = this.animWidth / 15; this.animGrow = new int[this.animWidth]; } public void updateScreen() { if(this.animLen == 0) { this.animDir = RANDOM.zrange(3) - 1; this.animLen = this.animDir == 0 ? (2 + RANDOM.zrange(2)) : (8 + RANDOM.zrange(96)); } else { this.animPos += this.animDir; if(this.animPos == -1) { this.animPos = 0; this.animDir = 1; } else if(this.animPos == this.animWidth - 3) { this.animPos = this.animWidth - 4; this.animDir = -1; } this.animLen--; } this.animStep = !this.animStep; StringBuilder sb = new StringBuilder(11); sb.append(TextColor.GRAY); sb.append("["); sb.append(TextColor.YELLOW); switch(this.animDir) { case -1: sb.append((this.animStep ? '>' : '-') + "' "); break; case 0: sb.append("`" + (this.animStep ? 'O' : 'o') + "'"); break; case 1: sb.append(" `" + (this.animStep ? '<' : '-')); break; } sb.append(TextColor.GRAY); sb.append("]"); this.animStr = sb.toString(); for(int z = this.animPos; z < this.animPos + 4; z++) { this.animGrow[z] = 0; } for(int z = 0; z < this.animGrowth; z++) { this.animGrow[RANDOM.zrange(this.animWidth)] += 1; } sb = new StringBuilder(this.animWidth + 2); sb.append(TextColor.DARK_GREEN); for(int z = 0; z < this.animWidth; z++) { switch(this.animGrow[z] / 5) { case 0: sb.append(TextColor.BLACK); break; case 1: sb.append(TextColor.GRAY); break; case 2: case 3: sb.append(TextColor.LIGHT_GRAY); break; case 4: case 5: case 6: sb.append(TextColor.WHITE); break; case 7: case 8: case 9: case 10: sb.append(TextColor.LIGHT_PURPLE); break; case 11: case 12: case 13: case 14: case 15: sb.append(TextColor.DARK_PURPLE); break; default: sb.append(TextColor.VIOLET); break; } sb.append(",."); } this.animBack = sb.toString(); } private void drawPing(int width, int xPos, int yPos, int ping) { GlState.color(1.0F, 1.0F, 1.0F, 1.0F); this.gm.getTextureManager().bindTexture(icons); int rectX = 0; int rectWidth = 0; if(ping < 0 || ping >= 20000) { rectWidth = 5; } else if(ping < 150) { rectWidth = 0; } else if(ping < 300) { rectWidth = 1; } else if(ping < 600) { rectWidth = 2; } else if(ping < 1000) { rectWidth = 3; } else { rectWidth = 4; } String str = this.formatPing(ping); this.zLevel += 100.0F; this.drawTexturedModalRect(xPos + width - 11, yPos, 0 + rectX * 10, 176 + rectWidth * 8, 10, 8); SKC.drawString(str, xPos + width - (11 + 1 + SKC.getStringWidth(str)), yPos, -1); this.zLevel -= 100.0F; } private void renderBossHealth() { Iterator iter = BOSSBARS.values().iterator(); int y = 0; while(iter.hasNext()) { BossStatus status = iter.next(); Entity entity; if(status.bossName != null && status.statusBarTime > 0 && (entity = this.gm.thePlayer.worldObj.getEntityByID(status.eid)) != null) { --status.statusBarTime; // FontRenderer fontrenderer = this.gm.fontRenderer; // Scaler scaledresolution = new Scaler(this.gm); int i = this.gm.displayWidth; // scaledresolution.getWidth(); int j = 182; int k = i / 2 - j / 2; int l = (int)(status.healthScale * (float)(j + 1)); int i1 = 12; if(entity instanceof EntityLiving) { Vec3 color = new Vec3(((EntityLiving)entity).getColor()); GlState.color((float)color.xCoord, (float)color.yCoord, (float)color.zCoord, 1.0F); } SKC.rect(k, y + i1, 0, 74, j, 5); SKC.rect(k, y + i1, 0, 74, j, 5); if(l > 0) { SKC.rect(k, y + i1, 0, 79, l, 5); } String s = status.bossName + TextColor.GRAY + " [" + EntityLiving.getHealthColor(status.health, status.maxHealth) + status.health + TextColor.GRAY + " / " + EntityLiving.getMaxHpColor(status.maxHealth) + status.maxHealth + TextColor.GRAY + "]"; SKC.drawString(s, i / 2 - SKC.getStringWidth(s) / 2, y + i1 - 10, 16777215); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); this.gm.getTextureManager().bindTexture(icons); y += 20; } else { iter.remove(); } } } public static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, EntityLiving ent) { GlState.enableColorMaterial(); SKC.glPushMatrix(); SKC.glTranslatef((float)posX, (float)posY, 50.0F); SKC.glScalef(-scale, scale, scale); SKC.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); float f = ent.yawOffset; float f1 = ent.rotYaw; float f2 = ent.rotPitch; float f3 = ent.prevHeadYaw; float f4 = ent.headYaw; SKC.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); ItemRenderer.enableStandardItemLighting(); SKC.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); SKC.glRotatef(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); ent.yawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F; ent.rotYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F; ent.rotPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F; ent.headYaw = ent.rotYaw; ent.prevHeadYaw = ent.rotYaw; SKC.glTranslatef(0.0F, 0.0F, 0.0F); RenderManager rendermanager = Game.getGame().getRenderManager(); rendermanager.setPlayerViewY(180.0F); // rendermanager.setRenderShadow(false); rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F); // rendermanager.setRenderShadow(true); ent.yawOffset = f; ent.rotYaw = f1; ent.rotPitch = f2; ent.prevHeadYaw = f3; ent.headYaw = f4; SKC.glPopMatrix(); ItemRenderer.disableStandardItemLighting(); GlState.disableRescaleNormal(); GlState.setActiveTexture(SKC.GL_TEXTURE1); GlState.disableTexture2D(); GlState.setActiveTexture(SKC.GL_TEXTURE0); } public static void drawEntity(int posX, int posY, float scale, float yaw, float pitch, EntityLiving ent) { GlState.color(1.0F, 1.0F, 1.0F, 1.0F); GlState.enableDepth(); GlState.enableColorMaterial(); SKC.glPushMatrix(); SKC.glTranslatef((float)posX, (float)posY, 200.0F); SKC.glScalef(-scale, scale, scale); SKC.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); float f = ent.yawOffset; float f1 = ent.rotYaw; float f2 = ent.rotPitch; float f3 = ent.prevHeadYaw; float f4 = ent.headYaw; SKC.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); ItemRenderer.enableStandardItemLighting(); SKC.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); SKC.glTranslatef(0.0F, ent.height / 2, 0.0F); SKC.glRotatef(-pitch, 1.0F, 0.0F, 0.0F); ent.yawOffset = yaw; ent.rotYaw = yaw; ent.rotPitch = 0.0f; ent.headYaw = ent.rotYaw; ent.prevHeadYaw = ent.rotYaw; SKC.glTranslatef(0.0F, -(ent.height / 2), 0.0F); RenderManager rendermanager = Game.getGame().getRenderManager(); rendermanager.setPlayerViewY(180.0F); rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F); // SKC.glTranslatef(0.0F, 0.0F, 0.0F); ent.yawOffset = f; ent.rotYaw = f1; ent.rotPitch = f2; ent.prevHeadYaw = f3; ent.headYaw = f4; SKC.glPopMatrix(); ItemRenderer.disableStandardItemLighting(); GlState.disableRescaleNormal(); GlState.setActiveTexture(SKC.GL_TEXTURE1); GlState.disableTexture2D(); GlState.setActiveTexture(SKC.GL_TEXTURE0); GlState.disableDepth(); } /* private final int[] tickTimes = new int[240]; private final long[] frames = new long[240]; private int tickIndex; private long frameLast; private long frameWait; private int lastIndex; private int frameCounter; private int frameIndex; private long startNanoTime = System.nanoTime(); long now = System.nanoTime(); this.addFrame(now - this.startNanoTime); this.startNanoTime = now; private void addFrame(long runningTime) { this.frames[this.frameIndex] = runningTime; ++this.frameIndex; if (this.frameIndex == 240) { this.frameIndex = 0; } if (this.frameCounter < 240) { this.lastIndex = 0; ++this.frameCounter; } else { this.lastIndex = (this.frameIndex + 1) % 240; } } private void updateTick() { long n = System.nanoTime(); if(n < this.frameLast + this.frameWait) return; this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L); this.frameLast = n; this.tickTimes[this.tickIndex++] = this.isServer() ? (int)this.server.getLastTick() : 0; if(this.tickIndex == 240) { this.tickIndex = 0; } } private int blendColors(int color1, int color2, float value) { int i = color1 >> 24 & 255; int j = color1 >> 16 & 255; int k = color1 >> 8 & 255; int l = color1 & 255; int i1 = color2 >> 24 & 255; int j1 = color2 >> 16 & 255; int k1 = color2 >> 8 & 255; int l1 = color2 & 255; int i2 = ExtMath.clampi((int)((float)i + (float)(i1 - i) * value), 0, 255); int j2 = ExtMath.clampi((int)((float)j + (float)(j1 - j) * value), 0, 255); int k2 = ExtMath.clampi((int)((float)k + (float)(k1 - k) * value), 0, 255); int l2 = ExtMath.clampi((int)((float)l + (float)(l1 - l) * value), 0, 255); return i2 << 24 | j2 << 16 | k2 << 8 | l2; } private int getFrameColor(int value, int base, int mid, int high) { value = ExtMath.clampi(value, base, high); return value < mid ? this.blendColors(-16711936, -256, (float)value / (float)mid) : this.blendColors(-256, -65536, (float)(value - mid) / (float)(high - mid)); } private void drawHorizontalLine(int startX, int endX, int y, int color) { if (endX < startX) { int i = startX; startX = endX; endX = i; } Gui.drawRect(startX, y, endX + 1, y + 1, color); } private void drawVerticalLine(int x, int startY, int endY, int color) { if (endY < startY) { int i = startY; startY = endY; endY = i; } Gui.drawRect(x, startY + 1, x + 1, endY, color); } private void renderLagometer() { GlState.disableDepth(); int w = this.displayWidth; int h = this.displayHeight; int shifted = this.lastIndex; int x = 0; Gui.drawRect(0, h - 74, 240, h - 14, 0x90505050); drawHorizontalLine(0, 239, h - 44, 0x5fffffff); drawHorizontalLine(0, 239, h - 74, 0x5fffffff); while(shifted != this.frameIndex) { int value = (int) (this.frames[shifted] / 1000000L); // , 30); int color = this.getFrameColor(value, 0, 17, 67); if(value > 0) drawVerticalLine(x, h - 14, h - 14 - value, color & 0xc0ffffff); ++x; shifted = (shifted + 1) % 240; } Gui.drawRect(1, h - 30 - 13, 26, h - 30 - 4, 0x90505050); FontRenderer.drawString("30ms", 2, h - 30 - 12, 0xE0E0E0); Gui.drawRect(1, h - 60 - 13, 26, h - 60 - 4, 0x90505050); FontRenderer.drawString("60ms", 2, h - 60 - 12, 0xE0E0E0); int width = FontRenderer.getStringWidth("ms/Frame"); Gui.drawRect(238 - width, h - 60 - 13, 239, h - 60 - 4, 0x90505050); FontRenderer.drawString("ms/Frame", 239 - width, h - 60 - 12, 0xE0E0E0); if(this.isServer()) { this.updateTick(); Gui.drawRect(w - 240, h - 74, w, h - 14, 0x90505050); x = w - 240; drawHorizontalLine(w - 240, w - 1, h - 44, 0x5fffffff); drawHorizontalLine(w - 240, w - 1, h - 74, 0x5fffffff); for (int n = 0; n < 240; ++n) { int value = this.tickTimes[(n + this.tickIndex) % 240]; int color = this.getFrameColor(value, 0, 50, 250); if(value > 0) drawVerticalLine(x, h - 14, h - 14 - value, color & 0xc0ffffff); ++x; shifted = (shifted + 1) % 240; } width = FontRenderer.getStringWidth("ms/Tick"); Gui.drawRect(w - 240 + 1, h - 30 - 13, w - 240 + 26, h - 30 - 4, 0x90505050); FontRenderer.drawString("30ms", w - 240 + 2, h - 30 - 12, 0xE0E0E0); Gui.drawRect(w - 240 + 1, h - 60 - 13, w - 240 + 26, h - 60 - 4, 0x90505050); FontRenderer.drawString("60ms", w - 240 + 2, h - 60 - 12, 0xE0E0E0); Gui.drawRect(w - 2 - width, h - 60 - 13, w - 1, h - 60 - 4, 0x90505050); FontRenderer.drawString("ms/Tick", w - 1 - width, h - 60 - 12, 0xE0E0E0); } GlState.enableDepth(); } */ private static void makeQuad(float[] polys, int o, float x, float z, float p, float q, float y00, float y10, float y01, float y11) { polys[o+0] = polys[o+25] = x; polys[o+1] = polys[o+26] = y00; polys[o+2] = polys[o+27] = z; polys[o+3] = polys[o+28] = 0.0f; polys[o+4] = polys[o+29] = 0.0f; polys[o+5] = x + p; polys[o+6] = y10; polys[o+7] = z; polys[o+8] = p; polys[o+9] = 0.0f; polys[o+10] = polys[o+15] = x + p; polys[o+11] = polys[o+16] = y11; polys[o+12] = polys[o+17] = z + q; polys[o+13] = polys[o+18] = p; polys[o+14] = polys[o+19] = q; polys[o+20] = x; polys[o+21] = y01; polys[o+22] = z + q; polys[o+23] = 0.0f; polys[o+24] = q; } public static interface GraphFunc { float apply(float x, float z); } public static int makeGraph(GraphFunc func, int xvals, int zvals, float xoffset, float zoffset, float xrange, float zrange, float ysize) { int x, z; float[] vertices = new float[30 * xvals * zvals]; for(x = 0; x < xvals; x++) { for(z = 0; z < zvals; z++) { makeQuad(vertices, (x + z * xvals) * 30, (float)x / (float)xvals, (float)z / (float)zvals, 1.0f / (float)xvals, 1.0f / (float)zvals, func.apply(xoffset + (float)x / (float)xvals * xrange, zoffset + (float)z / (float)zvals * zrange) * ysize, func.apply(xoffset + (float)(x + 1) / (float)xvals * xrange, zoffset + (float)z / (float)zvals * zrange) * ysize, func.apply(xoffset + (float)x / (float)xvals * xrange, zoffset + (float)(z + 1) / (float)zvals * zrange) * ysize, func.apply(xoffset + (float)(x + 1) / (float)xvals * xrange, zoffset + (float)(z + 1) / (float)zvals * zrange) * ysize); } } SKC.glBufferData(sizeof(float) * 30 * xvals * zvals, vertices); return xvals * zvals * 6; } public static int test() { final Ng gen = new Ng(...); return makeGraph(new GraphFunc() { public float apply(float x, float z) { double n; gen.generate(&n, (double)x, 0, (double)z, 1, 1, 1, 512.0, 512.0, 512.0); return (float)(n / 512.0); } }, 128, 128, 0.0f, 0.0f, 512.0f, 512.0f, 0.125f); }