mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Allow accessing Registry context from TagValueOutput
This commit is contained in:
3 files changed
+38
-1
No files matched your search
@@ -43,7 +43,7 @@
|
||||
}
|
||||
|
||||
protected void saveAdditional(ValueOutput p_407573_) {
|
||||
+ if (getCapabilities() != null && this.level != null) p_407573_.storeNullable("ForgeCaps", CompoundTag.CODEC, serializeCaps(this.level.registryAccess()));
|
||||
+ if (getCapabilities() != null) p_407573_.storeNullable("ForgeCaps", CompoundTag.CODEC, serializeCaps(p_407573_));
|
||||
}
|
||||
|
||||
public final CompoundTag saveWithFullMetadata(HolderLookup.Provider p_331193_) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
--- a/net/minecraft/world/level/storage/TagValueOutput.java
|
||||
+++ b/net/minecraft/world/level/storage/TagValueOutput.java
|
||||
@@ -17,15 +_,21 @@
|
||||
private final ProblemReporter problemReporter;
|
||||
private final DynamicOps<Tag> ops;
|
||||
private final CompoundTag output;
|
||||
+ public final [email protected] Provider lookup;
|
||||
|
||||
TagValueOutput(ProblemReporter p_407091_, DynamicOps<Tag> p_407083_, CompoundTag p_409593_) {
|
||||
+ this(p_407091_, p_407083_, p_409593_, null);
|
||||
+ }
|
||||
+
|
||||
+ TagValueOutput(ProblemReporter p_407091_, DynamicOps<Tag> p_407083_, CompoundTag p_409593_, [email protected] Provider lookup) {
|
||||
this.problemReporter = p_407091_;
|
||||
this.ops = p_407083_;
|
||||
this.output = p_409593_;
|
||||
+ this.lookup = lookup;
|
||||
}
|
||||
|
||||
public static TagValueOutput createWithContext(ProblemReporter p_409887_, HolderLookup.Provider p_409738_) {
|
||||
- return new TagValueOutput(p_409887_, p_409738_.createSerializationContext(NbtOps.INSTANCE), new CompoundTag());
|
||||
+ return new TagValueOutput(p_409887_, p_409738_.createSerializationContext(NbtOps.INSTANCE), new CompoundTag(), p_409738_);
|
||||
}
|
||||
|
||||
public static TagValueOutput createWithoutContext(ProblemReporter p_405875_) {
|
||||
@@ -13,6 +13,8 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.storage.TagValueOutput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
@@ -176,6 +178,16 @@ public abstract class CapabilityProvider<B extends ICapabilityProviderImpl<B>> i
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
|
||||
protected final @Nullable CompoundTag serializeCaps(ValueOutput output) {
|
||||
if (isLazy && !initialized)
|
||||
return lazyData;
|
||||
var disp = getCapabilities();
|
||||
if (disp == null || !(output instanceof TagValueOutput tagOutput) || tagOutput.lookup == null)
|
||||
return null;
|
||||
return disp.serializeNBT(tagOutput.lookup);
|
||||
}
|
||||
|
||||
protected final @Nullable CompoundTag serializeCaps(HolderLookup.Provider registryAccess) {
|
||||
if (isLazy && !initialized)
|
||||
return lazyData;
|
||||
|
||||
Reference in new issue
Block a user