Skip to content

Commit

Permalink
polish up stacks and named recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzyhmstrs committed Sep 26, 2024
1 parent 2f51c29 commit 8b0680a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ public ArchaeologyLootRecipe(ClientArchaeologyLootTable loot) {
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + " " + modName);
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString());
} else {
Text unknown = LText.translatable("emi_loot.archaeology.unknown");
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + " " + unknown.getString());
}
if (EMILoot.config.isLogI18n(EMILoot.Type.ARCHAEOLOGY)) {
EMILoot.LOGGER.warn("Untranslated archaeology loot table \"" + loot.id + "\" (key: \"" + key + "\")");
EMILoot.LOGGER.warn("Untranslated archaeology loot table \"{}\" (key: \"{}\")", loot.id, key);
}
} else {
rawTitle = text;
Expand Down Expand Up @@ -143,7 +142,9 @@ public void addWidgets(WidgetHolder widgets) {
}

widgets.addText(title.title(), 1, 0, 0x404040, false);
if (title.trimmed()) {
if (EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
widgets.addTooltip(LText.components(title.rawTitle(), loot.id.getNamespace()), 0, 0, 144, 10);
} else {
widgets.addTooltipText(List.of(title.rawTitle()), 0, 0, 144, 10);
}
AtomicInteger index = new AtomicInteger(lootStacksSortedSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ public ChestLootRecipe(ClientChestLootTable loot) {
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + " " + modName);
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString());
} else {
Text unknown = LText.translatable("emi_loot.chest.unknown");
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + " " + unknown.getString());
}
if (EMILoot.config.isLogI18n(EMILoot.Type.CHEST)) {
EMILoot.LOGGER.warn("Untranslated chest loot table \"" + loot.id + "\" (key: \"" + key + "\")");
EMILoot.LOGGER.warn("Untranslated chest loot table \"{}\" (key: \"{}\")", loot.id, key);
}
} else {
rawTitle = text;
Expand Down Expand Up @@ -146,7 +145,9 @@ public void addWidgets(WidgetHolder widgets) {
finalRowHeight = 18;
}
widgets.addText(title.title(), 1, 0, 0x404040, false);
if (title.trimmed()) {
if (EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
widgets.addTooltip(LText.components(title.rawTitle(), loot.id.getNamespace()), 0, 0, 144, 10);
} else {
widgets.addTooltipText(List.of(title.rawTitle()), 0, 0, 144, 10);
}
AtomicInteger index = new AtomicInteger(lootStacksSortedSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public GameplayLootRecipe(ClientGameplayLootTable loot) {
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + " " + modName);
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString());
} else {
Text unknown = LText.translatable("emi_loot.gameplay.unknown");
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + " " + unknown.getString());
Expand Down Expand Up @@ -166,8 +165,10 @@ public void addWidgets(WidgetHolder widgets) {

//draw the gameplay name
widgets.addText(name.title(), 0, 0, 0x404040, false);
if (name.trimmed()) {
widgets.addTooltipText(List.of(name.rawTitle()), 0, 0, EMILoot.config.isTooltipStyle() ? 144 : 154, 10);
if (EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
widgets.addTooltip(LText.components(name.rawTitle(), loot.id.getNamespace()), 0, 0, 144, 10);
} else {
widgets.addTooltipText(List.of(name.rawTitle()), 0, 0, 144, 10);
}
if (EMILoot.config.isTooltipStyle()) {
List<ConditionalStack> stacks = (outputStacks.size() <= 4 || !EMILoot.config.isCompact(EMILoot.Type.GAMEPLAY))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public void addWidgets(WidgetHolder widgets) {
int offset = ClientResourceData.MOB_OFFSETS.getOrDefault(type, 0);
widgets.addTexture(EmiTexture.LARGE_SLOT, x, y);
widgets.addDrawable(x, y, 16, 16, (matrices, mx, my, delta) -> inputStack.render(matrices, 5, 6 + offset, delta));
widgets.addTooltip(inputStack.getTooltip(), x, y, 24, 24);
}

//draw the name, moved over if the spawn egg is available
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package fzzyhmstrs.emi_loot.util;

import dev.emi.emi.api.render.EmiTooltipComponents;
import dev.emi.emi.api.stack.EmiStack;
import fzzyhmstrs.emi_loot.EMILootClientAgnos;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.List;

public class BlockStateEmiStack extends EmiStack {
Expand Down Expand Up @@ -53,7 +56,15 @@ public Identifier getId() {

@Override
public List<Text> getTooltipText() {
return List.of(Registries.BLOCK.get(id).getName());
return List.of(state.getBlock().getName());
}

@Override
public List<TooltipComponent> getTooltip() {
ArrayList<TooltipComponent> list = new ArrayList<>();
list.add(EmiTooltipComponents.of(state.getBlock().getName()));
EmiTooltipComponents.appendModName(list, id.getNamespace());
return list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public List<TooltipComponent> getTooltip() {
List<TooltipComponent> list = new ArrayList<>();
if (entity != null) {
list.addAll(getTooltipText().stream().map(Text::asOrderedText).map(TooltipComponent::of).toList());
String mod = EMILootAgnos.getModName(Registries.ENTITY_TYPE.getId(entity.getType()).getNamespace());
list.add(TooltipComponent.of(LText.literal(mod).formatted(Formatting.BLUE).formatted(Formatting.ITALIC).asOrderedText()));
EmiTooltipComponents.appendModName(list, Registries.ENTITY_TYPE.getId(entity.getType()).getNamespace());
if (!getRemainder().isEmpty()) {
list.add(EmiTooltipComponents.getRemainderTooltipComponent(this));
}
Expand Down
10 changes: 10 additions & 0 deletions xplat/src/main/java/fzzyhmstrs/emi_loot/util/LText.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package fzzyhmstrs.emi_loot.util;

import dev.emi.emi.api.render.EmiTooltipComponents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.MutableText;
import net.minecraft.text.OrderedText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.util.Language;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -35,6 +38,13 @@ public class LText {
"archaeology"
));

public static List<TooltipComponent> components(Text title, String namespace) {
ArrayList<TooltipComponent> components = new ArrayList<>();
components.add(EmiTooltipComponents.of(title));
EmiTooltipComponents.appendModName(components, namespace);
return components;
}

public static MutableText translatable(String key) {
return Text.translatable(key);
}
Expand Down

0 comments on commit 8b0680a

Please sign in to comment.