Buckets:
| { | |
| "path": "Minecraft/mc-Data/ExampleComponents.java", | |
| "original_extension": "java", | |
| "content": "package com.example.examplemod;\n\nimport com.mojang.serialization.Codec;\nimport com.mojang.serialization.codecs.RecordCodecBuilder;\nimport net.minecraft.component.ComponentType;\nimport net.minecraft.component.type.NbtComponent;\nimport net.minecraft.item.ItemStack;\nimport net.minecraft.network.codec.PacketCodecs;\nimport net.minecraft.registry.Registries;\nimport net.minecraft.registry.Registry;\nimport net.minecraft.text.Text;\nimport net.minecraft.util.Identifier;\n\n/**\n * The 1.20.5+ DataComponent system replaced NBT-based item data and is the\n * standard way to attach custom data to ItemStacks in 1.21.7 - 1.21.11.\n *\n * Example: a \"Charge Level\" component for a custom tool that tracks\n * remaining charges and shows it in the tooltip.\n */\npublic final class ExampleComponents {\n\n private ExampleComponents() {}\n\n // A simple integer component: how many \"charges\" remain on the item.\n public static final ComponentType<Integer> CHARGE_LEVEL = Registry.register(\n Registries.DATA_COMPONENT_TYPE,\n Identifier.of(ExampleMod.MOD_ID, \"charge_level\"),\n ComponentType.<Integer>builder()\n .codec(Codec.INT)\n .packetCodec(PacketCodecs.VAR_INT)\n .build()\n );\n\n /** Set initial charge on item creation. */\n public static ItemStack withCharges(ItemStack stack, int charges) {\n stack.set(CHARGE_LEVEL, charges);\n return stack;\n }\n\n /** Consume one charge; returns true if there was a charge to consume. */\n public static boolean consumeCharge(ItemStack stack) {\n Integer current = stack.get(CHARGE_LEVEL);\n if (current == null || current <= 0) return false;\n stack.set(CHARGE_LEVEL, current - 1);\n return true;\n }\n\n /** Build a tooltip line showing remaining charges (call from an Item subclass override). */\n public static Text getChargeTooltip(ItemStack stack) {\n Integer current = stack.getOrDefault(CHARGE_LEVEL, 0);\n return Text.literal(\"Charges: \" + current).formatted(net.minecraft.util.Formatting.AQUA);\n }\n}\n" | |
| } |
Xet Storage Details
- Size:
- 2.26 kB
- Xet hash:
- 5a780465f94c2a91231e560030029b19e229a49d5e273ddfa55cf87b4775bd4f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.