mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-10-26 14:23:58 +00:00
add KeyBindings and crafting helper
This commit is contained in:
1 parent
f946acc811
commit
0bed08ffcd
17 files changed
+526
-31
No files matched your search
@@ -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:
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min
|
||||
- 支持增广样板终端(16 -> 4模式)
|
||||
- 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移
|
||||
- 允许你设置mod优先级列表,优先使用该mod的物品
|
||||
- 你可以使用鼠标滚轮来修改样板的输入/输出数量
|
||||
- 你可以使用ctrl + 鼠标滚轮来修改样板的输入/输出数量
|
||||
- 你可以使用shift + 鼠标滚轮来选择材料
|
||||
|
||||
## 当前支持的Mod列表:
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -42,7 +42,7 @@ public class NEECommands extends CommandBase {
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -23,6 +26,8 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
|
||||
RecipeProcessor.init();
|
||||
|
||||
registerKeyBindings();
|
||||
|
||||
Set<String> defaultIdentifiers = new HashSet<>(
|
||||
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
|
||||
);
|
||||
@@ -37,6 +42,8 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
|
||||
}
|
||||
|
||||
installCraftingTermSupport();
|
||||
|
||||
installPatternTerminalExSupport(identifiers);
|
||||
|
||||
installThaumicEnergisticsSupport();
|
||||
@@ -54,6 +61,20 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
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");
|
||||
|
||||
@@ -5,10 +5,12 @@ import appeng.container.slot.SlotFake;
|
||||
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;
|
||||
@@ -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();
|
||||
@@ -48,32 +53,7 @@ public class NotEnoughEnergistics {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -248,7 +248,7 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
import appeng.container.slot.SlotCraftingMatrix;
|
||||
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketNEIRecipe;
|
||||
import appeng.util.Platform;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketCraftingHelper;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class NEECraftingHelper implements IOverlayHandler {
|
||||
public static IngredientTracker tracker = null;
|
||||
public static int stackIndex = 1;
|
||||
public static boolean noPreview = false;
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
Container container = Minecraft.getMinecraft().thePlayer.openContainer;
|
||||
if (firstGui instanceof GuiCraftingTerm && NEECraftingHandler.isCraftingTableRecipe(recipe) && container instanceof ContainerCraftingTerm) {
|
||||
tracker = createTracker((GuiCraftingTerm) firstGui, recipe, recipeIndex);
|
||||
if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview"))) {
|
||||
if (!tracker.getRequireToCraftStacks().isEmpty()) {
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(0), false));
|
||||
noPreview = false;
|
||||
stackIndex = 1;
|
||||
}
|
||||
} else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"))) {
|
||||
//no preview
|
||||
if (!tracker.getRequireToCraftStacks().isEmpty()) {
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(0), true));
|
||||
noPreview = true;
|
||||
stackIndex = 1;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
try {
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false));
|
||||
if (packet.size() >= 32 * 1024) {
|
||||
AELog.warn("Recipe for " + recipe.getRecipeName() + " has too many variants, reduced version will be used");
|
||||
packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, true));
|
||||
}
|
||||
NetworkHandler.instance.sendToServer(packet);
|
||||
} catch (final Exception | Error ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IngredientTracker createTracker(GuiCraftingTerm firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
IngredientTracker tracker = new IngredientTracker(firstGui);
|
||||
List<PositionedStack> requiredIngredient = new ArrayList<>();
|
||||
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
|
||||
ItemStack firstStack = positionedStack.items[0];
|
||||
boolean find = false;
|
||||
for (PositionedStack currentIngredient : requiredIngredient) {
|
||||
ItemStack currentStack = currentIngredient.items[0];
|
||||
if (currentStack.isItemEqual(firstStack) && ItemStack.areItemStackTagsEqual(currentStack, firstStack)) {
|
||||
find = true;
|
||||
currentStack.stackSize = currentStack.stackSize + firstStack.stackSize;
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
requiredIngredient.add(positionedStack);
|
||||
}
|
||||
}
|
||||
|
||||
for (PositionedStack currentIngredient : requiredIngredient) {
|
||||
for (ItemStack currentStack : currentIngredient.items) {
|
||||
if (tracker.hasCraftableStack(currentStack)) {
|
||||
ItemStack requiredStack = currentStack.copy();
|
||||
requiredStack.stackSize = currentIngredient.items[0].stackSize;
|
||||
tracker.addRequireToCraftStack(requiredStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
private boolean testSize(final NBTTagCompound recipe) throws IOException {
|
||||
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
final DataOutputStream outputStream = new DataOutputStream(bytes);
|
||||
CompressedStreamTools.writeCompressed(recipe, outputStream);
|
||||
return bytes.size() > 3 * 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
private NBTTagCompound packIngredients(GuiContainer gui, List<PositionedStack> ingredients, boolean limited) throws IOException {
|
||||
final NBTTagCompound recipe = new NBTTagCompound();
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
for (final Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
|
||||
if (slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix) {
|
||||
if (slot.getSlotIndex() == col + row * 3) {
|
||||
final NBTTagList tags = new NBTTagList();
|
||||
final List<ItemStack> list = new LinkedList<>();
|
||||
|
||||
// prefer pure crystals.
|
||||
for (int x = 0; x < positionedStack.items.length; x++) {
|
||||
if (Platform.isRecipePrioritized(positionedStack.items[x])) {
|
||||
list.add(0, positionedStack.items[x]);
|
||||
} else {
|
||||
list.add(positionedStack.items[x]);
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : list) {
|
||||
final NBTTagCompound tag = new NBTTagCompound();
|
||||
is.writeToNBT(tag);
|
||||
tags.appendTag(tag);
|
||||
if (limited) {
|
||||
final NBTTagCompound test = new NBTTagCompound();
|
||||
test.setTag("#" + slot.getSlotIndex(), tags);
|
||||
if (testSize(test)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipe.setTag("#" + slot.getSlotIndex(), tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onActionPerformedEventPre(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
//make nei's transfer system doesn't require presses shift
|
||||
if (event.gui instanceof GuiRecipe) {
|
||||
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
|
||||
GuiButton[] overlayButtons = null;
|
||||
final int OVERLAY_BUTTON_ID_START = 4;
|
||||
try {
|
||||
overlayButtons = (GuiButton[]) ReflectionHelper.findField(GuiRecipe.class, "overlayButtons").get(guiRecipe);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (overlayButtons != null && event.button.id >= OVERLAY_BUTTON_ID_START && event.button.id < OVERLAY_BUTTON_ID_START + overlayButtons.length) {
|
||||
if (guiRecipe.firstGui instanceof GuiPatternTerm || guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui)) {
|
||||
int recipesPerPage = -1;
|
||||
IRecipeHandler handler = null;
|
||||
try {
|
||||
recipesPerPage = (int) ReflectionHelper.findMethod(GuiRecipe.class, guiRecipe, new String[]{"getRecipesPerPage"}).invoke(guiRecipe);
|
||||
handler = (IRecipeHandler) ReflectionHelper.findField(GuiRecipe.class, "handler").get(guiRecipe);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (recipesPerPage >= 0 && handler != null) {
|
||||
int recipe = guiRecipe.page * recipesPerPage + event.button.id - OVERLAY_BUTTON_ID_START;
|
||||
final IOverlayHandler overlayHandler = handler.getOverlayHandler(guiRecipe.firstGui, recipe);
|
||||
Minecraft.getMinecraft().displayGuiScreen(guiRecipe.firstGui);
|
||||
overlayHandler.overlayRecipe(guiRecipe.firstGui, guiRecipe.currenthandlers.get(guiRecipe.recipetype), recipe, NEIClientUtils.shiftKey());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class NEENetworkHandler {
|
||||
INSTANCE.registerMessage(PacketExtremeRecipe.class, PacketExtremeRecipe.class, 2, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketStackCountChange.class, PacketStackCountChange.class, 3, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketRecipeItemChange.class, PacketRecipeItemChange.class, 4, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketCraftingHelper.class, PacketCraftingHelper.class, 5, Side.SERVER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class PacketCraftingHelper implements IMessage, IMessageHandler<PacketCraftingHelper, IMessage> {
|
||||
|
||||
|
||||
private ItemStack requireToCraftStack;
|
||||
private boolean noPreview;
|
||||
|
||||
public PacketCraftingHelper() {
|
||||
|
||||
}
|
||||
|
||||
public PacketCraftingHelper(ItemStack requireToCraftStack, boolean noPreview) {
|
||||
this.requireToCraftStack = requireToCraftStack;
|
||||
this.noPreview = noPreview;
|
||||
}
|
||||
|
||||
public ItemStack getRequireToCraftStack() {
|
||||
return requireToCraftStack;
|
||||
}
|
||||
|
||||
public boolean isNoPreview() {
|
||||
return noPreview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.requireToCraftStack = ByteBufUtils.readItemStack(buf);
|
||||
this.noPreview = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeItemStack(buf, this.requireToCraftStack);
|
||||
buf.writeBoolean(this.noPreview);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCraftingHelper message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
AEBaseContainer baseContainer = (AEBaseContainer) container;
|
||||
Object target = baseContainer.getTarget();
|
||||
if (target instanceof IGridHost) {
|
||||
IGridHost gh = (IGridHost) target;
|
||||
IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
|
||||
if (gn != null) {
|
||||
IGrid grid = gn.getGrid();
|
||||
if (grid != null && message.getRequireToCraftStack() != null) {
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
|
||||
IAEItemStack result = AEItemStack.create(message.getRequireToCraftStack());
|
||||
futureJob = cg.beginCraftingJob(player.worldObj, grid, baseContainer.getActionSource(), result, null);
|
||||
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
Platform.openGUI(player, te, baseContainer.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
|
||||
if (player.openContainer instanceof ContainerCraftConfirm) {
|
||||
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setAutoStart(message.isNoPreview());
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.vfyjxf.nee.proxy;
|
||||
|
||||
import com.github.vfyjxf.nee.NEECommands;
|
||||
import com.github.vfyjxf.nee.client.GuiHandler;
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
ClientCommandHandler.instance.registerCommand(new NEECommands());
|
||||
FMLCommonHandler.instance().bus().register(new GuiHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new GuiHandler());
|
||||
if (NEEConfig.noShift) {
|
||||
MinecraftForge.EVENT_BUS.register(new NEECraftingHelper());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.vfyjxf.nee.proxy;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
|
||||
public abstract class CommonProxy {
|
||||
|
||||
public abstract void init(FMLInitializationEvent event);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.github.vfyjxf.nee.proxy;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
|
||||
public class ServerProxy extends CommonProxy{
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.client.gui.implementations.GuiMEMonitorable;
|
||||
import appeng.client.me.ItemRepo;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IngredientTracker {
|
||||
|
||||
private List<IAEItemStack> craftbleAEItemStacks;
|
||||
private List<ItemStack> requireToCraftStacks = new ArrayList<>();
|
||||
|
||||
public IngredientTracker(GuiCraftingTerm gui) {
|
||||
this.craftbleAEItemStacks = getCraftableStacks(gui);
|
||||
}
|
||||
|
||||
|
||||
private List<IAEItemStack> getCraftableStacks(GuiCraftingTerm gui) {
|
||||
List<IAEItemStack> craftableAEItemSafcks = new ArrayList<>();
|
||||
ArrayList<IAEItemStack> view = null;
|
||||
try {
|
||||
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui);
|
||||
view = (ArrayList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "view").get(repo);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (view != null) {
|
||||
for (IAEItemStack stack : view) {
|
||||
if (stack.isCraftable()) {
|
||||
craftableAEItemSafcks.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return craftableAEItemSafcks;
|
||||
}
|
||||
|
||||
public boolean hasCraftableStack(ItemStack stack) {
|
||||
for (IAEItemStack aeItemStack : this.craftbleAEItemStacks) {
|
||||
if (aeItemStack.isSameType(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> getCraftbleAEItemStacks() {
|
||||
return this.craftbleAEItemStacks;
|
||||
}
|
||||
|
||||
public List<ItemStack> getRequireToCraftStacks() {
|
||||
return this.requireToCraftStacks;
|
||||
}
|
||||
|
||||
|
||||
public void addRequireToCraftStack(ItemStack requiredStack) {
|
||||
for (IAEItemStack craftableStack : this.getCraftbleAEItemStacks()) {
|
||||
if (craftableStack.isSameType(requiredStack)) {
|
||||
int requiredCount = (int) (requiredStack.stackSize - craftableStack.getStackSize());
|
||||
if (requiredCount > 0) {
|
||||
requiredStack.stackSize = requiredCount;
|
||||
this.requireToCraftStacks.add(requiredStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
nei.options.keys.nee=NotEnoughEnergistics
|
||||
nei.options.keys.nee.count=Change Item Count
|
||||
nei.options.keys.nee.ingredient=Choose ingredient
|
||||
nei.options.keys.nee.preview=Crafting Help
|
||||
nei.options.keys.nee.nopreview=Crafting Help(No Preview)
|
||||
Reference in new issue
Block a user