diff --git a/README.md b/README.md index ca0b8da..9dbff4f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/READNE_CN.md b/READNE_CN.md index 8e2727d..d7ef68b 100644 --- a/READNE_CN.md +++ b/READNE_CN.md @@ -18,7 +18,7 @@ NotEnoughEnergistics 是[Just Enough Energistics](https://www.curseforge.com/min - 支持增广样板终端(16 -> 4模式) - 允许你设置转换黑名单和转换优先名单,如对应物品在里面,那么他们将不会被转移/优先被转移 - 允许你设置mod优先级列表,优先使用该mod的物品 -- 你可以使用鼠标滚轮来修改样板的输入/输出数量 +- 你可以使用ctrl + 鼠标滚轮来修改样板的输入/输出数量 - 你可以使用shift + 鼠标滚轮来选择材料 ## 当前支持的Mod列表: diff --git a/gradle.properties b/gradle.properties index cdf20c1..8551064 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/github/vfyjxf/nee/NEECommands.java b/src/main/java/com/github/vfyjxf/nee/NEECommands.java index 0d834a2..313773e 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEECommands.java +++ b/src/main/java/com/github/vfyjxf/nee/NEECommands.java @@ -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); diff --git a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java index 932b18c..1b18b18 100644 --- a/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/NEINeeConfig.java @@ -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 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"); diff --git a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java index 8edadc7..37241e6 100644 --- a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java +++ b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java @@ -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); } } diff --git a/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java b/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java new file mode 100644 index 0000000..255a668 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/client/GuiHandler.java @@ -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++; + } + } + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java index 0dc407d..7dd4ffd 100644 --- a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java @@ -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(); diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java index fb31ff5..162ccb3 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -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); diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java new file mode 100644 index 0000000..3f5f238 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java @@ -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 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 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 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) gui.inventorySlots.inventorySlots) { + if (slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix) { + if (slot.getSlotIndex() == col + row * 3) { + final NBTTagList tags = new NBTTagList(); + final List 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); + } + } + } + } + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java index 1457f8b..847fdac 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java @@ -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); } } \ No newline at end of file diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingHelper.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingHelper.java new file mode 100644 index 0000000..444e71c --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingHelper.java @@ -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 { + + + 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 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; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java new file mode 100644 index 0000000..3f31e2d --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/proxy/ClientProxy.java @@ -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()); + } + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java b/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java new file mode 100644 index 0000000..2d205e8 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java @@ -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); + +} diff --git a/src/main/java/com/github/vfyjxf/nee/proxy/ServerProxy.java b/src/main/java/com/github/vfyjxf/nee/proxy/ServerProxy.java new file mode 100644 index 0000000..5ee77ea --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/proxy/ServerProxy.java @@ -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 + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java new file mode 100644 index 0000000..da2e3e4 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java @@ -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 craftbleAEItemStacks; + private List requireToCraftStacks = new ArrayList<>(); + + public IngredientTracker(GuiCraftingTerm gui) { + this.craftbleAEItemStacks = getCraftableStacks(gui); + } + + + private List getCraftableStacks(GuiCraftingTerm gui) { + List craftableAEItemSafcks = new ArrayList<>(); + ArrayList view = null; + try { + ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui); + view = (ArrayList) 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 getCraftbleAEItemStacks() { + return this.craftbleAEItemStacks; + } + + public List 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); + } + } + } + } + +} diff --git a/src/main/resources/assets/neenergistics/lang/en_US.lang b/src/main/resources/assets/neenergistics/lang/en_US.lang new file mode 100644 index 0000000..0a43805 --- /dev/null +++ b/src/main/resources/assets/neenergistics/lang/en_US.lang @@ -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) \ No newline at end of file