Package net.minecraft.nbt
Class NbtHelper
java.lang.Object
net.minecraft.nbt.NbtHelper
Helper methods for handling NBT.
- Mappings:
Namespace Name named net/minecraft/nbt/NbtHelperintermediary net/minecraft/class_2512official up
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.mojang.serialization.Codec<RegistryKey<Block>> private static final Comparator<NbtList> private static final charprivate static final Splitterprivate static final Stringprivate static final Splitterstatic final Stringprivate static final Comparator<NbtList> private static final intprivate static final intprivate static final charprivate static final Loggerprivate static final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilderappendFormattedString(StringBuilder stringBuilder, NbtElement nbt, int depth, boolean withArrayContents) private static StringBuilderappendIndent(int depth, StringBuilder stringBuilder) static NbtCompoundfromBlockState(BlockState state) Returns the serialized block state.static NbtCompoundfromFluidState(FluidState state) Returns the serialized fluid state.(package private) static NbtCompoundfromNbtProviderFormat(NbtCompound compound) (package private) static NbtCompoundstatic NbtCompoundfromNbtProviderString(String string) Returns thestringparsed as an NBT provider-formatted NBT compound.static intgetDataVersion(com.mojang.serialization.Dynamic<?> dynamic, int fallback) static intgetDataVersion(NbtCompound nbt, int fallback) static booleanmatches(@Nullable NbtElement standard, @Nullable NbtElement subject, boolean ignoreListOrder) Returns whetherstandardis a subset ofsubject.private static <T extends Comparable<T>>
StringnameValue(Property<T> property, Comparable<?> value) static NbtCompoundstatic NbtCompoundputDataVersion(NbtCompound nbt, int dataVersion) static BlockStatetoBlockState(RegistryEntryLookup<Block> blockLookup, NbtCompound nbt) Returns the block state from thenbt.static StringReturns the human-readable, non-deserializable representation ofnbt.static StringtoFormattedString(NbtElement nbt, boolean withArrayContents) Returns the human-readable, non-deserializable representation ofnbt.(package private) static NbtCompoundtoNbtProviderFormat(NbtCompound compound) (package private) static StringtoNbtProviderFormattedPalette(NbtCompound compound) static StringtoNbtProviderString(NbtCompound compound) Returns the string representation ofcompoundas used by the NBT provider in the data generator.static TexttoPrettyPrintedText(NbtElement element) Returns the pretty-printed text representation ofelement.private static <S extends State<?,S>, T extends Comparable<T>>
SwithProperty(S state, Property<T> property, String key, NbtCompound properties, NbtCompound root)
-
Field Details
-
BLOCK_POS_COMPARATOR
- Mappings:
Namespace Name Mixin selector named BLOCK_POS_COMPARATORLnet/minecraft/nbt/NbtHelper;BLOCK_POS_COMPARATOR:Ljava/util/Comparator;intermediary field_27816Lnet/minecraft/class_2512;field_27816:Ljava/util/Comparator;official bLup;b:Ljava/util/Comparator;
-
ENTITY_POS_COMPARATOR
- Mappings:
Namespace Name Mixin selector named ENTITY_POS_COMPARATORLnet/minecraft/nbt/NbtHelper;ENTITY_POS_COMPARATOR:Ljava/util/Comparator;intermediary field_27817Lnet/minecraft/class_2512;field_27817:Ljava/util/Comparator;official cLup;c:Ljava/util/Comparator;
-
BLOCK_KEY_CODEC
- Mappings:
Namespace Name Mixin selector named BLOCK_KEY_CODECLnet/minecraft/nbt/NbtHelper;BLOCK_KEY_CODEC:Lcom/mojang/serialization/Codec;intermediary field_57978Lnet/minecraft/class_2512;field_57978:Lcom/mojang/serialization/Codec;official dLup;d:Lcom/mojang/serialization/Codec;
-
DATA_KEY
- See Also:
- Mappings:
Namespace Name Mixin selector named DATA_KEYLnet/minecraft/nbt/NbtHelper;DATA_KEY:Ljava/lang/String;intermediary field_33224Lnet/minecraft/class_2512;field_33224:Ljava/lang/String;official aLup;a:Ljava/lang/String;
-
LEFT_CURLY_BRACKET
private static final char LEFT_CURLY_BRACKET- See Also:
- Mappings:
Namespace Name Mixin selector named LEFT_CURLY_BRACKETLnet/minecraft/nbt/NbtHelper;LEFT_CURLY_BRACKET:Cintermediary field_33225Lnet/minecraft/class_2512;field_33225:Cofficial eLup;e:C
-
RIGHT_CURLY_BRACKET
private static final char RIGHT_CURLY_BRACKET- See Also:
- Mappings:
Namespace Name Mixin selector named RIGHT_CURLY_BRACKETLnet/minecraft/nbt/NbtHelper;RIGHT_CURLY_BRACKET:Cintermediary field_33226Lnet/minecraft/class_2512;field_33226:Cofficial fLup;f:C
-
COMMA
- See Also:
- Mappings:
Namespace Name Mixin selector named COMMALnet/minecraft/nbt/NbtHelper;COMMA:Ljava/lang/String;intermediary field_33227Lnet/minecraft/class_2512;field_33227:Ljava/lang/String;official gLup;g:Ljava/lang/String;
-
COLON
private static final char COLON- See Also:
- Mappings:
Namespace Name Mixin selector named COLONLnet/minecraft/nbt/NbtHelper;COLON:Cintermediary field_33228Lnet/minecraft/class_2512;field_33228:Cofficial hLup;h:C
-
COMMA_SPLITTER
- Mappings:
Namespace Name Mixin selector named COMMA_SPLITTERLnet/minecraft/nbt/NbtHelper;COMMA_SPLITTER:Lcom/google/common/base/Splitter;intermediary field_27818Lnet/minecraft/class_2512;field_27818:Lcom/google/common/base/Splitter;official iLup;i:Lcom/google/common/base/Splitter;
-
COLON_SPLITTER
- Mappings:
Namespace Name Mixin selector named COLON_SPLITTERLnet/minecraft/nbt/NbtHelper;COLON_SPLITTER:Lcom/google/common/base/Splitter;intermediary field_27819Lnet/minecraft/class_2512;field_27819:Lcom/google/common/base/Splitter;official jLup;j:Lcom/google/common/base/Splitter;
-
LOGGER
- Mappings:
Namespace Name Mixin selector named LOGGERLnet/minecraft/nbt/NbtHelper;LOGGER:Lorg/slf4j/Logger;intermediary field_11582Lnet/minecraft/class_2512;field_11582:Lorg/slf4j/Logger;official kLup;k:Lorg/slf4j/Logger;
-
field_33229
private static final int field_33229- See Also:
- Mappings:
Namespace Name Mixin selector named field_33229Lnet/minecraft/nbt/NbtHelper;field_33229:Iintermediary field_33229Lnet/minecraft/class_2512;field_33229:Iofficial lLup;l:I
-
field_33230
private static final int field_33230- See Also:
- Mappings:
Namespace Name Mixin selector named field_33230Lnet/minecraft/nbt/NbtHelper;field_33230:Iintermediary field_33230Lnet/minecraft/class_2512;field_33230:Iofficial mLup;m:I
-
-
Constructor Details
-
NbtHelper
private NbtHelper()
-
-
Method Details
-
matches
public static boolean matches(@Nullable @Nullable NbtElement standard, @Nullable @Nullable NbtElement subject, boolean ignoreListOrder) Returns whetherstandardis a subset ofsubject.Elements are matched based on the following order:
- Passing the same reference to both parameters will return
true. - If
standardisnull, returntrue. - If
subjectisnull, returnfalse. - If the types of
standardandsubjectare different, returnfalse. - If
standardisNbtCompound, returntrueif all keys in thestandardexist insubjectand the values match (comparing recursively.) - If
standardisNbtListandignoreListOrderistrue, returntrueif both lists are empty, or if there exists a "matching" value insubjectfor all values ofstandard(that is, ifstandardis a subset ofsubject, ignoring duplicates.), otherwisefalse. This means that the comparison ignores the ordering of the lists. - Otherwise, return
standard.equals(subject).
- Parameters:
standard- the standard (also called as "template" or "schema") elementsubject- the element to testignoreListOrder- whether to ignore ordering forNbtList- Returns:
- whether
standardis a subset ofsubject - Mappings:
Namespace Name Mixin selector named matchesLnet/minecraft/nbt/NbtHelper;matches(Lnet/minecraft/nbt/NbtElement;Lnet/minecraft/nbt/NbtElement;Z)Zintermediary method_10687Lnet/minecraft/class_2512;method_10687(Lnet/minecraft/class_2520;Lnet/minecraft/class_2520;Z)Zofficial aLup;a(Lva;Lva;Z)Z
- Passing the same reference to both parameters will return
-
toBlockState
Returns the block state from thenbt.This returns the default state for
Blocks.AIRif the block name is not present.- Returns:
- the block state from the
nbt - See Also:
- Mappings:
Namespace Name Mixin selector named toBlockStateLnet/minecraft/nbt/NbtHelper;toBlockState(Lnet/minecraft/registry/RegistryEntryLookup;Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/block/BlockState;intermediary method_10681Lnet/minecraft/class_2512;method_10681(Lnet/minecraft/class_7871;Lnet/minecraft/class_2487;)Lnet/minecraft/class_2680;official aLup;a(Ljh;Lua;)Lebq;
-
withProperty
private static <S extends State<?,S>, S withPropertyT extends Comparable<T>> (S state, Property<T> property, String key, NbtCompound properties, NbtCompound root) - Mappings:
Namespace Name Mixin selector named withPropertyLnet/minecraft/nbt/NbtHelper;withProperty(Lnet/minecraft/state/State;Lnet/minecraft/state/property/Property;Ljava/lang/String;Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/state/State;intermediary method_10682Lnet/minecraft/class_2512;method_10682(Lnet/minecraft/class_2688;Lnet/minecraft/class_2769;Ljava/lang/String;Lnet/minecraft/class_2487;Lnet/minecraft/class_2487;)Lnet/minecraft/class_2688;official aLup;a(Lebs;Lect;Ljava/lang/String;Lua;Lua;)Lebs;
-
fromBlockState
Returns the serialized block state.- Returns:
- the serialized block state
- See Also:
- Mappings:
Namespace Name Mixin selector named fromBlockStateLnet/minecraft/nbt/NbtHelper;fromBlockState(Lnet/minecraft/block/BlockState;)Lnet/minecraft/nbt/NbtCompound;intermediary method_10686Lnet/minecraft/class_2512;method_10686(Lnet/minecraft/class_2680;)Lnet/minecraft/class_2487;official aLup;a(Lebq;)Lua;
-
fromFluidState
Returns the serialized fluid state.- Returns:
- the serialized fluid state
- Mappings:
Namespace Name Mixin selector named fromFluidStateLnet/minecraft/nbt/NbtHelper;fromFluidState(Lnet/minecraft/fluid/FluidState;)Lnet/minecraft/nbt/NbtCompound;intermediary method_36115Lnet/minecraft/class_2512;method_36115(Lnet/minecraft/class_3610;)Lnet/minecraft/class_2487;official aLup;a(Leya;)Lua;
-
nameValue
private static <T extends Comparable<T>> String nameValue(Property<T> property, Comparable<?> value) - Mappings:
Namespace Name Mixin selector named nameValueLnet/minecraft/nbt/NbtHelper;nameValue(Lnet/minecraft/state/property/Property;Ljava/lang/Comparable;)Ljava/lang/String;intermediary method_10685Lnet/minecraft/class_2512;method_10685(Lnet/minecraft/class_2769;Ljava/lang/Comparable;)Ljava/lang/String;official aLup;a(Lect;Ljava/lang/Comparable;)Ljava/lang/String;
-
toFormattedString
Returns the human-readable, non-deserializable representation ofnbt.This does not include contents of
NbtByteArray,NbtIntArray, andNbtLongArray. To include them, calltoFormattedString(NbtElement, boolean)withwithArrayContentsparameter set to true.- Returns:
- the human-readable, non-deserializable representation of
nbt - See Also:
- Mappings:
Namespace Name Mixin selector named toFormattedStringLnet/minecraft/nbt/NbtHelper;toFormattedString(Lnet/minecraft/nbt/NbtElement;)Ljava/lang/String;intermediary method_36118Lnet/minecraft/class_2512;method_36118(Lnet/minecraft/class_2520;)Ljava/lang/String;official aLup;a(Lva;)Ljava/lang/String;
-
toFormattedString
Returns the human-readable, non-deserializable representation ofnbt.- Parameters:
withArrayContents- whether to include contents ofNbtByteArray,NbtIntArray, andNbtLongArray- Returns:
- the human-readable, non-deserializable representation of
nbt - Mappings:
Namespace Name Mixin selector named toFormattedStringLnet/minecraft/nbt/NbtHelper;toFormattedString(Lnet/minecraft/nbt/NbtElement;Z)Ljava/lang/String;intermediary method_36117Lnet/minecraft/class_2512;method_36117(Lnet/minecraft/class_2520;Z)Ljava/lang/String;official aLup;a(Lva;Z)Ljava/lang/String;
-
appendFormattedString
public static StringBuilder appendFormattedString(StringBuilder stringBuilder, NbtElement nbt, int depth, boolean withArrayContents) - Mappings:
Namespace Name Mixin selector named appendFormattedStringLnet/minecraft/nbt/NbtHelper;appendFormattedString(Ljava/lang/StringBuilder;Lnet/minecraft/nbt/NbtElement;IZ)Ljava/lang/StringBuilder;intermediary method_36116Lnet/minecraft/class_2512;method_36116(Ljava/lang/StringBuilder;Lnet/minecraft/class_2520;IZ)Ljava/lang/StringBuilder;official aLup;a(Ljava/lang/StringBuilder;Lva;IZ)Ljava/lang/StringBuilder;
-
appendIndent
- Mappings:
Namespace Name Mixin selector named appendIndentLnet/minecraft/nbt/NbtHelper;appendIndent(ILjava/lang/StringBuilder;)Ljava/lang/StringBuilder;intermediary method_36114Lnet/minecraft/class_2512;method_36114(ILjava/lang/StringBuilder;)Ljava/lang/StringBuilder;official aLup;a(ILjava/lang/StringBuilder;)Ljava/lang/StringBuilder;
-
toPrettyPrintedText
Returns the pretty-printed text representation ofelement.- Returns:
- the pretty-printed text representation of
element - See Also:
- Mappings:
Namespace Name Mixin selector named toPrettyPrintedTextLnet/minecraft/nbt/NbtHelper;toPrettyPrintedText(Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/text/Text;intermediary method_32270Lnet/minecraft/class_2512;method_32270(Lnet/minecraft/class_2520;)Lnet/minecraft/class_2561;official bLup;b(Lva;)Lxg;
-
toNbtProviderString
Returns the string representation ofcompoundas used by the NBT provider in the data generator.The passed
compoundwill be sorted and modified in-place to make it more human-readable e.g. by convertingNbtCompoundin thepalettesNbtListto its short string representation. Therefore the returned value is not an accurate representation of the original NBT.- Returns:
- the string representation of
compoundas used by the NBT provider in the data generator - See Also:
- Mappings:
Namespace Name Mixin selector named toNbtProviderStringLnet/minecraft/nbt/NbtHelper;toNbtProviderString(Lnet/minecraft/nbt/NbtCompound;)Ljava/lang/String;intermediary method_32271Lnet/minecraft/class_2512;method_32271(Lnet/minecraft/class_2487;)Ljava/lang/String;official aLup;a(Lua;)Ljava/lang/String;
-
fromNbtProviderString
public static NbtCompound fromNbtProviderString(String string) throws com.mojang.brigadier.exceptions.CommandSyntaxException Returns thestringparsed as an NBT provider-formatted NBT compound.This method first parses the string as an NBT, then performs several conversions from human-readable
NbtCompounditems to the actual values used in-game.- Returns:
- the
stringparsed as an NBT provider-formatted NBT compound - Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- See Also:
- Mappings:
Namespace Name Mixin selector named fromNbtProviderStringLnet/minecraft/nbt/NbtHelper;fromNbtProviderString(Ljava/lang/String;)Lnet/minecraft/nbt/NbtCompound;intermediary method_32260Lnet/minecraft/class_2512;method_32260(Ljava/lang/String;)Lnet/minecraft/class_2487;official aLup;a(Ljava/lang/String;)Lua;
-
toNbtProviderFormat
- Mappings:
Namespace Name Mixin selector named toNbtProviderFormatLnet/minecraft/nbt/NbtHelper;toNbtProviderFormat(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/nbt/NbtCompound;intermediary method_32273Lnet/minecraft/class_2512;method_32273(Lnet/minecraft/class_2487;)Lnet/minecraft/class_2487;official bLup;b(Lua;)Lua;
-
fromNbtProviderFormat
- Mappings:
Namespace Name Mixin selector named fromNbtProviderFormatLnet/minecraft/nbt/NbtHelper;fromNbtProviderFormat(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/nbt/NbtCompound;intermediary method_32275Lnet/minecraft/class_2512;method_32275(Lnet/minecraft/class_2487;)Lnet/minecraft/class_2487;official cLup;c(Lua;)Lua;
-
toNbtProviderFormattedPalette
- Mappings:
Namespace Name Mixin selector named toNbtProviderFormattedPaletteLnet/minecraft/nbt/NbtHelper;toNbtProviderFormattedPalette(Lnet/minecraft/nbt/NbtCompound;)Ljava/lang/String;intermediary method_32277Lnet/minecraft/class_2512;method_32277(Lnet/minecraft/class_2487;)Ljava/lang/String;official dLup;d(Lua;)Ljava/lang/String;
-
fromNbtProviderFormattedPalette
- Mappings:
Namespace Name Mixin selector named fromNbtProviderFormattedPaletteLnet/minecraft/nbt/NbtHelper;fromNbtProviderFormattedPalette(Ljava/lang/String;)Lnet/minecraft/nbt/NbtCompound;intermediary method_32267Lnet/minecraft/class_2512;method_32267(Ljava/lang/String;)Lnet/minecraft/class_2487;official bLup;b(Ljava/lang/String;)Lua;
-
putDataVersion
- Mappings:
Namespace Name Mixin selector named putDataVersionLnet/minecraft/nbt/NbtHelper;putDataVersion(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/nbt/NbtCompound;intermediary method_48310Lnet/minecraft/class_2512;method_48310(Lnet/minecraft/class_2487;)Lnet/minecraft/class_2487;official eLup;e(Lua;)Lua;
-
putDataVersion
- Mappings:
Namespace Name Mixin selector named putDataVersionLnet/minecraft/nbt/NbtHelper;putDataVersion(Lnet/minecraft/nbt/NbtCompound;I)Lnet/minecraft/nbt/NbtCompound;intermediary method_48308Lnet/minecraft/class_2512;method_48308(Lnet/minecraft/class_2487;I)Lnet/minecraft/class_2487;official aLup;a(Lua;I)Lua;
-
getDataVersion
- Mappings:
Namespace Name Mixin selector named getDataVersionLnet/minecraft/nbt/NbtHelper;getDataVersion(Lnet/minecraft/nbt/NbtCompound;I)Iintermediary method_48309Lnet/minecraft/class_2512;method_48309(Lnet/minecraft/class_2487;I)Iofficial bLup;b(Lua;I)I
-
getDataVersion
public static int getDataVersion(com.mojang.serialization.Dynamic<?> dynamic, int fallback) - Mappings:
Namespace Name Mixin selector named getDataVersionLnet/minecraft/nbt/NbtHelper;getDataVersion(Lcom/mojang/serialization/Dynamic;I)Iintermediary method_68084Lnet/minecraft/class_2512;method_68084(Lcom/mojang/serialization/Dynamic;I)Iofficial aLup;a(Lcom/mojang/serialization/Dynamic;I)I
-