public static Texture getTextureFromPath(String path) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { if (textures.containsKey(path)) { return textures.get(path); } Texture texture = null; try { FileInputStream stream = new FileInputStream(path); if (stream.available() > 0) { texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST); } stream.close(); } catch (IOException e) { } if (texture != null) { textures.put(path, texture); } return texture; } finally { SpoutClient.enableSandbox(wasSandboxed); } }
public static Texture getTextureFromJar(String path) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { if (textures.containsKey(path)) { return textures.get(path); } Texture texture = null; // Check inside jar try { InputStream stream = Minecraft.class.getResourceAsStream(path); texture = TextureLoader.getTexture("PNG", stream, true, GL11.GL_NEAREST); stream.close(); } catch (Exception e) { } // Check MCP/Eclipse Path if (texture == null) { texture = getTextureFromPath( FileUtil.getSpoutcraftDirectory().getAbsolutePath() + "/../.." + path); } if (texture != null) { textures.put(path, texture); } return texture; } finally { SpoutClient.enableSandbox(wasSandboxed); } }
@SuppressWarnings("unchecked") public void readData(SpoutInputStream input) throws IOException { String packetName = input.readString(); boolean sandboxed = SpoutClient.isSandboxed(); SpoutClient.enableSandbox(); try { Class<? extends AddonPacket> packetClass = AddonPacket.getPacketFromId(packetName); Constructor<? extends AddonPacket> constructor = null; Constructor<? extends AddonPacket>[] constructors = (Constructor<? extends AddonPacket>[]) packetClass.getConstructors(); for (Constructor<? extends AddonPacket> c : constructors) { if (c.getGenericParameterTypes().length == 0) { constructor = c; break; } } packet = constructor.newInstance(); } catch (Exception e) { e.printStackTrace(); } if (!sandboxed) { SpoutClient.disableSandbox(); } int size = input.readInt(); compressed = input.readBoolean(); data = new byte[size]; input.read(data); }
public static boolean isTextureDownloaded(String addon, String url) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { return getTextureFile(addon, url).exists(); } finally { SpoutClient.enableSandbox(wasSandboxed); } }
public void run(int playerId) { World world = SpoutClient.getHandle().theWorld; TileEntity te = world.getBlockTileEntity(x, y, z); if (te != null && te instanceof TileEntitySign) { TileEntitySign sign = (TileEntitySign) te; GuiEditSign gui = new GuiEditSign(sign); SpoutClient.getHandle().displayGuiScreen(gui); } }
public void render(int x, int y, int width, int height) { MCRenderDelegate r = (MCRenderDelegate) SpoutClient.getInstance().getRenderDelegate(); FontRenderer font = SpoutClient.getHandle().fontRenderer; String sResolution = resolution + "x"; int sWidth = font.getStringWidth(sResolution); font.drawStringWithShadow(sResolution, x + width - sWidth - 2, y + 2, 0xffaaaaaa); String name = r.getFittingText(getName(), width - 29 - sWidth - 2 - x); font.drawStringWithShadow(name, x + 29, y + 2, 0xffffffff); String sStatus = ""; if (size > 1024 * 1024 * 9000) { sStatus = ChatColor.RED + "It's over 9000! "; } if (size > 1024 * 1024) { sStatus += size / (1024 * 1024) + " MB"; } else if (size > 1024) { sStatus = size / 1024 + " KB"; } else { sStatus = size + " Bytes"; } if (isDownloading()) { sStatus = "Downloading: " + ChatColor.WHITE + download.getProgress() + "%"; } if (downloadFail != null) { sStatus = downloadFail; } if (installed) { sStatus = ChatColor.GREEN + "Installed"; } if (sStatus != null) { sWidth = font.getStringWidth(sStatus); font.drawStringWithShadow(sStatus, x + width - sWidth - 2, y + 11, 0xffaaaaaa); } String author = "by " + ChatColor.WHITE + getAuthor(); author = r.getFittingText(author, width - 29 - sWidth - 2 - x); font.drawStringWithShadow(author, x + 29, y + 11, 0xffaaaaaa); String desc = r.getFittingText(getDescription(), width - 2 - 29); font.drawStringWithShadow(desc, x + 29, y + 20, 0xffaaaaaa); String iconUrl = getIconUrl(); Texture icon = CustomTextureManager.getTextureFromUrl(iconUrl); if (icon == null) { CustomTextureManager.downloadTexture(iconUrl, true); } else { GL11.glPushMatrix(); GL11.glTranslated(x + 2, y + 2, 0); r.drawTexture(icon, 25, 25); GL11.glPopMatrix(); } }
public void download() { if (download == null && !installed) { downloadFail = null; boolean wasSandboxed = SpoutClient.isSandboxed(); if (wasSandboxed) SpoutClient.disableSandbox(); download = new Download(this); downloads.put(getId(), download); download.start(); if (wasSandboxed) SpoutClient.enableSandbox(); } }
@Override protected void buttonClicked(Button btn) { if (btn == doneButton) { SpoutClient.getHandle().displayGuiScreen(parent); } if (btn == switchToAdvancedCheck) { Configuration.setAdvancedOptions(true); Configuration.write(); SpoutClient.getHandle().displayGuiScreen(new GuiAdvancedOptions(parent)); } }
private String completeNames(String message) { tabHelp = null; String[] words = message.split(" "); if (words.length > 0) { String lastWord = words[words.length - 1]; if (lastWord.endsWith("_")) { lastWord = lastWord.substring(0, lastWord.length() - 1); } if (lastWord.length() > 2) { // Check nearby players Player p = SpoutClient.getInstance().getPlayer(lastWord); String playerName = p != null ? p.getName() : null; // Check server player list if (playerName == null && SpoutClient.getHandle().isMultiplayerWorld()) { int delta = Integer.MAX_VALUE; String best = null; final List<GuiPlayerInfo> players = ((EntityClientPlayerMP) SpoutClient.getHandle().thePlayer).sendQueue.playerNames; final String toLower = lastWord.toLowerCase(); for (GuiPlayerInfo info : players) { String name = ChatColor.stripColor(info.name); if (name.toLowerCase().startsWith(toLower)) { int curDelta = info.name.length() - lastWord.length(); if (curDelta < delta) { best = name; delta = curDelta; } if (curDelta == 0) { break; } } } if (best != null) { playerName = best; } } // Autocomplete if (playerName != null && playerName.length() > lastWord.length()) { message = message.substring(0, message.length() - 1) + "|" + ChatColor.YELLOW + playerName.substring(lastWord.length()) + ChatColor.RESET; tabHelp = playerName.substring(lastWord.length()); } } } return message; }
public void save() { boolean wasSandboxed = SpoutClient.disableSandbox(); Yaml yaml = new Yaml(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ignore", ignorePeople); map.put("highlight", wordHighlight); try { yaml.dump(map, new FileWriter(getFile())); } catch (IOException e) { e.printStackTrace(); } SpoutClient.enableSandbox(wasSandboxed); }
public void load() { boolean wasSandboxed = SpoutClient.disableSandbox(); Yaml yaml = new Yaml(); try { Object l = yaml.load(new FileReader(getFile())); HashMap<String, Object> map = (HashMap<String, Object>) l; ignorePeople = (List<String>) map.get("ignore"); wordHighlight = (List<String>) map.get("highlight"); } catch (FileNotFoundException e) { ignorePeople = new ArrayList<String>(); wordHighlight = new ArrayList<String>(); } SpoutClient.enableSandbox(wasSandboxed); }
@Override protected void executeAction() { MinimapConfig.initialize(false); MinimapConfig.getInstance().save(); SpoutClient.getHandle().displayGuiScreen(new GuiMinimapMenu(parent.parent)); }
protected void buttonClicked(Button btn) { if (btn.equals(recordButton)) { recording = !recording; updateRecordButton(); } if (btn.equals(doneButton)) { item.setTitle(commandText.getText()); if (!item.getTitle().equals("") && item.getKey() != -1) { SimpleKeyBindingManager manager = (SimpleKeyBindingManager) SpoutClient.getInstance().getKeyBindingManager(); manager.unregisterShortcut(item); manager.registerShortcut(item); } mc.displayGuiScreen(parent); parent.getModel().refresh(); } if (btn.equals(addButton)) { editCommand(-1); } if (btn.equals(editButton)) { editCommand(slot.getSelectedRow()); } if (btn.equals(removeButton)) { item.removeCommand(slot.getSelectedRow()); slot.updateItems(); updateButtons(); } }
private void entityCalc() { synchronized (map.watchedEntities) { map.watchedEntities.clear(); if (!Spoutcraft.hasPermission("spout.plugin.minimap.showentities")) { return; } if (!MinimapConfig.getInstance().isShowingEntities()) { return; } int radius = map.renderSize / 2; double playerX = map.getPlayerX(); double playerZ = map.getPlayerZ(); for (Object ob : SpoutClient.getHandle() .theWorld .getEntitiesWithinAABB( EntityLiving.class, AxisAlignedBB.getBoundingBox( playerX - radius, 0, playerZ - radius, playerX + radius, 256, playerZ + radius))) { net.minecraft.src.Entity e = (net.minecraft.src.Entity) ob; if (!MinimapConfig.getInstance().isEntityVisible(e.getClass())) { continue; } WatchedEntity w = new WatchedEntity(e); if (w.getTexture() != null) { map.watchedEntities.add(w); } } } }
public void sendChat(String message) { if (!Spoutcraft.hasPermission("spout.client.chatcolors")) { message = message.replaceAll("(&([a-fA-F0-9]))", ""); } List<String> lines = formatChat(message, false); for (String chat : lines) { SpoutClient.getHandle().thePlayer.sendChatMessage(chat); } }
public static Texture getTextureFromUrl(String plugin, String url, boolean download) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { File texture = getTextureFile(plugin, url); if (!texture.exists()) { return null; } try { return getTextureFromPath(texture.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); return null; } } finally { SpoutClient.enableSandbox(wasSandboxed); } }
public void run(int playerId) { if (packet != null) { SpoutInputStream stream = new SpoutInputStream(ByteBuffer.wrap(data)); boolean sandboxed = SpoutClient.isSandboxed(); SpoutClient.enableSandbox(); try { packet.read(stream); packet.run(); } catch (Exception e) { e.printStackTrace(); } if (!sandboxed) { SpoutClient.disableSandbox(); } } }
public void render(int x, int y, int width, int height) { FontRenderer font = SpoutClient.getHandle().fontRenderer; parent.drawString(font, cmd, x + 2, y + 2, 0xffffff); if (cmd.startsWith("/")) { parent.drawString(font, "Command", x + 2, y + 13, 0xaaaaaa); } else { parent.drawString(font, "Chat Message", x + 2, y + 13, 0xaaaaaa); } }
public PacketAddonData(AddonPacket packet) { this.packet = packet; SpoutOutputStream stream = new SpoutOutputStream(); boolean sandboxed = SpoutClient.isSandboxed(); SpoutClient.enableSandbox(); try { packet.write(stream); } catch (Exception e) { e.printStackTrace(); } if (!sandboxed) { SpoutClient.disableSandbox(); } ByteBuffer buffer = stream.getRawBuffer(); data = new byte[buffer.capacity() - buffer.remaining()]; System.arraycopy(buffer.array(), 0, data, 0, data.length); needsCompression = data.length > 512; }
public static String getTexturePathFromUrl(String plugin, String url) { if (!isTextureDownloaded(plugin, url)) { return null; } boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { File download = new File(FileUtil.getTempDirectory(), FileUtil.getFileName(url)); try { return download.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } } finally { SpoutClient.enableSandbox(wasSandboxed); } return null; }
public static void downloadTexture(String plugin, String url, boolean ignoreEnding) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { String fileName = FileUtil.getFileName(url); if (!ignoreEnding && !FileUtil.isImageFile(fileName)) { System.out.println("Rejecting download of invalid texture: " + fileName); } else if (!isTextureDownloading(url) && !isTextureDownloaded(plugin, url)) { File dir = FileUtil.getTempDirectory(); if (plugin != null) { dir = new File(FileUtil.getCacheDirectory(), plugin); dir.mkdir(); } Download download = new Download(fileName, dir, url, null); FileDownloadThread.getInstance().addToDownloadQueue(download); } } finally { SpoutClient.enableSandbox(wasSandboxed); } }
public static File getTextureFile(String plugin, String url) { boolean wasSandboxed = SpoutClient.isSandboxed(); SpoutClient.disableSandbox(); try { String fileName = FileUtil.getFileName(url); File cache = cacheTextureFiles.get(plugin + File.separator + fileName); if (cache != null) { return cache; } if (plugin != null) { File file = FileUtil.findFile(plugin, fileName); if (file != null) { cacheTextureFiles.put(plugin + File.separator + fileName, file); return file; } } return new File(FileUtil.getTempDirectory(), fileName); } finally { SpoutClient.enableSandbox(wasSandboxed); } }
public boolean handleCommand(String command) { try { if (command.equals("/?") || command.startsWith("/client help")) { SpoutClient.getHandle() .ingameGUI .addChatMessage(ChatColor.YELLOW.toString() + "Spoutcraft Client Debug Commands:"); SpoutClient.getHandle().ingameGUI.addChatMessage("/client gc - run the garbage collector"); return true; } else if (command.startsWith("/client gc")) { SpoutClient.getHandle() .ingameGUI .addChatMessage(ChatColor.YELLOW.toString() + "Starting Garbage Collection..."); long start = System.currentTimeMillis(); long mem = Runtime.getRuntime().freeMemory(); long time = 250; if (command.split(" ").length > 2) { try { time = Long.parseLong(command.split(" ")[2]); } catch (Exception ignore) { } } while ((System.currentTimeMillis() - start) < time) { System.gc(); } SpoutClient.getHandle() .ingameGUI .addChatMessage(ChatColor.GREEN.toString() + "Garbage Collection Complete!"); SpoutClient.getHandle() .ingameGUI .addChatMessage( ChatColor.GREEN.toString() + (Runtime.getRuntime().freeMemory() - mem) / (1024D * 1024D) + " mb of memory freed"); return true; } } catch (Exception e) { } return false; }
// Don't call this method, for future use. protected Texture getTextureFromCoords(World world, int x, int y, int z) { short customId = 0; Texture texture = null; if (SpoutClient.getInstance().getRawWorld() != null) { SpoutcraftChunk sChunk = Spoutcraft.getChunkAt(SpoutClient.getInstance().getRawWorld(), x, y, z); customId = sChunk.getCustomBlockId(x, y, z); short[] customBlockIds = sChunk.getCustomBlockIds(); byte[] customBlockData = sChunk.getCustomBlockData(); if (customId > 0) { CustomBlock block = MaterialData.getCustomBlock(customId); if (block != null) { BlockDesign design = block.getBlockDesign(customBlockData[customId]); if (design != null) { texture = getTextureFromUrl(block.getAddon(), design.getTextureURL()); } } } } return texture; }
public List<String> formatChat(String message, boolean display) { final LinkedList<String> lines = new LinkedList<String>(); final FontRenderer font = Minecraft.theMinecraft.fontRenderer; final int width = (int) SpoutClient.getInstance().getActivePlayer().getMainScreen().getChatBar().getWidth() - 6; if (message.startsWith("/")) { if (display) { message = completeNames(message); } if (message.length() > 99) { message = message.substring(0, 100); } lines.add(message); return lines; } if (display) { message = completeNames(message); } StringBuilder builder = new StringBuilder(100); int lineWidth = 0; for (int i = 0; i < message.length(); i++) { char ch = message.charAt(i); int charWidth = font.getStringWidth(String.valueOf(ch)); if (lineWidth + charWidth < width && (display || builder.length() < 99)) { builder.append(ch); lineWidth += charWidth; } else { lines.add(builder.toString()); builder.delete(0, builder.length()); builder.append(ch); lineWidth = charWidth; } } if (builder.length() > 0) { lines.add(builder.toString()); } return lines; }
/** Abstract. Reads the raw packet data from the data stream. */ public void readPacketData(DataInputStream par1DataInputStream) throws IOException { this.xCh = par1DataInputStream.readInt(); this.zCh = par1DataInputStream.readInt(); this.includeInitialize = par1DataInputStream.readBoolean(); this.yChMin = par1DataInputStream.readShort(); this.yChMax = par1DataInputStream.readShort(); this.tempLength = par1DataInputStream.readInt(); if (temp.length < this.tempLength) { temp = new byte[this.tempLength]; } par1DataInputStream.readFully(temp, 0, this.tempLength); int var2 = 0; int var3; for (var3 = 0; var3 < 16; ++var3) { var2 += this.yChMin >> var3 & 1; } var3 = 12288 * var2; if (this.includeInitialize) { var3 += 256; } this.field_73596_g = new byte[var3]; Inflater var4 = new Inflater(); var4.setInput(temp, 0, this.tempLength); try { var4.inflate(this.field_73596_g); } catch (DataFormatException var9) { throw new IOException("Bad compressed data format"); } finally { var4.end(); } // Spout Start SpoutClient.getInstance() .getPacketManager() .sendSpoutPacket(new PacketCustomBlockChunkOverride(xCh, zCh)); // Spout End }
public void deleteCurrentControl() { SimpleKeyBindingManager man = (SimpleKeyBindingManager) SpoutClient.getInstance().getKeyBindingManager(); ControlsBasicItem item = model.getItem(view.getSelectedRow()); ShortcutBindingItem sh = null; if (item != null && item instanceof ShortcutBindingItem) { sh = (ShortcutBindingItem) item; } KeyBindingItem binding = null; if (item != null && item instanceof KeyBindingItem) { binding = (KeyBindingItem) item; } if (sh != null) { man.unregisterShortcut(sh.getShortcut()); man.save(); } else if (binding != null) { man.unregisterControl(binding.getBinding()); man.save(); model.refresh(); } else { item.setKey(-128); } model.refresh(); }
public Point getPlayerPosition() { int x = (int) SpoutClient.getHandle().thePlayer.posX; int z = (int) SpoutClient.getHandle().thePlayer.posZ; return new Point(x, z); }
@Override public void renderContents() { GL11.glDisable(2929); GL11.glEnable(3042); GL11.glDepthMask(false); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int scrollX = (int) (getScrollPosition(Orientation.HORIZONTAL) / scale); int scrollY = (int) (getScrollPosition(Orientation.VERTICAL) / scale); GL11.glScaled(scale, scale, scale); GL11.glTranslatef(-heightMap.getMinX() * 16, -heightMap.getMinZ() * 16, 0); int minChunkX = heightMap.getMinX() + scrollX / 16, minChunkZ = heightMap.getMinZ() + scrollY / 16, maxChunkX = 0, maxChunkZ = 0; int horiz = (int) (getWidth() / 16 / scale) + 1; int vert = (int) (getHeight() / 16 / scale) + 1; maxChunkX = minChunkX + horiz; maxChunkZ = minChunkZ + vert; minChunkX = Math.max(minChunkX, heightMap.getMinX()); minChunkZ = Math.max(minChunkZ, heightMap.getMinZ()); maxChunkX = Math.min(maxChunkX, heightMap.getMaxX()); maxChunkZ = Math.min(maxChunkZ, heightMap.getMaxZ()); GL11.glPushMatrix(); synchronized (chunks) { for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX += levelOfDetail) { for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ += levelOfDetail) { Map map = getChunkMap(levelOfDetail).get(chunkX, chunkZ); if (dirty || map == null || random.nextInt(10000) == 0) { renderer.renderQueue.add(new Point(chunkX, chunkZ)); } if (map != null && map != blankMap) { GL11.glPushMatrix(); int x = chunkX * 16; int y = chunkZ * 16; int width = x + 16 * levelOfDetail; int height = y + 16 * levelOfDetail; map.loadColorImage(); MinecraftTessellator tessellator = Spoutcraft.getTessellator(); tessellator.startDrawingQuads(); tessellator.addVertexWithUV((double) width, (double) height, -90, 1, 1); tessellator.addVertexWithUV((double) width, (double) y, -90, 1, 0); tessellator.addVertexWithUV((double) x, (double) y, -90, 0, 0); tessellator.addVertexWithUV((double) x, (double) height, -90, 0, 1); tessellator.draw(); // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // RenderUtil.drawRectangle(x, y, width, height, 0x88ffffff); if (MinimapConfig.getInstance().isHeightmap()) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_COLOR); map.loadHeightImage(); tessellator.startDrawingQuads(); tessellator.addVertexWithUV((double) width, (double) height, -90, 1, 1); tessellator.addVertexWithUV((double) width, (double) y, -90, 1, 0); tessellator.addVertexWithUV((double) x, (double) y, -90, 0, 0); tessellator.addVertexWithUV((double) x, (double) height, -90, 0, 1); tessellator.draw(); } GL11.glPopMatrix(); } } } } int x = (int) SpoutClient.getHandle().thePlayer.posX; int z = (int) SpoutClient.getHandle().thePlayer.posZ; drawPOI("You", x, z, 0xffff0000); for (Waypoint waypoint : MinimapConfig.getInstance().getAllWaypoints(MinimapUtils.getWorldName())) { if (!waypoint.deathpoint || MinimapConfig.getInstance().isDeathpoints()) { drawPOI(waypoint.name, waypoint.x, waypoint.z, 0xff00ff00); } } if (MinimapConfig.getInstance().getFocussedWaypoint() != null) { Waypoint pos = MinimapConfig.getInstance().getFocussedWaypoint(); drawPOI("Marker", pos.x, pos.z, 0xff00ffff); } GL11.glPopMatrix(); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(2929); GL11.glDisable(3042); dirty = false; Point newpos = getPlayerPosition(); if (lastPlayerPos.getX() != newpos.getX() || lastPlayerPos.getY() != newpos.getY()) { showPlayer(0); lastPlayerPos = newpos; } }
private void updateGeometry() { FontRenderer font = SpoutClient.getHandle().fontRenderer; this.width = (float) font.getStringWidth(text) * 0.0139F * scale; this.height = 0.124F * scale; }