How to set NBT to item?

I dont know, is it working or not, because I do not know what (or how) I need write in config to test it?(

When you get the item back, you should be able to use advanced tool tips to see the amount of nbt tags.

You can also chuck it on the ground and type /entitydata @e[type=item,c=1] {}

That’ll work, but that’s moderately annoying as well.

Oh, I am was using config wrongly, as always…
Thank you!

One more question, how I can add NBT to entity?

Entity#setRawData(DataView)

I tried it, but it is not working, like ItemStack::setRawData not working too,
(Only item = ItemStack.builder().fromContainer(container).build()).

I suspect you’re right.

https://github.com/SpongePowered/SpongeCommon/blob/bleeding/src/main/java/org/spongepowered/common/mixin/core/entity/MixinEntity.java#L893-L896

Well, you can use EntityUniverse(i.e. World)#createEntity(DataContainer) to create an entity from the result of toContainer.

I tried:

    private void createEntity() {
        World world = location.getExtent();
        location.getExtent().loadChunk(location.getChunkPosition(), true);
        Entity entity = world.createEntity(entity_type, location.getPosition());
        entity.setCreator(GWMCrates.PLUGIN_UUID);
        if (name.isPresent()) {
            entity.offer(Keys.DISPLAY_NAME, name.get());
            entity.offer(Keys.CUSTOM_NAME_VISIBLE, true);
        }
        entity.offer(Keys.AI_ENABLED, false);
        entity.offer(Keys.HAS_GRAVITY, false);
        DataContainer container = entity.toContainer();
        LinkedHashMap nbt_map = new LinkedHashMap(nbt);
        if (container.get(DataQuery.of("UnsafeData")).isPresent()) {
            Map unsafe_data_map = container.getMap(DataQuery.of("UnsafeData")).get();
            nbt_map.putAll(unsafe_data_map);
        }
        entity = world.createEntity(container).get(); //bad line
        world.spawnEntity(entity, GWMCrates.getInstance().getDefaultCause());
        this.entity = entity;
    }

But I got “No value present” exception (at “bad line”). Without this line - code works good (but without NBT ofcourse :frowning: )

Try deleting the UUID field, wherever it is, from the returned DataContainer. It could be erroring because it can’t create two entities with the same UUID.

How I can do it (delete UUID field from returned DataContainter)?

Print it so you can see where the field is, and then call DataContainer#remove(DataQuery)

Ohhh…
What from it I should remove?

Both UUIDLeast and UUIDMost from UnsafeData

OKay, really stupid question… But how I can remove them?
I tried this, but I think it not what I need…

container = container.remove(DataQuery.of("UnsafeData", "UUIDLeast")); container = container.remove(DataQuery.of("UnsafeData", "UUIDMost"));

Well, that should be it. If that doesn’t work, I’m stumped.

Hm, this is so sadly(