Added tooltips for unobtainable ores. (#2663)
This commit is contained in:
parent
a813368c5e
commit
c4625762d1
3 changed files with 24 additions and 7 deletions
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
package techreborn.events;
|
package techreborn.events;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -56,12 +57,18 @@ public class StackToolTipHandler implements ItemTooltipCallback {
|
||||||
|
|
||||||
public static final Map<Item, Boolean> ITEM_ID = Maps.newHashMap();
|
public static final Map<Item, Boolean> ITEM_ID = Maps.newHashMap();
|
||||||
private static final Map<Block, OreDistribution> ORE_DISTRIBUTION_MAP = Maps.newHashMap();
|
private static final Map<Block, OreDistribution> ORE_DISTRIBUTION_MAP = Maps.newHashMap();
|
||||||
|
private static final List<Block> UNOBTAINABLE_ORES = Lists.newLinkedList();
|
||||||
|
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
|
ItemTooltipCallback.EVENT.register(new StackToolTipHandler());
|
||||||
|
|
||||||
for (TRContent.Ores ore : TRContent.Ores.values()) {
|
for (TRContent.Ores ore : TRContent.Ores.values()) {
|
||||||
if (ore.isDeepslate()) continue;
|
if (ore.isDeepslate()) {
|
||||||
|
TRContent.Ores normal = ore.getUnDeepslate();
|
||||||
|
if (normal.distribution != null && normal.distribution.dimension != TargetDimension.OVERWORLD)
|
||||||
|
UNOBTAINABLE_ORES.add(ore.block);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (ore.distribution != null) {
|
if (ore.distribution != null) {
|
||||||
ORE_DISTRIBUTION_MAP.put(ore.block, ore.distribution);
|
ORE_DISTRIBUTION_MAP.put(ore.block, ore.distribution);
|
||||||
|
@ -103,19 +110,20 @@ public class StackToolTipHandler implements ItemTooltipCallback {
|
||||||
tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
|
tooltipLines.addAll(ToolTipAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text text = null;
|
||||||
|
if (UNOBTAINABLE_ORES.contains(block))
|
||||||
|
text = new TranslatableText("techreborn.tooltip.unobtainable");
|
||||||
OreDistribution oreDistribution = ORE_DISTRIBUTION_MAP.get(block);
|
OreDistribution oreDistribution = ORE_DISTRIBUTION_MAP.get(block);
|
||||||
|
if (oreDistribution != null && text == null) {
|
||||||
if (oreDistribution != null) {
|
text = switch (oreDistribution.dimension) {
|
||||||
Text text = switch (oreDistribution.dimension) {
|
|
||||||
case OVERWORLD -> getOverworldOreText(oreDistribution);
|
case OVERWORLD -> getOverworldOreText(oreDistribution);
|
||||||
case END -> new TranslatableText("techreborn.tooltip.ores.end");
|
case END -> new TranslatableText("techreborn.tooltip.ores.end");
|
||||||
case NETHER -> new TranslatableText("techreborn.tooltip.ores.nether");
|
case NETHER -> new TranslatableText("techreborn.tooltip.ores.nether");
|
||||||
};
|
};
|
||||||
|
}
|
||||||
if (text != null)
|
if (text != null)
|
||||||
tooltipLines.add(text.copy().formatted(Formatting.AQUA));
|
tooltipLines.add(text.copy().formatted(Formatting.AQUA));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isTRItem(Item item) {
|
private static boolean isTRItem(Item item) {
|
||||||
return Registry.ITEM.getId(item).getNamespace().equals("techreborn");
|
return Registry.ITEM.getId(item).getNamespace().equals("techreborn");
|
||||||
|
|
|
@ -381,6 +381,8 @@ public class TRContent {
|
||||||
|
|
||||||
private final static Map<Ores, Ores> deepslateMap = new HashMap<>();
|
private final static Map<Ores, Ores> deepslateMap = new HashMap<>();
|
||||||
|
|
||||||
|
private final static Map<Ores, Ores> unDeepslateMap = new HashMap<>();
|
||||||
|
|
||||||
public enum Ores implements ItemConvertible {
|
public enum Ores implements ItemConvertible {
|
||||||
// when changing ores also change data/techreborn/tags/items/ores.json for correct root advancement display
|
// when changing ores also change data/techreborn/tags/items/ores.json for correct root advancement display
|
||||||
// as well as data/minecraft/tags/blocks for correct mining level
|
// as well as data/minecraft/tags/blocks for correct mining level
|
||||||
|
@ -432,6 +434,7 @@ public class TRContent {
|
||||||
Ores(TRContent.Ores stoneOre) {
|
Ores(TRContent.Ores stoneOre) {
|
||||||
this((OreDistribution) null);
|
this((OreDistribution) null);
|
||||||
deepslateMap.put(stoneOre, this);
|
deepslateMap.put(stoneOre, this);
|
||||||
|
unDeepslateMap.put(this, stoneOre);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -444,6 +447,11 @@ public class TRContent {
|
||||||
return deepslateMap.get(this);
|
return deepslateMap.get(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TRContent.Ores getUnDeepslate() {
|
||||||
|
Preconditions.checkArgument(isDeepslate());
|
||||||
|
return unDeepslateMap.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isDeepslate() {
|
public boolean isDeepslate() {
|
||||||
return name.startsWith("deepslate_");
|
return name.startsWith("deepslate_");
|
||||||
}
|
}
|
||||||
|
|
|
@ -875,6 +875,7 @@
|
||||||
"techreborn.tooltip.ores.overworld" : "Can be found at y levels %s < %s",
|
"techreborn.tooltip.ores.overworld" : "Can be found at y levels %s < %s",
|
||||||
"techreborn.tooltip.ores.nether" : "Can be found in the nether",
|
"techreborn.tooltip.ores.nether" : "Can be found in the nether",
|
||||||
"techreborn.tooltip.ores.end" : "Can be found in the end",
|
"techreborn.tooltip.ores.end" : "Can be found in the end",
|
||||||
|
"techreborn.tooltip.unobtainable": "Unobtainable in Survival Mode",
|
||||||
|
|
||||||
"_comment23": "ManualUI",
|
"_comment23": "ManualUI",
|
||||||
"techreborn.manual.wiki": "Online wiki",
|
"techreborn.manual.wiki": "Online wiki",
|
||||||
|
|
Loading…
Add table
Reference in a new issue