Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

there is no specal Item NBT, you can use Entity#save to save your Entity into the given CompoundTag

Note the Tag you use to save the Entity should contains your Mod Id to avoid conflicts between other mods

  • Author

ok so i use this to save the entity:

ListTag listtag = compoundtag.getList("thingsandstuff.entities", 0);
        listtag.add(entity.saveWithoutId(compoundtag));
        compoundtag.put("thingsandstuff.entities", listtag);
        stack.setTag(compoundtag);
        entity.remove(Entity.RemovalReason.DISCARDED);

but how do i get the entity from the tag?

Edited by KaboomRoads

  • Author

this is how i save the entities now:

CompoundTag compoundtag = stack.getOrCreateTag();
        if (!compoundtag.contains("thingsandstuff.entities")) {
            compoundtag.put("thingsandstuff.entities", new ListTag());
        }
        ListTag listtag = compoundtag.getList("thingsandstuff.entities", 10);
        listtag.add(entity.saveWithoutId(compoundtag));
        compoundtag.put("thingsandstuff.entities", listtag);
        stack.setTag(compoundtag);
        entity.remove(Entity.RemovalReason.DISCARDED);

this is how i spawn them:

 CompoundTag compoundtag = stack.getOrCreateTag();
        if (!compoundtag.contains("thingsandstuff.entities"))
            return;
        ListTag listtag = compoundtag.getList("thingsandstuff.entities", 10);
        Stream<Entity> entities = EntityType.loadEntitiesRecursive(listtag, level);
        entities.forEach((e) -> e.setPos(pos));
        compoundtag.put("thingsandstuff.entities", new ListTag());
        stack.setTag(compoundtag);

it still doesnt seem to work.

  • Author

so i just changed some things like you said, and this is what i have right now:

public static void saveEntity(ItemStack stack, Entity entity) {
        if (stack == null)
            return;
        CompoundTag compoundtag = stack.getOrCreateTag();
        if (!compoundtag.contains("thingsandstuff.entities")) {
            compoundtag.put("thingsandstuff.entities", new ListTag());
        }
        ListTag listtag = compoundtag.getList("thingsandstuff.entities", 10);
        listtag.add(entity.saveWithoutId(compoundtag));
        compoundtag.put("thingsandstuff.entities", listtag);
        stack.setTag(compoundtag);
        entity.remove(Entity.RemovalReason.DISCARDED);
    }

    public static void releaseEntities(ItemStack stack, Vec3 pos, Level level) {
        if (stack == null)
            return;
        CompoundTag compoundtag = stack.getOrCreateTag();
        if (!compoundtag.contains("thingsandstuff.entities"))
            return;
        ListTag listtag = compoundtag.getList("thingsandstuff.entities", Tag.TAG_COMPOUND);
        Stream<Entity> entities = EntityType.loadEntitiesRecursive(listtag, level);
        entities.forEach((e) -> {
            e.teleportTo(pos.x, pos.y, pos.z);
            level.addFreshEntity(e);
        });
        compoundtag.put("thingsandstuff.entities", new ListTag());
        stack.setTag(compoundtag);
    }

it still doesnt spawn the entities though.

i dont really understand what you meant by it not compiling, it works fine for me.

  • Author

i found what seems to be the problem, but cant find the thing causing it. its this check right here that stops the code after from running;

if (!compoundtag.contains("thingsandstuff.entities"))
            return;

ย so the compound tag doesnt contain "thingsandstuff.entities"ย event though im setting the tag in the method saveEntity.

Is your saveEntity function called?

If you enable the debug data in game, can you see the tag on the itemstack (F3 + H I think allows you to view NBT by holding ctrl maybe? If not, there is always the data command)

Edited by Alpvax

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.