Solved Clone a Block

Discussion in 'Plugin Development' started by ShowbizLocket61, Apr 6, 2016.

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

    ShowbizLocket61

    Hey,

    How does one clone a block, exactly? Setting type and data doesn't work with signs and chests, and BlockState#update() doesn't seem to do anything
     
  2. Offline

    Zombie_Striker

    @ShowbizLocket61
    What exactly do you mean by "Clone"? What are the values you wish to copy over to another block that do not work?
     
  3. Offline

    ShowbizLocket61

  4. Offline

    Zombie_Striker

    @ShowbizLocket61
    • The Material is just an enum value. You do not need to clone this object.
    • The data is a byte, which does not need to be cloned.
    • You can clone an instance of BlockMeta by using BlockMeta.clone()
    • You can clone the BlockState by using BlockState.clone();
     
  5. Offline

    ShowbizLocket61

    @Zombie_Striker
    Sure. The problem is how do I set the properties of a block to exactly that of the snapshot. Type and data take care of only color, direction, and material, and fails sign text and chest contents and various other things.
     
  6. Offline

    Zombie_Striker

    @ShowbizLocket61
    Code:
    Material mat = block.getType();
    byte data = block.getData();
    BlockState state = block.getState().clone();
    
    block.setType(mat);
    block.setData(data);
    block.setState(state);
     
  7. Offline

    ShowbizLocket61

    @Zombie_Striker
    Block#setState would be exactly what I'm looking for. However, it doesn't exist. :/
     
  8. Offline

    mythbusterma

    @ShowbizLocket61

    You save the state of the block, and update later. It works fine.
     
  9. Offline

    ShowbizLocket61

    @mythbusterma
    Update, as in BlockState#update()? I tried it, it doesn't change the block. Doesn't throw errors either.
     
  10. Offline

    mythbusterma

  11. Offline

    Lightspeed

  12. Offline

    mythbusterma

    @Lightspeed

    But why? Just why...

    Code:
    BlockState state = block.getState();
    
    // ..... later on
    
    state.update();
    That's literally all that's required, not some stupid NBT crap.
     
  13. Offline

    mcdorli

    Guess what, state consist of data, type, location, etc, you don't need to set it back.
     
  14. Offline

    Lightspeed

    That doesn't copy inventory and a few more things I belive. ;-;
     
  15. Offline

    I Al Istannen

  16. Offline

    ShowbizLocket61

    @mcdorli
    I'm trying to revert the block.
     
  17. Offline

    Lightspeed

    So leme get this straight. . . You need to copy any set of blocks EXACTLY(Sign data/Inventory) and then revert it on request?
     
  18. Offline

    ShowbizLocket61

  19. Offline

    mcdorli

    Store their blockstate in a list, it contains everything you need.
     
  20. Offline

    ShowbizLocket61

    @mcdorli
    Yes, I know that >.<
    The problem is how I can revert it.
     
  21. Offline

    mcdorli

    By setting the type, then the data, etc.
     
  22. Offline

    mythbusterma

  23. Offline

    ShowbizLocket61

    @mythbusterma
    Thanks, mate. I didn't see the part where update() "will not modify the state of a block if it is no longer the same type."
     
Thread Status:
Not open for further replies.

Share This Page