mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 20:22:28 +00:00
1.21.6 - New EventBus 7
A full rewrite and redesign of the library that offers much better performance, new features and fixes all previous design flaws See the migration guide here: https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91 Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
642 files changed
+7258
-6187
No files matched your search
@@ -7,13 +7,20 @@ package net.minecraftforge.items;
|
||||
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.TagValueInput;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.ProblemReporter;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable<CompoundTag> {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
protected NonNullList<ItemStack> stacks;
|
||||
|
||||
public ItemStackHandler() {
|
||||
@@ -139,14 +146,18 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT(HolderLookup.Provider lookup) {
|
||||
var tag = new CompoundTag();
|
||||
ContainerHelper.saveAllItems(tag, this.stacks, lookup);
|
||||
return tag;
|
||||
try (var problems = new ProblemReporter.ScopedCollector(LOGGER)) {
|
||||
var output = TagValueOutput.createWithContext(problems, lookup);
|
||||
ContainerHelper.saveAllItems(output, this.stacks);
|
||||
return output.buildResult();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(HolderLookup.Provider lookup, CompoundTag nbt) {
|
||||
ContainerHelper.loadAllItems(nbt, stacks, lookup);
|
||||
try (var problems = new ProblemReporter.ScopedCollector(LOGGER)) {
|
||||
ContainerHelper.loadAllItems(TagValueInput.create(problems, lookup, nbt), stacks);
|
||||
}
|
||||
onLoad();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user