June 2, 20223 yr 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
June 2, 20223 yr 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 June 2, 20223 yr by KaboomRoads
June 2, 20223 yr 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.
June 2, 20223 yr 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.
June 2, 20223 yr 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.
June 7, 20223 yr 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 June 7, 20223 yr 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.