From 1fe97f5e07e4d4f15ca0597a894048f49abb7174 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 24 Jun 2024 23:24:09 -0400 Subject: [PATCH] Improve inclusion on gold foods --- .../assets/allomancy/lang/en_us.json | 5 +-- .../com/legobmw99/allomancy/Allomancy.java | 2 ++ .../allomancy/datagen/Languages.java | 5 +-- .../modules/consumables/ConsumeSetup.java | 14 ++++++++ .../item/component/FlakeStorage.java | 34 ++++++++++++++----- .../modules/powers/CommonEventHandler.java | 16 +++------ 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/generated/resources/assets/allomancy/lang/en_us.json b/src/generated/resources/assets/allomancy/lang/en_us.json index 01345a82..12930a3a 100644 --- a/src/generated/resources/assets/allomancy/lang/en_us.json +++ b/src/generated/resources/assets/allomancy/lang/en_us.json @@ -159,6 +159,9 @@ "allomancy.electrum.red": "Red Electrum Symbol", "allomancy.electrum.white": "White Electrum Symbol", "allomancy.electrum.yellow": "Yellow Electrum Symbol", + "allomancy.flake_storage.lore_count": "Contains %s metals", + "allomancy.flake_storage.lore_inst": "Hold SHIFT to view", + "allomancy.flake_storage.lore_single": "Contains 1 metal", "allomancy.gold.black": "Black Gold Symbol", "allomancy.gold.blue": "Blue Gold Symbol", "allomancy.gold.brown": "Brown Gold Symbol", @@ -415,8 +418,6 @@ "item.allomancy.tin_pattern": "Banner Pattern", "item.allomancy.tin_pattern.desc": "Tin Symbol", "item.allomancy.vial": "Allomantic Vial", - "item.allomancy.vial.lore_count": "Contains %d metals", - "item.allomancy.vial.lore_inst": "Hold SHIFT to view", "item.allomancy.zinc_flakes": "Zinc Flakes", "item.allomancy.zinc_ingot": "Zinc Ingot", "item.allomancy.zinc_nugget": "Zinc Nugget", diff --git a/src/main/java/com/legobmw99/allomancy/Allomancy.java b/src/main/java/com/legobmw99/allomancy/Allomancy.java index d82f3b65..6e57e0db 100644 --- a/src/main/java/com/legobmw99/allomancy/Allomancy.java +++ b/src/main/java/com/legobmw99/allomancy/Allomancy.java @@ -53,6 +53,8 @@ public Allomancy(IEventBus bus, ModContainer container, Dist dist) { bus.addListener(CombatClientSetup::registerEntityRenders); ConsumeSetup.register(bus); + bus.addListener(ConsumeSetup::onModifyComponents); + MaterialsSetup.register(bus); ItemDisplay.register(bus); diff --git a/src/main/java/com/legobmw99/allomancy/datagen/Languages.java b/src/main/java/com/legobmw99/allomancy/datagen/Languages.java index 1fe34b14..4ad2379e 100644 --- a/src/main/java/com/legobmw99/allomancy/datagen/Languages.java +++ b/src/main/java/com/legobmw99/allomancy/datagen/Languages.java @@ -69,8 +69,9 @@ protected void addTranslations() { add(CombatSetup.KOLOSS_BLADE.get(), "Koloss Blade"); add("item.allomancy.koloss_blade.lore", "This item is too heavy for the average person to wield."); add(ConsumeSetup.VIAL.get(), "Allomantic Vial"); - add("item.allomancy.vial.lore_count", "Contains %d metals"); - add("item.allomancy.vial.lore_inst", "Hold SHIFT to view"); + add("allomancy.flake_storage.lore_single", "Contains 1 metal"); + add("allomancy.flake_storage.lore_count", "Contains %s metals"); + add("allomancy.flake_storage.lore_inst", "Hold SHIFT to view"); add("death.attack.allomancy.coin", "%1$s was perforated by coins from %2$s"); for (Metal mt : Metal.values()) { diff --git a/src/main/java/com/legobmw99/allomancy/modules/consumables/ConsumeSetup.java b/src/main/java/com/legobmw99/allomancy/modules/consumables/ConsumeSetup.java index c77fa802..bd35822e 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/consumables/ConsumeSetup.java +++ b/src/main/java/com/legobmw99/allomancy/modules/consumables/ConsumeSetup.java @@ -1,6 +1,7 @@ package com.legobmw99.allomancy.modules.consumables; import com.legobmw99.allomancy.Allomancy; +import com.legobmw99.allomancy.api.enums.Metal; import com.legobmw99.allomancy.modules.consumables.item.GrinderItem; import com.legobmw99.allomancy.modules.consumables.item.LerasiumItem; import com.legobmw99.allomancy.modules.consumables.item.VialItem; @@ -8,8 +9,10 @@ import com.legobmw99.allomancy.modules.consumables.item.recipe.VialItemRecipe; import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.RecipeSerializer; import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.event.ModifyDefaultComponentsEvent; import net.neoforged.neoforge.registries.DeferredItem; import net.neoforged.neoforge.registries.DeferredRegister; @@ -45,4 +48,15 @@ public static void register(IEventBus bus) { RECIPES.register(bus); } + + public static void onModifyComponents(final ModifyDefaultComponentsEvent event) { + FlakeStorage.Mutable storage = new FlakeStorage.Mutable(); + storage.add(Metal.GOLD); + FlakeStorage gold = storage.toImmutable(); + + // TODO hide tooltip on these? + event.modify(Items.GOLDEN_APPLE, builder -> builder.set(FLAKE_STORAGE.get(), gold)); + event.modify(Items.GOLDEN_CARROT, builder -> builder.set(FLAKE_STORAGE.get(), gold)); + event.modify(Items.ENCHANTED_GOLDEN_APPLE, builder -> builder.set(FLAKE_STORAGE.get(), gold)); + } } diff --git a/src/main/java/com/legobmw99/allomancy/modules/consumables/item/component/FlakeStorage.java b/src/main/java/com/legobmw99/allomancy/modules/consumables/item/component/FlakeStorage.java index aced9b56..56fb49f5 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/consumables/item/component/FlakeStorage.java +++ b/src/main/java/com/legobmw99/allomancy/modules/consumables/item/component/FlakeStorage.java @@ -12,7 +12,6 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.component.TooltipProvider; -import java.util.Arrays; import java.util.EnumSet; import java.util.function.Consumer; @@ -72,21 +71,40 @@ public boolean equals(Object other) { } @Override - public void addToTooltip(Item.TooltipContext ctx, Consumer pTooltipAdder, TooltipFlag pTooltipFlag) { + public void addToTooltip(Item.TooltipContext ctx, Consumer tooltip, TooltipFlag flag) { if (Screen.hasShiftDown()) { for (Metal mt : Metal.values()) { if (this.contains(mt)) { - pTooltipAdder.accept(ItemDisplay.addColorToText("metals." + mt.getName(), ChatFormatting.GRAY)); + tooltip.accept(ItemDisplay.addColorToText("metals." + mt.getName(), ChatFormatting.GRAY)); } } } else { - int count = (int) Arrays.stream(Metal.values()).filter(this::contains).count(); - pTooltipAdder.accept( - ItemDisplay.addColorToText("item.allomancy.vial.lore_count", ChatFormatting.GRAY, count)); - pTooltipAdder.accept(ItemDisplay.addColorToText("item.allomancy.vial.lore_inst", ChatFormatting.GRAY)); + int count = 0; + Metal last = Metal.IRON; + for (Metal mt : Metal.values()) { + if (this.contains(mt)) { + count++; + last = mt; + } + } + switch (count) { + case 0 -> { + } + case 1 -> { + tooltip.accept( + ItemDisplay.addColorToText("allomancy.flake_storage.lore_single", ChatFormatting.GRAY)); + tooltip.accept(ItemDisplay.addColorToText("metals." + last.getName(), ChatFormatting.GRAY)); + } + default -> { + tooltip.accept( + ItemDisplay.addColorToText("allomancy.flake_storage.lore_count", ChatFormatting.GRAY, + count)); + tooltip.accept( + ItemDisplay.addColorToText("allomancy.flake_storage.lore_inst", ChatFormatting.GRAY)); + } + } } - } public static class Mutable { diff --git a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java index 15e3401d..8dab5aec 100644 --- a/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java +++ b/src/main/java/com/legobmw99/allomancy/modules/powers/CommonEventHandler.java @@ -223,23 +223,17 @@ public static void onEntityHurt(final LivingIncomingDamageEvent event) { @SubscribeEvent public static void onPlayerFinishUsingItem(final LivingEntityUseItemEvent.Finish event) { - if (!event.getEntity().hasData(AllomancerAttachment.ALLOMANCY_DATA)) { + FlakeStorage storage = event.getItem().get(FLAKE_STORAGE); + + if (storage == null || !event.getEntity().hasData(AllomancerAttachment.ALLOMANCY_DATA)) { return; } var data = event.getEntity().getData(AllomancerAttachment.ALLOMANCY_DATA); - - if (event.getItem().getItem() == Items.GOLDEN_APPLE || event.getItem().getItem() == Items.GOLDEN_CARROT) { - data.incrementStored(Metal.GOLD); - } else if (event.getItem().getItem() == Items.ENCHANTED_GOLDEN_APPLE) { - for (int i = 0; i < 10; i++) { + if (event.getItem().getItem() == Items.ENCHANTED_GOLDEN_APPLE && storage.contains(Metal.GOLD)) { + for (int i = 0; i < AllomancerData.MAX_STORAGE; i++) { data.incrementStored(Metal.GOLD); } } - - FlakeStorage storage = event.getItem().get(FLAKE_STORAGE); - if (storage == null) { - return; - } for (Metal mt : Metal.values()) { if (storage.contains(mt)) { data.incrementStored(mt);