BlockState gets changed by change of Block

Discussion in 'Plugin Development' started by Lordloss, Jan 11, 2016.

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

    Lordloss

    Hey guys, i just dont get it.

    What i do:
    Im getting BlockChanges from the LogBlock API, and store the BlockState into an ArrayList.
    Then i set the type of the Blocks to diamond ore, and try to reset them after 30 ticks.

    The problem:
    The BlockState gets affected by the .getBlock().setType(Material.DIAMOND_ORE);
    but shouldnt be the BlockState a snapshot from the Block at the time i stored it?

    am i missing something?

    Code:
        final List<BlockChange> bc = bcDummy;
        final ArrayList<BlockState> bs = new ArrayList();
    
        for (BlockChange b : bc) {
           
            if (b.replaced != 56) continue;
           
            bs.add(b.getLocation().getBlock().getState());
            b.getLocation().getBlock().setType(Material.DIAMOND_ORE);   
        }
    
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    
            public void run() {
    
                for (BlockState b : bs) {
    
                    b.update();
                }
            }
           },30);
     
  2. Offline

    ski23

    What do you mean it gets affected by? Could you be very specific.
     
  3. Offline

    Zombie_Striker

    @Lordloss
    You see, you are not storing a snapshot of the block state in the array, you are storing the location in the memory. (If you are confused, I suggest looking at this.) The thing is, what you want is to clone the object because you do not want the stored object to be affect by what is actually there.
     
Thread Status:
Not open for further replies.

Share This Page