diff --git a/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java b/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java new file mode 100644 index 000000000..ec04a466d --- /dev/null +++ b/src/main/java/vazkii/botania/client/core/handler/CorporeaInputHandler.java @@ -0,0 +1,78 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + *

+ * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + *

+ * File Created @ [04/07/2018, ‏‎19:16:14 (GMT)] + */ +package vazkii.botania.client.core.handler; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import org.lwjgl.input.Keyboard; +import vazkii.botania.api.corporea.CorporeaHelper; +import vazkii.botania.client.core.proxy.ClientProxy; +import vazkii.botania.common.block.tile.corporea.TileCorporeaIndex; +import vazkii.botania.common.lib.LibMisc; + +import java.util.function.Supplier; + +@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID, value = Side.CLIENT) +public class CorporeaInputHandler { + + /** Replaced in JEIBotaniaPlugin when JEI's loaded to provide stacks from the JEI item panel. */ + public static Supplier jeiPanelSupplier = () -> ItemStack.EMPTY; + + @SubscribeEvent + public static void buttonPressed(KeyboardInputEvent.Post event) { + Minecraft mc = Minecraft.getMinecraft(); + if(mc.world == null || !(mc.currentScreen instanceof GuiContainer) + || Keyboard.getEventKey() != ClientProxy.CORPOREA_REQUEST.getKeyCode() + || !Keyboard.getEventKeyState() + || Keyboard.isRepeatEvent() + || TileCorporeaIndex.InputHandler.getNearbyIndexes(mc.player).isEmpty()) + return; + + ItemStack stack = getStackUnderMouse(); + if(stack != null && !stack.isEmpty()) { + int count = 1; + int max = stack.getMaxStackSize(); + + if(GuiScreen.isShiftKeyDown()) { + count = max; + if(GuiScreen.isCtrlKeyDown()) + count /= 4; + } else if(GuiScreen.isCtrlKeyDown()) + count = max / 2; + + if(count > 0) { + String name = CorporeaHelper.stripControlCodes(stack.getDisplayName()); + String full = count + " " + name; + + mc.ingameGUI.getChatGUI().addToSentMessages(full); + mc.player.sendChatMessage(full); + event.setCanceled(true); + } + } + } + + private static ItemStack getStackUnderMouse() { + GuiScreen screen = Minecraft.getMinecraft().currentScreen; + if(screen instanceof GuiContainer) { + Slot slotUnderMouse = ((GuiContainer) screen).getSlotUnderMouse(); + if(slotUnderMouse != null) + return slotUnderMouse.getStack(); + } + return jeiPanelSupplier.get(); + } +} diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index a1a4930e1..e89ee7eda 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -18,6 +18,7 @@ import net.minecraft.client.renderer.entity.RenderSnowball; import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -26,6 +27,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.client.model.animation.AnimationTESR; +import net.minecraftforge.client.settings.KeyConflictContext; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; @@ -34,6 +36,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.relauncher.Side; +import org.lwjgl.input.Keyboard; import vazkii.botania.api.boss.IBotaniaBoss; import vazkii.botania.api.lexicon.LexiconEntry; import vazkii.botania.api.lexicon.multiblock.IMultiblockRenderHook; @@ -102,6 +105,7 @@ import vazkii.botania.common.item.ItemSextant.MultiblockSextant; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.equipment.bauble.ItemMonocle; import vazkii.botania.common.lexicon.LexiconData; +import vazkii.botania.common.lib.LibMisc; import java.awt.Desktop; import java.io.File; @@ -132,6 +136,8 @@ public class ClientProxy implements IProxy { EMPTY_MODEL.setVisible(false); } + public static final KeyBinding CORPOREA_REQUEST = new KeyBinding("nei.options.keys.gui.botania_corporea_request", KeyConflictContext.GUI, Keyboard.KEY_C, LibMisc.MOD_NAME); + @Override public void preInit(FMLPreInitializationEvent event) { PersistentVariableHelper.setCacheFile(new File(Minecraft.getMinecraft().mcDataDir, "BotaniaVars.dat")); @@ -170,6 +176,8 @@ public class ClientProxy implements IProxy { } TileEntityItemStackRenderer.instance = new RenderTilePylon.ForwardingTEISR(TileEntityItemStackRenderer.instance); + + ClientRegistry.registerKeyBinding(ClientProxy.CORPOREA_REQUEST); } @Override diff --git a/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java index 0529bd0ce..e1c1e1afa 100644 --- a/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java +++ b/src/main/java/vazkii/botania/client/integration/jei/JEIBotaniaPlugin.java @@ -8,6 +8,7 @@ */ package vazkii.botania.client.integration.jei; +import mezz.jei.api.IJeiRuntime; import mezz.jei.api.IModPlugin; import mezz.jei.api.IModRegistry; import mezz.jei.api.ISubtypeRegistry; @@ -27,6 +28,7 @@ import vazkii.botania.api.recipe.RecipePureDaisy; import vazkii.botania.api.recipe.RecipeRuneAltar; import vazkii.botania.api.state.enums.AltarVariant; import vazkii.botania.api.state.enums.PoolVariant; +import vazkii.botania.client.core.handler.CorporeaInputHandler; import vazkii.botania.client.gui.crafting.ContainerCraftingHalo; import vazkii.botania.client.integration.jei.brewery.BreweryRecipeCategory; import vazkii.botania.client.integration.jei.brewery.BreweryRecipeWrapper; @@ -51,7 +53,6 @@ import vazkii.botania.common.item.ModItems; import vazkii.botania.common.item.block.ItemBlockSpecialFlower; import javax.annotation.Nonnull; -import java.util.Map; import java.util.stream.Collectors; import static vazkii.botania.common.lib.LibBlockNames.SUBTILE_ORECHID; @@ -148,4 +149,14 @@ public class JEIBotaniaPlugin implements IModPlugin { registry.getRecipeTransferRegistry().addRecipeTransferHandler(ContainerCraftingHalo.class, VanillaRecipeCategoryUid.CRAFTING, 1, 9, 10, 36); } + @Override + public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { + CorporeaInputHandler.jeiPanelSupplier = () -> { + Object o = jeiRuntime.getIngredientListOverlay().getIngredientUnderMouse(); + if(o instanceof ItemStack) + return (ItemStack) o; + return ItemStack.EMPTY; + }; + } + } diff --git a/src/main/resources/assets/botania/lang/en_us.lang b/src/main/resources/assets/botania/lang/en_us.lang index ed8660548..bbe4c9a28 100644 --- a/src/main/resources/assets/botania/lang/en_us.lang +++ b/src/main/resources/assets/botania/lang/en_us.lang @@ -3247,7 +3247,7 @@ botania.page.corporeaIndex2=Requests can be more complex than just a single item botania.page.corporeaIndex3=The plural form of an item's name may only be used case it's a regular noun when it comes to the plural (suffixed by "-s", "-es" or "-ies"), the singular version works just as well for requests of multiple items, such as "10 apple".
"10 of this" requests 10 items whose name equals the item in the player's hand, as expected. botania.page.corporeaIndex4=Examples of complex requests include "10 apples", "a stack of apples", "2 stacks of apples", "2 stacks and 20 apples", "half a stack of apples", "a dozen apples", and so on.
The index will also recognise more or less verbose forms of request, so "2x stacks and 20x of apples" is equal to "2 stack 2 apple" or "2 stacks + 2 apples". botania.page.corporeaIndex5=Requesting with "all" or "every" will deliver every single item in the network that matches the criteria, so "all apples" will deliver all the apples in the network.
On the other side, requesting "count", "show", "display" or "tell" won't request any, but will tell the requester how many exist in the network. -botania.page.corporeaIndex8=While near a &1Corporea Index&0, if one is using &4NotEnoughItems&0, pressing C on an item in one's inventory (or NEI panel) will request 1 of said item.
Using SHIFT will instead request a full stack, CTRL will request half a stack and SHIFT+CTRL a quarter of a stack. +botania.page.corporeaIndex8=While near a &1Corporea Index&0, pressing C on an item in one's inventory (or, if one is using &4JustEnoughItems&0, the JEI panel) will request 1 of said item.
Using SHIFT will instead request a full stack, CTRL will request half a stack and SHIFT+CTRL a quarter of a stack. botania.page.corporeaIndex6=Lastly, while near a &1Corporea Index&0, writing part of an item's name and pressing TAB in the chat menu will autocomplete the item's name. botania.page.corporeaIndex7=A certain magical one at that diff --git a/src/main/resources/assets/botania/lang/zh_cn.lang b/src/main/resources/assets/botania/lang/zh_cn.lang index 01e3416c8..4d2cc0cb7 100644 --- a/src/main/resources/assets/botania/lang/zh_cn.lang +++ b/src/main/resources/assets/botania/lang/zh_cn.lang @@ -3244,7 +3244,7 @@ botania.page.corporeaIndex2=输入"铁..."将搜索任何名称包 括"铁"的 botania.page.corporeaIndex3=物品名称的复数形式只能在 常规名词涉及到复数(以"-s", "-es"或"-ies"为后缀)时使用, 当前版本同样适用于多个物 品请求,例如"10 苹果".
"10 of this"搜索10个等同于 玩家手持物品的物品. botania.page.corporeaIndex4=复数请求的例子包括 "10 apples", "a stack of apples", "2 stacks of apples", "2 stacks and 20 apples", "half a stack of apples", "a dozen apples",等等.
索引可以识别或多或少的搜 索的繁琐形式,所以: "2x stacks and 20x of apples"等同于 "2 stack 2 apple"或 "2 stacks + 2 apples". botania.page.corporeaIndex5=搜索"all"或"every"会提供网络 内符合条件的全部物品,所以 "all 苹果"将提供网络内所有 苹果.
另外,搜索"count","show","tell" 或"display"不会抽取任何物品, 但会显示物品库存. -botania.page.corporeaIndex8=若有人在&1多媒体索引&0附近使用 &4NEI&0,只需对着物品栏中某个物品 按C(NEI面板中亦可)即可请求一 个对应物品.
按住SHIFT则可请求一组, 按住 CTRL可请求半组,同时按住SHIFT和 CTRL则可请求四分之一组. +botania.page.corporeaIndex8=若有人在&1多媒体索引&0附近使用 &4JEI&0,只需对着物品栏中某个物品 按C(JEI面板中亦可)即可请求一 个对应物品.
按住SHIFT则可请求一组, 按住 CTRL可请求半组,同时按住SHIFT和 CTRL则可请求四分之一组. botania.page.corporeaIndex6=最后,在&1多媒体索引&0附近,并在聊 天窗口中输入物品名称的一部 分后,可使用TAB键补全物品全名. botania.page.corporeaIndex7=魔法禁书索引,不对,目录