Util change blocks

Discussion in 'Resources' started by The_Spaceman, Aug 2, 2017.

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

    The_Spaceman

    I've made a method that lets you set the block for a block

    I made this for copying and pasting a regen of a world.
    (like //copy and //pase from WorldEdit)

    as far as I know this doesn't break on a Bukkit update.

    code:
    https://pastebin.com/vuzKGmvd

    quick fix for the code:
    Code:
    case CHEST:
    case TRAPPED_CHEST:
        Chest toChest = (Chest) blockTo.getState();
        Chest fromChest = (Chest) blockFrom.getState();
    
        toChest.setCustomName(fromChest.getCustomName());
        try {
            toChest.getInventory().setContents(fromChest.getInventory().getContents());
        } catch (IllegalArgumentException e) {
            //catch the half double chest exception
        }
        toChest.setLock(fromChest.getLock());
        toChest.update();
    
        break;
    
    replace the "case CHEST:" with that, this fixes the traped_chest and if you are replaceing a double chest you wont get an error. when replaceing a double chest the first chest contains a half inventory and you are putting in a full inventory. bc that isnt possible you have to catch it and let the inventory be filled when its a double chest

    If you have any questions don't be afraid to ask me.
     
    Last edited: Aug 7, 2017
    MightyOne likes this.
  2. Offline

    Blares

    to get a block is simple to change it is simple. block.setType(Material.something);
     
  3. Offline

    timtower Administrator Administrator Moderator

    Doesn't take over inventories and metadata.
    This code does.
     
    Maxx_Qc likes this.
Thread Status:
Not open for further replies.

Share This Page