| 1 | package net.minecraft.world.item;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.function.Consumer;
|
| 5 | import net.minecraft.ChatFormatting;
|
| 6 | import net.minecraft.network.chat.CommonComponents;
|
| 7 | import net.minecraft.network.chat.Component;
|
| 8 | import net.minecraft.resources.Identifier;
|
| 9 | import net.minecraft.util.Util;
|
| 10 | import net.minecraft.world.item.component.TooltipDisplay;
|
| 11 |
|
| 12 | public class SmithingTemplateItem extends Item {
|
| 13 | private static final ChatFormatting TITLE_FORMAT = ChatFormatting.GRAY;
|
| 14 | private static final ChatFormatting DESCRIPTION_FORMAT = ChatFormatting.BLUE;
|
| 15 | private static final Component INGREDIENTS_TITLE = Component.translatable(
|
| 16 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.ingredients"))
|
| 17 | )
|
| 18 | .withStyle(TITLE_FORMAT);
|
| 19 | private static final Component APPLIES_TO_TITLE = Component.translatable(
|
| 20 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.applies_to"))
|
| 21 | )
|
| 22 | .withStyle(TITLE_FORMAT);
|
| 23 | private static final Component SMITHING_TEMPLATE_SUFFIX = Component.translatable(
|
| 24 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template"))
|
| 25 | )
|
| 26 | .withStyle(TITLE_FORMAT);
|
| 27 | private static final Component ARMOR_TRIM_APPLIES_TO = Component.translatable(
|
| 28 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.armor_trim.applies_to"))
|
| 29 | )
|
| 30 | .withStyle(DESCRIPTION_FORMAT);
|
| 31 | private static final Component ARMOR_TRIM_INGREDIENTS = Component.translatable(
|
| 32 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.armor_trim.ingredients"))
|
| 33 | )
|
| 34 | .withStyle(DESCRIPTION_FORMAT);
|
| 35 | private static final Component ARMOR_TRIM_BASE_SLOT_DESCRIPTION = Component.translatable(
|
| 36 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.armor_trim.base_slot_description"))
|
| 37 | );
|
| 38 | private static final Component ARMOR_TRIM_ADDITIONS_SLOT_DESCRIPTION = Component.translatable(
|
| 39 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.armor_trim.additions_slot_description"))
|
| 40 | );
|
| 41 | private static final Component NETHERITE_UPGRADE_APPLIES_TO = Component.translatable(
|
| 42 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.netherite_upgrade.applies_to"))
|
| 43 | )
|
| 44 | .withStyle(DESCRIPTION_FORMAT);
|
| 45 | private static final Component NETHERITE_UPGRADE_INGREDIENTS = Component.translatable(
|
| 46 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.netherite_upgrade.ingredients"))
|
| 47 | )
|
| 48 | .withStyle(DESCRIPTION_FORMAT);
|
| 49 | private static final Component NETHERITE_UPGRADE_BASE_SLOT_DESCRIPTION = Component.translatable(
|
| 50 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.netherite_upgrade.base_slot_description"))
|
| 51 | );
|
| 52 | private static final Component NETHERITE_UPGRADE_ADDITIONS_SLOT_DESCRIPTION = Component.translatable(
|
| 53 | Util.makeDescriptionId("item", Identifier.withDefaultNamespace("smithing_template.netherite_upgrade.additions_slot_description"))
|
| 54 | );
|
| 55 | private static final Identifier EMPTY_SLOT_HELMET = Identifier.withDefaultNamespace("container/slot/helmet");
|
| 56 | private static final Identifier EMPTY_SLOT_CHESTPLATE = Identifier.withDefaultNamespace("container/slot/chestplate");
|
| 57 | private static final Identifier EMPTY_SLOT_LEGGINGS = Identifier.withDefaultNamespace("container/slot/leggings");
|
| 58 | private static final Identifier EMPTY_SLOT_BOOTS = Identifier.withDefaultNamespace("container/slot/boots");
|
| 59 | private static final Identifier EMPTY_SLOT_HOE = Identifier.withDefaultNamespace("container/slot/hoe");
|
| 60 | private static final Identifier EMPTY_SLOT_AXE = Identifier.withDefaultNamespace("container/slot/axe");
|
| 61 | private static final Identifier EMPTY_SLOT_SWORD = Identifier.withDefaultNamespace("container/slot/sword");
|
| 62 | private static final Identifier EMPTY_SLOT_SHOVEL = Identifier.withDefaultNamespace("container/slot/shovel");
|
| 63 | private static final Identifier EMPTY_SLOT_SPEAR = Identifier.withDefaultNamespace("container/slot/spear");
|
| 64 | private static final Identifier EMPTY_SLOT_PICKAXE = Identifier.withDefaultNamespace("container/slot/pickaxe");
|
| 65 | private static final Identifier EMPTY_SLOT_INGOT = Identifier.withDefaultNamespace("container/slot/ingot");
|
| 66 | private static final Identifier EMPTY_SLOT_REDSTONE_DUST = Identifier.withDefaultNamespace("container/slot/redstone_dust");
|
| 67 | private static final Identifier EMPTY_SLOT_QUARTZ = Identifier.withDefaultNamespace("container/slot/quartz");
|
| 68 | private static final Identifier EMPTY_SLOT_EMERALD = Identifier.withDefaultNamespace("container/slot/emerald");
|
| 69 | private static final Identifier EMPTY_SLOT_DIAMOND = Identifier.withDefaultNamespace("container/slot/diamond");
|
| 70 | private static final Identifier EMPTY_SLOT_LAPIS_LAZULI = Identifier.withDefaultNamespace("container/slot/lapis_lazuli");
|
| 71 | private static final Identifier EMPTY_SLOT_AMETHYST_SHARD = Identifier.withDefaultNamespace("container/slot/amethyst_shard");
|
| 72 | private static final Identifier EMPTY_SLOT_NAUTILUS_ARMOR = Identifier.withDefaultNamespace("container/slot/nautilus_armor");
|
| 73 | private final Component appliesTo;
|
| 74 | private final Component ingredients;
|
| 75 | private final Component baseSlotDescription;
|
| 76 | private final Component additionsSlotDescription;
|
| 77 | private final List<Identifier> baseSlotEmptyIcons;
|
| 78 | private final List<Identifier> additionalSlotEmptyIcons;
|
| 79 |
|
| 80 | public SmithingTemplateItem(
|
| 81 | final Component appliesTo,
|
| 82 | final Component ingredients,
|
| 83 | final Component baseSlotDescription,
|
| 84 | final Component additionsSlotDescription,
|
| 85 | final List<Identifier> baseSlotEmptyIcons,
|
| 86 | final List<Identifier> additionalSlotEmptyIcons,
|
| 87 | final Item.Properties properties
|
| 88 | ) {
|
| 89 | super(properties);
|
| 90 | this.appliesTo = appliesTo;
|
| 91 | this.ingredients = ingredients;
|
| 92 | this.baseSlotDescription = baseSlotDescription;
|
| 93 | this.additionsSlotDescription = additionsSlotDescription;
|
| 94 | this.baseSlotEmptyIcons = baseSlotEmptyIcons;
|
| 95 | this.additionalSlotEmptyIcons = additionalSlotEmptyIcons;
|
| 96 | }
|
| 97 |
|
| 98 | public static SmithingTemplateItem createArmorTrimTemplate(final Item.Properties properties) {
|
| 99 | return new SmithingTemplateItem(
|
| 100 | ARMOR_TRIM_APPLIES_TO,
|
| 101 | ARMOR_TRIM_INGREDIENTS,
|
| 102 | ARMOR_TRIM_BASE_SLOT_DESCRIPTION,
|
| 103 | ARMOR_TRIM_ADDITIONS_SLOT_DESCRIPTION,
|
| 104 | createTrimmableArmorIconList(),
|
| 105 | createTrimmableMaterialIconList(),
|
| 106 | properties
|
| 107 | );
|
| 108 | }
|
| 109 |
|
| 110 | public static SmithingTemplateItem createNetheriteUpgradeTemplate(final Item.Properties properties) {
|
| 111 | return new SmithingTemplateItem(
|
| 112 | NETHERITE_UPGRADE_APPLIES_TO,
|
| 113 | NETHERITE_UPGRADE_INGREDIENTS,
|
| 114 | NETHERITE_UPGRADE_BASE_SLOT_DESCRIPTION,
|
| 115 | NETHERITE_UPGRADE_ADDITIONS_SLOT_DESCRIPTION,
|
| 116 | createNetheriteUpgradeIconList(),
|
| 117 | createNetheriteUpgradeMaterialList(),
|
| 118 | properties
|
| 119 | );
|
| 120 | }
|
| 121 |
|
| 122 | private static List<Identifier> createTrimmableArmorIconList() {
|
| 123 | return List.of(EMPTY_SLOT_HELMET, EMPTY_SLOT_CHESTPLATE, EMPTY_SLOT_LEGGINGS, EMPTY_SLOT_BOOTS);
|
| 124 | }
|
| 125 |
|
| 126 | private static List<Identifier> createTrimmableMaterialIconList() {
|
| 127 | return List.of(
|
| 128 | EMPTY_SLOT_INGOT, EMPTY_SLOT_REDSTONE_DUST, EMPTY_SLOT_LAPIS_LAZULI, EMPTY_SLOT_QUARTZ, EMPTY_SLOT_DIAMOND, EMPTY_SLOT_EMERALD, EMPTY_SLOT_AMETHYST_SHARD
|
| 129 | );
|
| 130 | }
|
| 131 |
|
| 132 | private static List<Identifier> createNetheriteUpgradeIconList() {
|
| 133 | return List.of(
|
| 134 | EMPTY_SLOT_HELMET,
|
| 135 | EMPTY_SLOT_SWORD,
|
| 136 | EMPTY_SLOT_CHESTPLATE,
|
| 137 | EMPTY_SLOT_PICKAXE,
|
| 138 | EMPTY_SLOT_LEGGINGS,
|
| 139 | EMPTY_SLOT_AXE,
|
| 140 | EMPTY_SLOT_BOOTS,
|
| 141 | EMPTY_SLOT_HOE,
|
| 142 | EMPTY_SLOT_SHOVEL,
|
| 143 | EMPTY_SLOT_NAUTILUS_ARMOR,
|
| 144 | EMPTY_SLOT_SPEAR
|
| 145 | );
|
| 146 | }
|
| 147 |
|
| 148 | private static List<Identifier> createNetheriteUpgradeMaterialList() {
|
| 149 | return List.of(EMPTY_SLOT_INGOT);
|
| 150 | }
|
| 151 |
|
| 152 | @Override
|
| 153 | public void appendHoverText(
|
| 154 | final ItemStack itemStack, final Item.TooltipContext context, final TooltipDisplay display, final Consumer<Component> builder, final TooltipFlag tooltipFlag
|
| 155 | ) {
|
| 156 | builder.accept(SMITHING_TEMPLATE_SUFFIX);
|
| 157 | builder.accept(CommonComponents.EMPTY);
|
| 158 | builder.accept(APPLIES_TO_TITLE);
|
| 159 | builder.accept(CommonComponents.space().append(this.appliesTo));
|
| 160 | builder.accept(INGREDIENTS_TITLE);
|
| 161 | builder.accept(CommonComponents.space().append(this.ingredients));
|
| 162 | }
|
| 163 |
|
| 164 | public Component getBaseSlotDescription() {
|
| 165 | return this.baseSlotDescription;
|
| 166 | }
|
| 167 |
|
| 168 | public Component getAdditionSlotDescription() {
|
| 169 | return this.additionsSlotDescription;
|
| 170 | }
|
| 171 |
|
| 172 | public List<Identifier> getBaseSlotEmptyIcons() {
|
| 173 | return this.baseSlotEmptyIcons;
|
| 174 | }
|
| 175 |
|
| 176 | public List<Identifier> getAdditionalSlotEmptyIcons() {
|
| 177 | return this.additionalSlotEmptyIcons;
|
| 178 | }
|
| 179 | }
|
| 180 |
|