Skip to content

Commit

Permalink
Improve inclusion on gold foods
Browse files Browse the repository at this point in the history
  • Loading branch information
legobmw99 committed Jun 25, 2024
1 parent b6be86f commit 1fe97f5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/generated/resources/assets/allomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/legobmw99/allomancy/Allomancy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/legobmw99/allomancy/datagen/Languages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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;
import com.legobmw99.allomancy.modules.consumables.item.component.FlakeStorage;
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;

Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -72,21 +71,40 @@ public boolean equals(Object other) {
}

@Override
public void addToTooltip(Item.TooltipContext ctx, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) {
public void addToTooltip(Item.TooltipContext ctx, Consumer<Component> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1fe97f5

Please sign in to comment.