-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp JEI Helpers, Revamp Information Item
- Loading branch information
1 parent
477d343
commit d7f2a52
Showing
17 changed files
with
343 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,60 @@ | ||
import gregtech.client.utils.TooltipHelper | ||
import net.minecraft.util.text.TextFormatting | ||
|
||
import static com.nomiceu.nomilabs.groovy.GroovyHelpers.JEIHelpers.* | ||
import static com.nomiceu.nomilabs.groovy.GroovyHelpers.TranslationHelpers.* | ||
|
||
// JEI Helpers. (Goes in Post Init) | ||
// JEI and Translation Helpers. (Goes in Post Init) | ||
|
||
// There are two types of translations: translate and translatable. | ||
// Translate translates the input NOW, whilst translatable translates the input when it is needed. | ||
// All JEI Pages use Translatable, so that the language can be changed on-the-fly. | ||
|
||
// Translate: Instantly Translate Something, on Server or Client, with Parameters | ||
// Use TranslateFormat to Translate with Parameters and a GT Format Code wrapped around the string! | ||
// (Note, normal format codes should be included in the lang itself, and thus are not available with `translateFormat`) | ||
// (Note, normal format codes are still available with `format`) | ||
println('Translated Hand Framing Tool Side: ' + translate('tooltip.nomilabs.hand_framing_tool.side', format('Hi', TextFormatting.AQUA))) | ||
println('Translated Hand Framing Tool Main: ' + translateFormat('tooltip.nomilabs.hand_framing_tool.not_set', TooltipHelper.RAINBOW)) | ||
|
||
// Translatable: Save something to be translated later | ||
var translatableObj = translatable('tooltip.nomilabs.excitationcoil.description') | ||
|
||
// You can add formatting (TextFormatting, GTFormatCode, or Format) | ||
translatableObj.addFormat(TextFormatting.AQUA) | ||
|
||
// You can append other translatable objects | ||
// Note that appended objects will be concatenated with no seperator, and in this order: | ||
// If translatable1 has translated2 and translated3 appended in that order, and translated2 has p1 and p2 appended in that order: | ||
// transtable1 + translated2 + p1 + p2 + translated3 | ||
translatableObj.append(translatable('tooltip.nomilabs.hand_framing_tool.front', format('Hello World!', TextFormatting.RED))) | ||
|
||
// Very flexible, you can even append literal strings | ||
translatableObj.append(translatableLiteral('Hello World!')) | ||
|
||
// Call `toString` or `translate` to retrieve the translated and concatenated string | ||
println('Translatable Object: ' + translatableObj.translate()) | ||
|
||
/* JEI Pages. Each Method requires Translatable Objects. */ | ||
|
||
/* Description Pages. Each entry is seperated by double new lines. */ | ||
|
||
// Add a description page for a stack | ||
addDescription(item('minecraft:apple'), format("An Ordinary Apple... Not Poisoned.", TextFormatting.DARK_GREEN), "Eat it!") | ||
addDescription(item('minecraft:apple'), translatableLiteral('An Ordinary Apple... Not Poisoned.').addFormat(TextFormatting.DARK_GREEN), translatableLiteral('Eat it!')) | ||
|
||
// Add a translated description page for a stack | ||
addDescription(item('minecraft:iron_ingot'), translate("tooltip.nomilabs.greenhouse.description"), translate("tooltip.nomilabs.dme_sim_chamber.description")) | ||
addDescription(item('minecraft:iron_ingot'), translatable('tooltip.nomilabs.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) | ||
|
||
/* Recipe Output Tooltips. These are tooltips that appear on CRAFTING recipes that output that stack. */ | ||
|
||
// Add a crafting recipe output tooltip for a stack | ||
addRecipeOutputTooltip(item('minecraft:gold_ingot'), format("A Very Low Carrot Gold Ingot.", TextFormatting.GOLD), "Oops! Meant Carat!") | ||
addRecipeOutputTooltip(item('minecraft:gold_ingot'), translatableLiteral('A Very Low Carrot Gold Ingot.').addFormat(TextFormatting.GOLD)) | ||
|
||
// Add a translated crafting recipe output tooltip for a stack | ||
addRecipeOutputTooltip(item('minecraft:iron_ingot'), translate("tooltip.nomilabs.greenhouse.description"), translate("tooltip.nomilabs.dme_sim_chamber.description")) | ||
addRecipeOutputTooltip(item('minecraft:iron_ingot'), translatable('tooltip.nomilabs.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) | ||
|
||
// Add a crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild) | ||
addRecipeOutputTooltip(item('minecraft:gold_ingot'), resource('minecraft:gold_ingot_from_block'), format("A Very High Carat Gold Ingot.", TextFormatting.GOLD), "Precious!") | ||
addRecipeOutputTooltip(item('minecraft:gold_ingot'), resource('minecraft:gold_ingot_from_block'), translatableLiteral('A Very High Carrot Gold Ingot.').addFormat(TextFormatting.GOLD)) | ||
|
||
// Add a translated crafting recipe output tooltip for a specific recipe for a stack (Higher Priority than wild) | ||
addRecipeOutputTooltip(item('minecraft:iron_ingot'), resource('minecraft:iron_ingot_from_nuggets'), translate("tooltip.nomilabs.universalnavigator.description"), translate("tooltip.nomilabs.greenhouse.description"), translate("tooltip.nomilabs.dme_sim_chamber.description")) | ||
addRecipeOutputTooltip(item('minecraft:iron_ingot'), resource('minecraft:iron_ingot_from_nuggets'), translatable('tooltip.nomilabs.universalnavigator.description'), translatable('tooltip.nomilabs.greenhouse.description'), translatable('tooltip.nomilabs.dme_sim_chamber.description')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/nomiceu/nomilabs/event/LabsLanguageChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.nomiceu.nomilabs.event; | ||
|
||
import net.minecraft.client.resources.Language; | ||
import net.minecraftforge.fml.common.eventhandler.Event; | ||
|
||
/** | ||
* An event that is called AFTER language is changed, and resources are refreshed. | ||
* <p> | ||
* Called Client Side ONLY. | ||
*/ | ||
public class LabsLanguageChangedEvent extends Event { | ||
|
||
public final Language oldLanguage; | ||
public final Language newLanguage; | ||
|
||
public LabsLanguageChangedEvent(Language oldLanguage, Language newLanguage) { | ||
this.oldLanguage = oldLanguage; | ||
this.newLanguage = newLanguage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.nomiceu.nomilabs.item; | ||
|
||
import static com.nomiceu.nomilabs.util.LabsTranslate.*; | ||
|
||
import java.util.*; | ||
|
||
import net.minecraft.client.util.ITooltipFlag; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.EnumRarity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.IRarity; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* An item specifically designed to show information, via the tooltip. | ||
* <p> | ||
* Note that this item is not in any creative tabs or JEI! | ||
*/ | ||
public class ItemInfo extends Item { | ||
|
||
private final EnumRarity rarity; | ||
private static final Map<Integer, Translatable[]> TOOLTIP_MAP; | ||
|
||
public static final int AE2_STUFF_REMAP_INFO = 1; | ||
|
||
public ItemInfo(ResourceLocation rl, EnumRarity rarity) { | ||
setRegistryName(rl); | ||
setMaxStackSize(64); | ||
setHasSubtypes(true); | ||
|
||
this.rarity = rarity; | ||
} | ||
|
||
/** | ||
* Does not include the item with no meta. | ||
*/ | ||
public Set<Integer> getSubMetas() { | ||
return TOOLTIP_MAP.keySet(); | ||
} | ||
|
||
@Override | ||
protected boolean isInCreativeTab(@NotNull CreativeTabs targetTab) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public @NotNull IRarity getForgeRarity(@NotNull ItemStack stack) { | ||
return rarity; | ||
} | ||
|
||
@Override | ||
public void addInformation(ItemStack stack, @Nullable World worldIn, @NotNull List<String> tooltip, | ||
@NotNull ITooltipFlag flagIn) { | ||
if (!TOOLTIP_MAP.containsKey(stack.getMetadata())) return; | ||
|
||
var tooltipList = TOOLTIP_MAP.get(stack.getMetadata()); | ||
for (var line : tooltipList) { | ||
tooltip.add(line.translate()); | ||
} | ||
} | ||
|
||
static { | ||
TOOLTIP_MAP = new HashMap<>(); | ||
// Leave Meta 0 as Nothing, so its almost a normal item | ||
TOOLTIP_MAP.put(AE2_STUFF_REMAP_INFO, new Translatable[] { | ||
translatable("tooltip.nomilabs.info.ae2-stuff.1"), | ||
translatableLiteral(""), | ||
translatable("tooltip.nomilabs.info.ae2-stuff.2"), | ||
translatableLiteral(""), | ||
translatable("tooltip.nomilabs.info.ae2-stuff.3"), | ||
translatable("tooltip.nomilabs.info.ae2-stuff.4"), | ||
translatable("tooltip.nomilabs.info.ae2-stuff.5") | ||
}); | ||
} | ||
} |
Oops, something went wrong.