How to get and change NBT of an item (simple pls)

i have a mod which adds realistic 3d weapons but this mod has some problems…
U can add a weapon some modifications like Foregrip…
The problem is if u put an weapon thats not had any magazines before (no Nbt tag for magazines) server crashes…

i want to get weapons Nbt data and check if it has some or not…
if there is no Nbt data event will be canceled…

Most of Sponge’s classes can be cast to the native net.minecraft classes.

Generally we recommend making a compat mod if you need to do anything complex with a 3rd party mod. This is a Forge mod that works at the MC level, providing an interface for SpongeAPI plugins to use without having to reach into MC internals.

Otherwise, you can also import the minecraft internals (eg using ForgeGradle) and then access them in your plugin.

For an example, see @gabizou’s interface for Thaumcraft:

Thank you :slight_smile: but im just newbie at libraries like Sponge
I dont wanna get myself messed up while working in Keys and stuff
is there a way that i can get all item data as a string like
{EntityTag:{id:“AK47”}} ??

/entitydata in minecraft gives some info like this…

Yes, myEntity.toContainer() will give you a DataContainer representation of the entity. Within that, the UnsafeData tag will be the raw NBT.

DataContainer should be functionally equivalent to NBT, DataQuery is just a way to easily descend the tree. Eg,

myEntity.toContainer().getString(DataQuery.of("UnsafeData", "EntityTag, "id"))