How to remove item drops in unloaded chunks!

Discussion in 'Plugin Development' started by Paxination, Jan 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Paxination

    http://pastebin.com/13bBALpL

    I am trying to clear all ITEMS in a radius of a specific location that MAY or MAY NOT be loaded.

    I can get that code to work if I am in the chunk. But the point of it is so I dont have to be in that chunk.

    I've tried several different ways of loading the chunks. And at this point I use a runTaskLater to give the server time to load all the chunks. And its not working. And yes I am preventing the chunks from unloading in my listener as I save the chunks to a List<Chunk>. And once done it clears it.

    Any other suggestions?
     
  2. Offline

    xTrollxDudex

    Paxination
    If thechunk is unloaded, players must be pretty far from it, use .setRemoveWhenFarAway(true)
     
  3. Offline

    RawCode

    i can't see any logic in your code.
    if you want to remove items inside chunk, just fetch chunk object with world.getChunkAt () and remove items from given chunk.
     
  4. Offline

    Paxination

    xTrollxDudex .setRemoveWhenFarAway(boolean) is undefined for both Entities and Items. Isnt that method for LivinigEntities? I am working with Items, mentioned it in my opening post.

    RawCode Dont know how you dont see any logic in it, yeah its a bit messy, i was up all night working on it and it started getting frustrating. But it partially works. Only when I am near the location im trying to clean up. But if you look just a WEE bit closer I am doing exactly that...its just I am (at this point) trying to iterate through all neighboring chunks with this...

    Code:java
    1. for(int x=-radius;x<radius; x = x + 16){
    2. for(int z=-radius;z<radius;z=z+16){
    3. plugin.eList.add(world.getChunkAt(this.x + x, this.z + z));
    4. world.loadChunk(this.x + x, this.z + z);
    5. }
    6. }


    And loading them before i attept to remove items. AFAIK you cant do any thing with a chunk while the chunk is unloaded. At least with entities! The chunk has to be loaded to work with them. As with my mob tp code, i have to add the chunk the mob is in so the server doesnt unload it, else my mob doesnt TP even tho it says it is.

    It was a lot simplier earlier. This rendition just got more complex than what I had before as the items will not get removed if im not in the area. So I attempted to try and load the chunks in the area and then remove the items, but it still doesnt work. Only if a player is near the chunk to load it.
     
  5. Offline

    xTrollxDudex

    Paxination
    Posted without thinking :/ sorry.

    Try subtracting the number of times you want to iterate by the radius, I'm sure this is what you are doing:
    Code:
    + - | + +
    ---------
    - - | - +
    Right now, you are only doing the top right. If you subtract it, you can expand it to the ther 3 quadrants, if you understand.
     
  6. Offline

    Paxination

    Code:java
    1. for(int x=-radius;x<radius; x = x + 16){
    2. for(int z=-radius;z<radius;z=z+16){
    3. plugin.eList.add(world.getChunkAt(this.x + x, this.z + z));
    4. world.loadChunk(this.x + x, this.z + z);
    5. }
    6. }


    xTrollxDudex I am doing that in the code i just repasted. Yeah i know what you mean by quadrants, like on graph paper. -x and -z is lower left quadrant -x +z is upper left, ect ...ect...

    Int x = -radius, x < radius , x=x+16

    X starts off as the negative of my search radius, When X = radius or higher, loop stops, and we are incrementing by 16 to shift it to other chunks.

    Z starts off as the negative of my search radius and if X and Z are both negative, i am starting in the bottom left quadrant. both loops stop when Z is equal to my search radius and X is equal to my search radius. WHich is the top right quadrant.

    It might be easier to read if I had put some spaces in it, my bad. As I said I was up all night over this. I literally could not sleep with this hanging over my head.

    Oh i see what your thinking. world.loadChunk(this.x PLUS x, this.z PLUS z); x and z both start off as negatives and added to this.x and this.z. So its actually subtract it as a negative from the for loop. It any of that made sense.
     
  7. Offline

    RawCode

    Entity[] eay = world.getchunkat().getEntities ()
    for (Entity E : eay) {}

    i absolutely can't see any logic in your code, why you enumerate chunks, why you use some delayed task, everything you need to pick chunks in given area and process them.
     
  8. Offline

    Paxination

    That wont work. The chunks are not loaded. getchunkat() only returns the instance of the chunk. Does not load it. I know how to iterate through entities. But they will not be removed if the chunk is not LOADED.

    You input the x, y and z with radius, i get the first chunk from that. This is the center of where I want to start search for Items. I start iterating through all chunks to LOAD them. I add the chunks reference to a list, and onChunkUnload I compare the unloading chunk with the list and cancel if it matches to keep it loaded. Cuz it can unload as fast as it loaded. Then I delete the entities.

    Not to mention, the items could be spread out in several chunks in that area so your way is leaving me short if it does work.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page