mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Pressing a KeyBinding while in the inventory while hovering over an Item that has an entry in the book will open said entry
This commit is contained in:
parent
5a73b28ac4
commit
57e236f5a5
4 changed files with 93 additions and 15 deletions
|
@ -11,24 +11,77 @@
|
||||||
package ellpeck.actuallyadditions.event;
|
package ellpeck.actuallyadditions.event;
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
|
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
||||||
|
import ellpeck.actuallyadditions.booklet.InitBooklet;
|
||||||
|
import ellpeck.actuallyadditions.booklet.page.BookletPage;
|
||||||
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
||||||
|
import ellpeck.actuallyadditions.util.KeyBinds;
|
||||||
import ellpeck.actuallyadditions.util.KeyUtil;
|
import ellpeck.actuallyadditions.util.KeyUtil;
|
||||||
import ellpeck.actuallyadditions.util.ModUtil;
|
import ellpeck.actuallyadditions.util.ModUtil;
|
||||||
import ellpeck.actuallyadditions.util.StringUtil;
|
import ellpeck.actuallyadditions.util.StringUtil;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumChatFormatting;
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TooltipEvent{
|
public class TooltipEvent{
|
||||||
|
|
||||||
private static final String TEXT_PRE = EnumChatFormatting.DARK_GRAY+" ";
|
private static final String ADVANCED_INFO_TEXT_PRE = EnumChatFormatting.DARK_GRAY+" ";
|
||||||
private static final String HEADER_PRE = EnumChatFormatting.GRAY+" -";
|
private static final String ADVANCED_INFO_HEADER_PRE = EnumChatFormatting.GRAY+" -";
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onTooltipEvent(ItemTooltipEvent event){
|
public void onTooltipEvent(ItemTooltipEvent event){
|
||||||
|
//Booklet Access
|
||||||
|
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
|
||||||
|
if(screen != null && !(screen instanceof GuiBooklet) && screen instanceof GuiContainer){
|
||||||
|
GuiContainer gui = (GuiContainer)screen;
|
||||||
|
for(Object o : gui.inventorySlots.inventorySlots){
|
||||||
|
if(o instanceof Slot){
|
||||||
|
Slot slot = (Slot)o;
|
||||||
|
|
||||||
|
int guiLeft = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 4);
|
||||||
|
int guiTop = ReflectionHelper.getPrivateValue(GuiContainer.class, gui, 5);
|
||||||
|
int mouseX = Mouse.getEventX()*gui.width/Minecraft.getMinecraft().displayWidth-guiLeft;
|
||||||
|
int mouseY = gui.height-Mouse.getEventY()*gui.height/Minecraft.getMinecraft().displayHeight-1-guiTop;
|
||||||
|
|
||||||
|
if(mouseX >= slot.xDisplayPosition-1 && mouseY >= slot.yDisplayPosition-1 && mouseX <= slot.xDisplayPosition+16 && mouseY <= slot.yDisplayPosition+16){
|
||||||
|
ItemStack stack = slot.getStack();
|
||||||
|
if(stack != null){
|
||||||
|
for(BookletPage page : InitBooklet.pagesWithItemStackData){
|
||||||
|
if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){
|
||||||
|
int keyCode = KeyBinds.keybindOpenBooklet.getKeyCode();
|
||||||
|
event.toolTip.add(EnumChatFormatting.GOLD+StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".keyToSeeRecipe", keyCode > 0 && keyCode < Keyboard.KEYBOARD_SIZE ? "'"+Keyboard.getKeyName(keyCode)+"'" : "[KEY NOT DEFINED!]"));
|
||||||
|
|
||||||
|
//Do something better for checking if the key is pressed
|
||||||
|
if(Keyboard.isKeyDown(KeyBinds.keybindOpenBooklet.getKeyCode())){
|
||||||
|
GuiBooklet book = new GuiBooklet();
|
||||||
|
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||||
|
Minecraft.getMinecraft().displayGuiScreen(book);
|
||||||
|
book.openIndexEntry(page.getChapter().entry, InitBooklet.entries.indexOf(page.getChapter().entry)/GuiBooklet.BUTTONS_PER_PAGE+1, true);
|
||||||
|
book.openChapter(page.getChapter(), page);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Advanced Item Info
|
||||||
if(event.itemStack.getItem() != null){
|
if(event.itemStack.getItem() != null){
|
||||||
if(ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()){
|
if(ConfigBoolValues.CTRL_EXTRA_INFO.isEnabled()){
|
||||||
if(KeyUtil.isControlPressed()){
|
if(KeyUtil.isControlPressed()){
|
||||||
|
@ -36,32 +89,32 @@ public class TooltipEvent{
|
||||||
|
|
||||||
//OreDict Names
|
//OreDict Names
|
||||||
int[] oreIDs = OreDictionary.getOreIDs(event.itemStack);
|
int[] oreIDs = OreDictionary.getOreIDs(event.itemStack);
|
||||||
event.toolTip.add(HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".oredictName.desc")+":");
|
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".oredictName.desc")+":");
|
||||||
if(oreIDs.length > 0){
|
if(oreIDs.length > 0){
|
||||||
for(int oreID : oreIDs){
|
for(int oreID : oreIDs){
|
||||||
event.toolTip.add(TEXT_PRE+OreDictionary.getOreName(oreID));
|
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+OreDictionary.getOreName(oreID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
event.toolTip.add(TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".noOredictNameAvail.desc"));
|
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".noOredictNameAvail.desc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Code Name
|
//Code Name
|
||||||
event.toolTip.add(HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".codeName.desc")+":");
|
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".codeName.desc")+":");
|
||||||
event.toolTip.add(TEXT_PRE+Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
|
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+Item.itemRegistry.getNameForObject(event.itemStack.getItem()));
|
||||||
|
|
||||||
//Base Item's Unlocalized Name
|
//Base Item's Unlocalized Name
|
||||||
String baseName = event.itemStack.getItem().getUnlocalizedName();
|
String baseName = event.itemStack.getItem().getUnlocalizedName();
|
||||||
if(baseName != null){
|
if(baseName != null){
|
||||||
event.toolTip.add(HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".baseUnlocName.desc")+":");
|
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".baseUnlocName.desc")+":");
|
||||||
event.toolTip.add(TEXT_PRE+baseName);
|
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Unlocalized Name
|
//Unlocalized Name
|
||||||
String metaName = event.itemStack.getItem().getUnlocalizedName(event.itemStack);
|
String metaName = event.itemStack.getItem().getUnlocalizedName(event.itemStack);
|
||||||
if(metaName != null && baseName != null && !metaName.equals(baseName)){
|
if(metaName != null && baseName != null && !metaName.equals(baseName)){
|
||||||
event.toolTip.add(HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".unlocName.desc")+":");
|
event.toolTip.add(ADVANCED_INFO_HEADER_PRE+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".unlocName.desc")+":");
|
||||||
event.toolTip.add(TEXT_PRE+metaName);
|
event.toolTip.add(ADVANCED_INFO_TEXT_PRE+metaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Disabling Info
|
//Disabling Info
|
||||||
|
|
|
@ -24,10 +24,7 @@ import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||||
import ellpeck.actuallyadditions.event.RenderPlayerEventAA;
|
import ellpeck.actuallyadditions.event.RenderPlayerEventAA;
|
||||||
import ellpeck.actuallyadditions.tile.*;
|
import ellpeck.actuallyadditions.tile.*;
|
||||||
import ellpeck.actuallyadditions.update.UpdateCheckerClientNotifier;
|
import ellpeck.actuallyadditions.update.UpdateCheckerClientNotifier;
|
||||||
import ellpeck.actuallyadditions.util.AssetUtil;
|
import ellpeck.actuallyadditions.util.*;
|
||||||
import ellpeck.actuallyadditions.util.ModUtil;
|
|
||||||
import ellpeck.actuallyadditions.util.PersistantVariables;
|
|
||||||
import ellpeck.actuallyadditions.util.Util;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
|
@ -43,6 +40,7 @@ public class ClientProxy implements IProxy{
|
||||||
|
|
||||||
PersistantVariables.setTheFile(new File(event.getModConfigurationDirectory().getParent(), ModUtil.MOD_ID+"Data.dat"));
|
PersistantVariables.setTheFile(new File(event.getModConfigurationDirectory().getParent(), ModUtil.MOD_ID+"Data.dat"));
|
||||||
|
|
||||||
|
KeyBinds.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
25
src/main/java/ellpeck/actuallyadditions/util/KeyBinds.java
Normal file
25
src/main/java/ellpeck/actuallyadditions/util/KeyBinds.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* This file ("KeyBinds.java") is part of the Actually Additions Mod for Minecraft.
|
||||||
|
* It is created and owned by Ellpeck and distributed
|
||||||
|
* under the Actually Additions License to be found at
|
||||||
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ellpeck.actuallyadditions.util;
|
||||||
|
|
||||||
|
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||||
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
public class KeyBinds{
|
||||||
|
|
||||||
|
public static KeyBinding keybindOpenBooklet = new KeyBinding("key."+ModUtil.MOD_ID_LOWER+".openBooklet.name", Keyboard.KEY_I, "key."+ModUtil.MOD_ID_LOWER+".category");
|
||||||
|
|
||||||
|
public static void init(){
|
||||||
|
ClientRegistry.registerKeyBinding(keybindOpenBooklet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -376,7 +376,9 @@ booklet.actuallyadditions.indexEntry.itemsNoRF.name=Items that don't use RF
|
||||||
booklet.actuallyadditions.indexEntry.itemsRF.name=Items that use RF
|
booklet.actuallyadditions.indexEntry.itemsRF.name=Items that use RF
|
||||||
|
|
||||||
booklet.actuallyadditions.recipeDisabled=The crafting recipe for this item is disabled in the Config File! If you're on a server, ask the server author to enable it in the config. If you're on a client, press the 'Open Config'-Button on the top right and enable the recipe!
|
booklet.actuallyadditions.recipeDisabled=The crafting recipe for this item is disabled in the Config File! If you're on a server, ask the server author to enable it in the config. If you're on a client, press the 'Open Config'-Button on the top right and enable the recipe!
|
||||||
|
|
||||||
booklet.actuallyadditions.clickToSeeRecipe=Click to see more Information
|
booklet.actuallyadditions.clickToSeeRecipe=Click to see more Information
|
||||||
|
booklet.actuallyadditions.keyToSeeRecipe=Press %s to see more Information
|
||||||
|
|
||||||
booklet.actuallyadditions.chapter.intro.name=An Introduction to ActAdd
|
booklet.actuallyadditions.chapter.intro.name=An Introduction to ActAdd
|
||||||
booklet.actuallyadditions.chapter.intro.text.1=<i>This book, written years ago, found by the player, used to help understand the wonders of this world, finally opened, finally looked at, full of glory, full of grace, will be used to help the player along on their journey through <imp>Actually Additions<r><i>. <n>What is <imp>Actually Additions<r><i>, you may ask. <n><imp>Actually Additions<r><i> adds blocks, items, and features to make the player's experience easier, automate the world and properly do what you've always wanted to do.
|
booklet.actuallyadditions.chapter.intro.text.1=<i>This book, written years ago, found by the player, used to help understand the wonders of this world, finally opened, finally looked at, full of glory, full of grace, will be used to help the player along on their journey through <imp>Actually Additions<r><i>. <n>What is <imp>Actually Additions<r><i>, you may ask. <n><imp>Actually Additions<r><i> adds blocks, items, and features to make the player's experience easier, automate the world and properly do what you've always wanted to do.
|
||||||
|
|
Loading…
Reference in a new issue