Skip to content

Commit 8a06989

Browse files
committed
Fix game tests and use mojang helpers
1 parent b13b497 commit 8a06989

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/gameTest/java/mekanism/common/tests/util/TransporterTestUtils.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import mekanism.common.util.EnumUtils;
99
import mekanism.common.util.NBTUtils;
1010
import net.minecraft.core.Direction;
11+
import net.minecraft.core.HolderLookup;
12+
import net.minecraft.core.NonNullList;
1113
import net.minecraft.nbt.CompoundTag;
12-
import net.minecraft.nbt.ListTag;
14+
import net.minecraft.world.ContainerHelper;
1315
import net.minecraft.world.item.ItemStack;
1416
import net.minecraft.world.level.ItemLike;
1517
import 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

Comments
 (0)