88import mekanism .common .util .EnumUtils ;
99import mekanism .common .util .NBTUtils ;
1010import net .minecraft .core .Direction ;
11+ import net .minecraft .core .HolderLookup ;
12+ import net .minecraft .core .NonNullList ;
1113import net .minecraft .nbt .CompoundTag ;
12- import net .minecraft .nbt . ListTag ;
14+ import net .minecraft .world . ContainerHelper ;
1315import net .minecraft .world .item .ItemStack ;
1416import net .minecraft .world .level .ItemLike ;
1517import net .neoforged .neoforge .server .ServerLifecycleHooks ;
@@ -31,31 +33,15 @@ public static CompoundTag containing(ItemLike itemLike, int amount) {
3133 }
3234
3335 public static CompoundTag containing (ItemStack ... stacks ) {
34- CompoundTag tag = new CompoundTag ();
35- ListTag items = new ListTag ();
36- for (int i = 0 ; i < stacks .length ; i ++) {
37- CompoundTag item = saveItem (stacks [i ]);
38- item .putByte (SerializationConstants .SLOT , (byte ) i );
39- items .add (item );
40- }
41- tag .put (SerializationConstants .ITEMS , items );
42- return tag ;
36+ return ContainerHelper .saveAllItems (new CompoundTag (), NonNullList .of (ItemStack .EMPTY , stacks ), registryAccess ());
4337 }
4438
4539 public static CompoundTag containing (ItemStack stack , int slots ) {
46- CompoundTag tag = new CompoundTag ();
47- ListTag items = new ListTag ();
48- for (int i = 0 ; i < slots ; i ++) {
49- CompoundTag item = saveItem (stack );
50- item .putByte (SerializationConstants .SLOT , (byte ) i );
51- items .add (item );
52- }
53- tag .put (SerializationConstants .ITEMS , items );
54- return tag ;
40+ return ContainerHelper .saveAllItems (new CompoundTag (), NonNullList .withSize (slots , stack ), registryAccess ());
5541 }
5642
57- private static CompoundTag saveItem ( ItemStack stack ) {
58- return ( CompoundTag ) stack . save ( ServerLifecycleHooks .getCurrentServer ().registryAccess (), new CompoundTag () );
43+ private static HolderLookup . Provider registryAccess ( ) {
44+ return ServerLifecycleHooks .getCurrentServer ().registryAccess ();
5945 }
6046
6147 @ Nullable
0 commit comments