Thread: [830 Matrix] Need Help Packing Items

Results 1 to 3 of 3
  1. #1 [830 Matrix] Need Help Packing Items 
    Registered Member ReMillion's Avatar
    Join Date
    Jul 2021
    Age
    33
    Posts
    15
    Thanks given
    2
    Thanks received
    1
    Rep Power
    11
    [Help][830 Matrix 3]



    Hello RuneServer. I am off and on studying Java... I am taking a 12 Hour Course over the next 2 to 3 weeks.
    But in the meantime I am trying to have fun with some of the Easy Things.

    This job is usually easy in an RSPS...
    I am simply trying to add items to the RS3 Map that can be picked up.

    I found some Packed and Unpacked Item Spawn Files.
    The Packed Item Files are written in .is
    Attached image

    I know the RSPS Server reads the items in the .is Packed Files.
    I placed a couple of items in the Unpacked Files.

    I was trying to figure out which application was used to Pack the Item Files and I found:
    ItemSpawns.Java in Server\src\com\rs\utils

    This is the exact File I want to trigger, the coding is here but i know this is what I want to do:
    Code:
    package com.rs.utils;
    
    import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    import java.nio.channels.FileChannel.MapMode;
    
    import com.rs.Settings;
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.game.World;
    import com.rs.game.WorldTile;
    import com.rs.game.item.Item;
    
    public final class ItemSpawns {
    
    	public static final void init() {
    		if (!new File("data/items/packedSpawns").exists())
    			packItemSpawns();
    	}
    
    	private static final void packItemSpawns() {
    		Logger.log("ItemSpawns", "Packing item spawns...");
    		if (!new File("data/items/packedSpawns").mkdir())
    			throw new RuntimeException("Couldn't create packedSpawns directory.");
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("data/items/unpackedSpawnsList.txt"));
    			while (true) {
    				String line = in.readLine();
    				if (line == null)
    					break;
    				if (line.startsWith("//"))
    					continue;
    				String[] splitedLine = line.split(" - ", 2);
    				if (splitedLine.length != 2) {
    					in.close();
    					throw new RuntimeException("Invalid generated item line: " + line + ", " + splitedLine.length);
    				}
    				int itemId = Integer.parseInt(splitedLine[0]);
    				String[] splitedLine2 = splitedLine[1].split(" ", 3);
    				if (splitedLine2.length != 3) {
    					in.close();
    					throw new RuntimeException("Invalid generated item line: " + line);
    				}
    				WorldTile tile = new WorldTile(Integer.parseInt(splitedLine2[0]), Integer.parseInt(splitedLine2[1]), Integer.parseInt(splitedLine2[2]));
    				addItemSpawn(itemId, tile.getRegionId(), tile);
    			}
    			in.close();
    		} catch (Throwable e) {
    			Logger.handle(e);
    		}
    	}
    
     @suppressWarnings("deprecation")
    	public static final void loadItemSpawns(int regionId) {
    		File file = new File("data/items/packedSpawns/" + regionId + ".is");
    		if (!file.exists())
    			return;
    		try {
    			RandomAccessFile in = new RandomAccessFile(file, "r");
    			FileChannel channel = in.getChannel();
    			ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());
    			while (buffer.hasRemaining()) {
    				int itemId = buffer.getShort() & 0xffff;
    				int plane = buffer.get() & 0xff;
    				int x = buffer.getShort() & 0xffff;
    				int y = buffer.getShort() & 0xffff;
    				World.addGroundItemForever(new Item(itemId, ItemDefinitions.getItemDefinitions(itemId).isStackable() ? Settings.getDropQuantityRate() : 1), new WorldTile(x, y, plane));
    			}
    			channel.close();
    			in.close();
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	private static final void addItemSpawn(int itemId, int regionId, WorldTile tile) {
    		try {
    			DataOutputStream out = new DataOutputStream(new FileOutputStream("data/items/packedSpawns/" + regionId + ".is", true));
    			out.writeShort(itemId);
    			out.writeByte(tile.getPlane());
    			out.writeShort(tile.getX());
    			out.writeShort(tile.getY());
    			out.flush();
    			out.close();
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	private ItemSpawns() {
    	}
    }
    My problem is... (Might be really Noobie):
    I don't know how to run this Java File...

    Can someone please help me?
    Studying Java for Elvarg [317]



    Discord:XeroXipher#7116
    GitHub:WORK IN PROGRESS



    Attached image
    Reply With Quote  
     

  2. #2  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Posts
    2,622
    Thanks given
    201
    Thanks received
    813
    Rep Power
    1462
    There is no main method so you cant directly run the class. However, if you look, there is a method

    Code:
    	public static final void init() {
    		if (!new File("data/items/packedSpawns").exists())
    			packItemSpawns();
    	}
    Based on the name, I would assume that this is called when the server is starting up. In this case, if the packed file does not exist it will pack a new file. As a result, I would expect that you can just delete the packedspawns folder and then rerun the server.

    Alternatively, you could add this method and run the class directly after deleting the packed spawns folder.


    Code:
    public static void main(String[] args) {
     init();
    }
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  3. #3  
    Registered Member ReMillion's Avatar
    Join Date
    Jul 2021
    Age
    33
    Posts
    15
    Thanks given
    2
    Thanks received
    1
    Rep Power
    11
    Thank you so much @Advocatus
    Studying Java for Elvarg [317]



    Discord:XeroXipher#7116
    GitHub:WORK IN PROGRESS



    Attached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 1
    Last Post: 04-05-2018, 07:21 AM
  2. Matrix 830 Hosting! Need HELP!! urgent. <3
    By icemaster766 in forum Help
    Replies: 1
    Last Post: 08-24-2016, 01:37 AM
  3. Need help Packing item bonuses, 667/704
    By Mos Def in forum Help
    Replies: 1
    Last Post: 07-27-2014, 02:27 PM
  4. [Matrix 718] Need help with item 4 gp command
    By Originalstrucks in forum Help
    Replies: 4
    Last Post: 07-31-2013, 07:25 PM
  5. need help adding item requirements
    By manilla rose in forum RS2 Server
    Replies: 1
    Last Post: 09-25-2007, 12:23 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •