Item Decoder
Utility class for decoding items from strings. If the string cannot be decoded, it will return the provided fallback item and log an error.
stringToItem
Section titled “stringToItem”Decodes an item from a string. The string should be in the format “namespace:path”. If the string cannot be decoded, it will return the provided fallback item and log an error.
import dev.matthiesen.matthiesen_core.common.utility.item.ItemDecoder;import net.minecraft.world.item.Item;import net.minecraft.world.item.Items;
public class Example { public static void main(String[] args) { String itemString = "minecraft:stone"; Item fallbackItem = Items.AIR; // Fallback item if decoding fails
Item decodedItem = ItemDecoder.stringToItem(itemString, fallbackItem);
System.out.println("Decoded Item: " + decodedItem); }}stringToBlock
Section titled “stringToBlock”Decodes a block from a string. The string should be in the format “namespace:path”. If the string cannot be decoded, it will return the provided fallback block and log an error.
import dev.matthiesen.matthiesen_core.common.utility.item.ItemDecoder;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.Blocks;
public class Example { public static void main(String[] args) { String blockString = "minecraft:stone"; Block fallbackBlock = Blocks.AIR; // Fallback block if decoding fails
Block decodedBlock = ItemDecoder.stringToBlock(blockString, fallbackBlock);
System.out.println("Decoded Block: " + decodedBlock); }}