mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
Remove Non-HolderLookup methods from INBTSerializeable and mark it as deprecated in favor of using Vanilla's new Component system. Closes #9998
This commit is contained in:
11 files changed
+97
-214
No files matched your search
@@ -13,14 +13,10 @@ import net.minecraft.nbt.Tag;
|
||||
* code base that can be serialized to and from a NBT tag.
|
||||
*
|
||||
* @deprecated // Mojang has switched most things to Codecs and registry context, probably worth deleting this.
|
||||
*
|
||||
* Most cases this is used for Capabilities, and should use Components attached to the object that the cap is attached to.
|
||||
*/
|
||||
public interface INBTSerializable<T extends Tag> {
|
||||
default T serializeNBT() { return null; }
|
||||
default T serializeNBT(HolderLookup.Provider registryAccess) {
|
||||
return serializeNBT();
|
||||
}
|
||||
default void deserializeNBT(T nbt) { }
|
||||
default void deserializeNBT(HolderLookup.Provider registryAccess, T nbt) {
|
||||
deserializeNBT(nbt);
|
||||
}
|
||||
T serializeNBT(HolderLookup.Provider registryAccess);
|
||||
void deserializeNBT(HolderLookup.Provider registryAccess, T nbt);
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderLookup.Provider;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.minecraft.world.level.storage.DimensionDataStorage;
|
||||
@@ -23,18 +22,10 @@ public class LevelCapabilityData extends SavedData {
|
||||
this.serializable = serializable;
|
||||
}
|
||||
|
||||
public void read(CompoundTag nbt) {
|
||||
this.capNBT = nbt;
|
||||
if (serializable != null) {
|
||||
serializable.deserializeNBT(this.capNBT);
|
||||
this.capNBT = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag nbt, HolderLookup.Provider provider) {
|
||||
if (serializable != null)
|
||||
nbt = serializable.serializeNBT();
|
||||
nbt = serializable.serializeNBT(provider);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@@ -43,27 +34,18 @@ public class LevelCapabilityData extends SavedData {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCapabilities(INBTSerializable<CompoundTag> capabilities) {
|
||||
this.serializable = capabilities;
|
||||
if (this.capNBT != null && serializable != null) {
|
||||
serializable.deserializeNBT(this.capNBT);
|
||||
this.capNBT = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static LevelCapabilityData compute(DimensionDataStorage data, @Nullable INBTSerializable<CompoundTag> caps) {
|
||||
var factory = new Factory<>(
|
||||
() -> new LevelCapabilityData(caps),
|
||||
(tag, lookup) -> {
|
||||
var ret = new LevelCapabilityData(caps);
|
||||
ret.read(tag);
|
||||
if (caps != null)
|
||||
caps.deserializeNBT(lookup, tag);
|
||||
return ret;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
var ret = data.computeIfAbsent(factory, ID);
|
||||
ret.setCapabilities(caps);
|
||||
return ret;
|
||||
return data.computeIfAbsent(factory, ID);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user