Skip to content

Commit

Permalink
add KeyBindings and crafting helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vfyjxf committed Oct 1, 2021
1 parent f946acc commit 0bed08f
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This mod removes that functionality and allows the player to use NEI's transfer
- Support Processing Pattern Terminal(16 -> 4 mode).
- Allow you to add item blackList and item priority list, if item in them, it will not be transferred / transfer it first.(use /nee RecipeProcessor to get RecipeProcessor and identifier in log)
- Allow you to add mod priority list,if the mod's has this item,it will be use first.
- You can use the mouse wheel to change the Pattern item input/output amount.
- You can use the ctrl + mouse wheel to change the Pattern item input/output amount.
- You can use shift + mouse wheel to choose ingredient.

## Compatible Modslist as followed:
Expand Down
2 changes: 1 addition & 1 deletion READNE_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min
- 支持增广样板终端(16 -> 4模式)
- 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移
- 允许你设置mod优先级列表,优先使用该mod的物品
- 你可以使用鼠标滚轮来修改样板的输入/输出数量
- 你可以使用ctrl + 鼠标滚轮来修改样板的输入/输出数量
- 你可以使用shift + 鼠标滚轮来选择材料

## 当前支持的Mod列表:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.daemon=false
mc_version=1.7.10
nei_version=2.1.6-GTNH
ae2_version=rv3-beta-52-GTNH
mod_version=1.2.13
mod_version=1.2.14
forge_version=10.13.4.1614
mod_group=com.github.vfyjxf.neenergistics
mod_id=neenergistics
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/vfyjxf/nee/NEECommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void processCommand(ICommandSender sender, String[] args) {
}
}
} else if ("add".equalsIgnoreCase(args[0]) && args.length > 1) {
if ("blacklist".equals(args[1]) || "priorityItem".equalsIgnoreCase(args[1])) {
if ("blacklist".equalsIgnoreCase(args[1]) || "priorityItem".equalsIgnoreCase(args[1])) {
ItemStack currentStack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
if (currentStack != null) {
String currentItemJsonString = ItemUtils.toItemJsonString(currentStack);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.github.vfyjxf.nee;

import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiPatternTermEx;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
import com.github.vfyjxf.nee.processor.RecipeProcessor;
import cpw.mods.fml.common.Loader;
import org.lwjgl.input.Keyboard;
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter;

Expand All @@ -23,6 +26,8 @@ public void loadConfig() {

RecipeProcessor.init();

registerKeyBindings();

Set<String> defaultIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
);
Expand All @@ -37,6 +42,8 @@ public void loadConfig() {
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
}

installCraftingTermSupport();

installPatternTerminalExSupport(identifiers);

installThaumicEnergisticsSupport();
Expand All @@ -54,6 +61,20 @@ public String getVersion() {
return NotEnoughEnergistics.VERSION;
}

private void registerKeyBindings() {
API.addKeyBind("nee.count", Keyboard.KEY_LCONTROL);
API.addKeyBind("nee.ingredient", Keyboard.KEY_LSHIFT);
API.addKeyBind("nee.preview", Keyboard.KEY_LCONTROL);
API.addKeyBind("nee.nopreview", Keyboard.KEY_LMENU);
}

private void installCraftingTermSupport() {
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting");
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting2x2");
API.registerGuiOverlayHandler(GuiCraftingTerm.class, new NEECraftingHelper(), "crafting");
API.registerGuiOverlayHandler(GuiCraftingTerm.class, new NEECraftingHelper(), "crafting2x2");
}

private void installThaumicEnergisticsSupport() {
try {
Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
import com.github.vfyjxf.nee.proxy.CommonProxy;
import com.github.vfyjxf.nee.utils.GuiUtils;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
Expand Down Expand Up @@ -39,6 +41,9 @@ public class NotEnoughEnergistics {
public static final String GUI_FACTORY = "com.github.vfyjxf.nee.config.NEEConfigGuiFactory";
public static final Logger logger = LogManager.getLogger("NotEnoughEnergistics");

@SidedProxy(clientSide = "com.github.vfyjxf.nee.proxy.ClientProxy", serverSide = "com.github.vfyjxf.nee.proxy.ServerProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent e) {
NEENetworkHandler.init();
Expand All @@ -48,32 +53,7 @@ public void preInit(FMLPreInitializationEvent e) {

@EventHandler
public void init(FMLInitializationEvent event) {
if (FMLCommonHandler.instance().getSide().isClient()) {
FMLCommonHandler.instance().bus().register(this);
ClientCommandHandler.instance.registerCommand(new NEECommands());
}
}

@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
Minecraft mc = Minecraft.getMinecraft();
int dWheel = Mouse.getDWheel();
if (dWheel != 0 && mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen)) {
int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth;
int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1;
Slot currentSlot = GuiUtils.getSlotUnderMouse((GuiContainer) mc.currentScreen, x, y);
if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) {
//try to change current itemstack to next ingredient;
if (GuiContainer.isShiftKeyDown() && GuiUtils.isCraftingSlot(currentSlot)) {
GuiUtils.handleRecipeIngredientChange(currentSlot, dWheel);
} else if (GuiContainer.isCtrlKeyDown()) {
int changeCount = dWheel / 120;
NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount));
}
}
}
}
proxy.init(event);
}

}
60 changes: 60 additions & 0 deletions src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.github.vfyjxf.nee.client;

import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotFake;
import codechicken.nei.NEIClientConfig;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingHelper;
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
import com.github.vfyjxf.nee.utils.GuiUtils;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
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.minecraftforge.client.event.GuiOpenEvent;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*;

public class GuiHandler {

@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
Minecraft mc = Minecraft.getMinecraft();
int dWheel = Mouse.getDWheel();
boolean isPatternTerm = mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen);
if (dWheel != 0 && isPatternTerm) {
int x = Mouse.getEventX() * mc.currentScreen.width / mc.displayWidth;
int y = mc.currentScreen.height - Mouse.getEventY() * mc.currentScreen.height / mc.displayHeight - 1;
Slot currentSlot = GuiUtils.getSlotUnderMouse((GuiContainer) mc.currentScreen, x, y);
if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) {
//try to change current itemstack to next ingredient;
if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.ingredient")) && GuiUtils.isCraftingSlot(currentSlot)) {
GuiUtils.handleRecipeIngredientChange(currentSlot, dWheel);
} else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.count"))) {
int changeCount = dWheel / 120;
NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount));
}
}
}
}
}

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (event.gui instanceof GuiCraftingTerm && currentScreen instanceof GuiCraftConfirm && tracker != null) {
if (tracker.getRequireToCraftStacks().size() > 1 && stackIndex < tracker.getRequireToCraftStacks().size()) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(stackIndex), noPreview));
stackIndex++;
}
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class NEEConfig {
public static String[] transformPriorityList = new String[0];
public static String[] transformPriorityModList = new String[0];

public static boolean noShift = true;

public static void loadConfig(File configFile) {
config = new Configuration(configFile);
config.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private int getSlotIndex(int xy) {
}
}

private boolean isCraftingTableRecipe(IRecipeHandler recipe) {
public static boolean isCraftingTableRecipe(IRecipeHandler recipe) {
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
Expand Down
Loading

0 comments on commit 0bed08f

Please sign in to comment.