Solved Set a block's tile entity data

Discussion in 'Plugin Development' started by fireboyev, Feb 6, 2017.

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

    fireboyev

    Hey all, I was wondering how to grab the tile entity(Container) data from one block and set it to another. I have tried using this:


    Code:
            CraftWorld cw = (CraftWorld)newloc.getWorld();
            TileEntity oldtileEntity = cw.getHandle().getTileEntity(new BlockPosition(oldblock.getX(), oldblock.getY(), oldblock.getZ()));
            TileEntity newtileEntity = cw.getHandle().getTileEntity(new BlockPosition(newblock.getX(), newblock.getY(), newblock.getZ()));
            newtileEntity = oldtileEntity;
            NBTTagCompound ntc = new NBTTagCompound();
            newtileEntity.save(ntc);
    but it just doesn't work.
    there are no errors on actual tile entities but there are on normal blocks (that's just cause I didn't add a check yet.)
     
  2. @fireboyev
    What makes you think that should copy over the data? All you do is get two tileentities, set one equal to the other and create a completely new CompoundTag
     
  3. Offline

    Rayzr522

    @fireboyev
    All your code will do is clear all data on the first tileentity. You need to get the CompoundTag from the old TE, and save it to the new TE. You can probably do that in about 3 lines.
     
  4. Offline

    fireboyev

    @Rayzr522
    and how would I get the CompoundTag from the old tile entity?

    -EDIT-

    I tried using println() to check what oldtileEntity.save(ntc) was outputting and it is outputting the correct data in the slots, now how do I save the data in the newtileEntity?

    -EDIT AGAIN-
    It seems that I can't access the oldtileEntity after saving it to the new
     
    Last edited: Feb 7, 2017
  5. @fireboyev
    Code:java
    1. // This gets the compound from the current chest (it's a confusing name, I know)
    2. tileEntity.save(new NBTTagCompound())
    3. // This sets the compound to the new chest. Input the old compound tag into this method, and you should be good to go.
    4. newTileEntity.a(compoundTag)
     
  6. Offline

    fireboyev

    It worked! Thanks for your help.
     
Thread Status:
Not open for further replies.

Share This Page