Reintroduce corporea index requesting from inventory/JEI item panel. (#2668)

* Reintroduce corporea index requesting from item panel.

This was removed in 08550cc442, during
the move from NEI to JEI. Rewritten to use JEI instead of NEI.

* Make this feature not depend on JEI to function, redo key checking

Instead, the JEI plugin will set a dummy supplier in the corporea handler to a proper one pulling from the item panel.
In addition, keyboard checks now use Keyboard's triggers instead.
This commit is contained in:
Hubry authored and Vincent Lee committed 2018-07-13 08:25:34 -07:00
1 parent 58346ad107
commit 73a1055b65
5 files changed
+100 -3

No files matched your search

@@ -0,0 +1,78 @@
/**
* This class was created by <Hubry>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
* <p>
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
* <p>
* 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<ItemStack> 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();
}
}
@@ -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
@@ -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;
};
}
}