Solved Get and set nbt tags to blocks(Simple Awnser Below ;) !!!)

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

?

Nbt tags are awesome(Light is bored so he makes a poll)

  1. CRAP YEAH!!!

    1 vote(s)
    33.3%
  2. Sure!

    0 vote(s)
    0.0%
  3. Not really. . .

    1 vote(s)
    33.3%
  4. What is wrong with you light. . .

    1 vote(s)
    33.3%
Thread Status:
Not open for further replies.
  1. Offline

    Lightspeed

    I need to get nbt tags of a block and then set it to another block.
    Simple enough?
     
  2. Offline

    Zombie_Striker

    @Lightspeed
    Please click the link in my signature.

    What have you tried? Can you post what you tried? What is not working?
     
  3. Offline

    Lightspeed

    @Zombie_Striker Well I tried grabbing data from the block I was looking at and set it to the same block with the same data at my location.
    Nothing amazing I just thought data would have the things I need like items in chest and sign data.
    Code erm just
    Code:
    block2.setData(block.getData());
    . . .
    I don't see any need for this in the question.
     
    Last edited: Jan 14, 2016
  4. Offline

    Lightspeed

    Omg guys I'm so proud of myself! :D
    Code:
    Player p = (Player) s;
                    Location loc = p.getTargetBlock((HashSet<Byte>) null, 0).getLocation();
                    Location loc2 = p.getLocation();
                    Block b = p.getWorld().getBlockAt(loc);
                    Block b2 = p.getWorld().getBlockAt(p.getLocation());
                    b2.setTypeIdAndData(b.getTypeId(), b.getData(), false);
                    CraftWorld cw = (CraftWorld)p.getWorld();
                    TileEntity tileEntity = cw.getTileEntityAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
                    TileEntity tileEntity2 = cw.getTileEntityAt(loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ());
                    WorldServer we = cw.getHandle();
                    we.setTileEntity(tileEntity2.getPosition(), tileEntity);
    Hopefully you can learn from this test code I created to learn myself.
    It basically takes the block the players is looking at and COMPLETLY copies it to were hes standing.
    **MAYBE**
    Also you can use we.SomeSetting = true/false; to change settings thru the plugin I belive(MAYBE NOT)
    **MAYBE**
    If your going to copy/paste please learn what it does and use some of the code. This code will generate an error setting 1 tileEntity to another(Bukkit will fix it but, the second block you break of the 2 you copied will send a message to console!)

    You might wana create your own tile entity instead of copying it like I did.
    Bukkit will fix everything but, It will spam your console(Remember this is just code to learn not to to perform).
    EDIT: Thx mod I accidentaly erased ur edit sorry.
    ANOTHEREDIT: Like I said learn how this code works and learn from it. It isn't code to run
     
    Last edited: Jan 18, 2016
  5. Offline

    Lightspeed

    Proper Code No Errors(May have uneeded lines of code)
    Code:
    Player p = (Player) s;
    Location loc = p.getTargetBlock((HashSet<Byte>) null, 0).getLocation();
    Location loc2 = p.getLocation();
    Block b = p.getWorld().getBlockAt(loc);
    Block b2 = p.getWorld().getBlockAt(p.getLocation());
    b2.setTypeIdAndData(b.getTypeId(), b.getData(), true);
    CraftWorld cw = (CraftWorld) p.getWorld();
    TileEntity tileEntity = cw.getTileEntityAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    TileEntity tileEntity2 = cw.getTileEntityAt(loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ());
    NBTTagCompound ntc = new NBTTagCompound();
    NBTTagCompound ntc2 = new NBTTagCompound();
    tileEntity.b(ntc);
    ntc2 = (NBTTagCompound) ntc.clone();
    ntc2.setInt("x", loc2.getBlockX());
    ntc2.setInt("y", loc2.getBlockY());
    ntc2.setInt("z", loc2.getBlockZ());
    tileEntity2.a(ntc2);
    tileEntity2.update();
    So easy!
    Feel free to use code above(Please learn what it does first so you can remove uneeded crap if there)!
     
Thread Status:
Not open for further replies.

Share This Page