1.add nei drag for ae 2.allow use the ctrl + mouse wheel to change the amount of fake item in Interface

This commit is contained in:
vfyjxf committed 2021-11-13 02:55:04 +08:00
1 parent 4fa2a3df0f
commit 9963789272
9 files changed
+144 -35

No files matched your search

@@ -1,11 +1,15 @@
package com.github.vfyjxf.nee;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiInterface;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiPatternTermEx;
import codechicken.nei.NEIController;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import com.github.vfyjxf.nee.client.GuiHandler;
import com.github.vfyjxf.nee.client.NEEContainerDrawHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
@@ -13,18 +17,21 @@ 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 net.minecraft.client.gui.inventory.GuiContainer;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
import org.lwjgl.input.Keyboard;
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
public class NEINeeConfig implements IConfigureNEI {
private static final List<Class<?>> transferBlacklist = new ArrayList<>(Arrays.asList(
GuiInterface.class, GuiPatternTerm.class
));
@Override
public void loadConfig() {
@@ -32,6 +39,8 @@ public class NEINeeConfig implements IConfigureNEI {
registerKeyBindings();
registerGuiHandler();
if (NEEConfig.drawHighlight) {
GuiContainerManager.addDrawHandler(NEEContainerDrawHandler.instance);
}
@@ -78,6 +87,35 @@ public class NEINeeConfig implements IConfigureNEI {
API.addKeyBind("nee.nopreview", Keyboard.KEY_LMENU);
}
private void registerGuiHandler() {
API.registerNEIGuiHandler(GuiHandler.instance);
//disable MouseScrollTransfer in some gui
replaceNEIController();
}
private void replaceNEIController() {
int controllerIndex = -1;
for (IContainerInputHandler inputHandler : GuiContainerManager.inputHandlers) {
if (inputHandler instanceof NEIController) {
controllerIndex = GuiContainerManager.inputHandlers.indexOf(inputHandler);
break;
}
}
if (controllerIndex > 0) {
GuiContainerManager.inputHandlers.remove(controllerIndex);
GuiContainerManager.inputHandlers.add(controllerIndex, new NEIController() {
@Override
public boolean mouseScrolled(GuiContainer gui, int mouseX, int mouseY, int scrolled) {
if (transferBlacklist.contains(gui.getClass())) {
return false;
}
return super.mouseScrolled(gui, mouseX, mouseY, scrolled);
}
});
NotEnoughEnergistics.logger.info("NEIController replaced success");
}
}
private void installCraftingTermSupport() {
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting");
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting2x2");
@@ -1,16 +1,21 @@
package com.github.vfyjxf.nee.client;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiInterface;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotFake;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PositionedStack;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingHelper;
import com.github.vfyjxf.nee.network.packet.PacketRecipeItemChange;
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.ItemUtils;
@@ -28,9 +33,13 @@ import org.lwjgl.input.Mouse;
import java.util.ArrayList;
import java.util.List;
import static com.github.vfyjxf.nee.config.NEEConfig.draggedStackDefaultSize;
import static com.github.vfyjxf.nee.config.NEEConfig.useStackSizeFromNEI;
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*;
public class GuiHandler {
public class GuiHandler implements INEIGuiHandler {
public static GuiHandler instance = new GuiHandler();
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event) {
@@ -38,7 +47,8 @@ public class GuiHandler {
Minecraft mc = Minecraft.getMinecraft();
int dWheel = Mouse.getDWheel();
boolean isPatternTerm = mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen);
if (dWheel != 0 && isPatternTerm) {
boolean isInterface = mc.currentScreen instanceof GuiInterface;
if (dWheel != 0 && (isPatternTerm || isInterface)) {
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);
@@ -110,7 +120,7 @@ public class GuiHandler {
} else {
craftingSlots.add(currentSlot.slotNumber);
}
NEENetworkHandler.getInstance().sendToServer(new PacketRecipeItemChange(currentStack, craftingSlots));
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(currentStack, craftingSlots));
}
}
}
@@ -128,4 +138,41 @@ public class GuiHandler {
return craftingSlots;
}
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return null;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return null;
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
return null;
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (gui instanceof AEBaseGui) {
if (button != 2) {
Slot currentSlot = GuiUtils.getSlotUnderMouse(gui, mouseX, mouseY);
if (currentSlot instanceof SlotFake && ((SlotFake) currentSlot).isEnabled()) {
List<Integer> slots = new ArrayList<>();
slots.add(currentSlot.slotNumber);
ItemStack copyStack = draggedStack.copy();
copyStack.stackSize = useStackSizeFromNEI ? draggedStack.stackSize : draggedStackDefaultSize;
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(copyStack, slots));
return true;
}
}
}
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
}
}
@@ -5,7 +5,6 @@ import appeng.client.gui.implementations.GuiPatternTerm;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PositionedStack;
import codechicken.nei.guihook.IContainerDrawHandler;
import codechicken.nei.guihook.IContainerTooltipHandler;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
@@ -23,6 +23,9 @@ public class NEEConfig {
public static boolean matchOtherItems = true;
public static boolean drawHighlight = true;
public static boolean allowSynchronousSwitchIngredient = true;
public static boolean useStackSizeFromNEI = false;
public static int draggedStackDefaultSize = 1;
public static void loadConfig(File configFile) {
config = new Configuration(configFile);
@@ -50,6 +53,12 @@ public class NEEConfig {
allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);
useStackSizeFromNEI = config.get("client","useStackSizeFromNEI",false,
"Use the StackSize set by NEI").getBoolean();
draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
if (config.hasChanged()) config.save();
}
@@ -71,6 +80,12 @@ public class NEEConfig {
allowSynchronousSwitchIngredient = config.get("client", "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);
useStackSizeFromNEI = config.get("client","useStackSizeFromNEI",false,
"Use the StackSize set by NEI").getBoolean();
draggedStackDefaultSize = config.get("client", "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
ItemUtils.reloadConfig();
}
@@ -18,7 +18,7 @@ public class NEENetworkHandler {
INSTANCE.registerMessage(PacketArcaneRecipe.class, PacketArcaneRecipe.class, 1, Side.SERVER);
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(PacketSlotStackChange.class, PacketSlotStackChange.class, 4, Side.SERVER);
INSTANCE.registerMessage(PacketCraftingHelper.class, PacketCraftingHelper.class, 5, Side.SERVER);
}
@@ -1,7 +1,5 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.container.implementations.ContainerPatternTerm;
import com.github.vfyjxf.nee.utils.GuiUtils;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@@ -17,16 +15,16 @@ import java.util.List;
/**
* @author vfyjxf
*/
public class PacketRecipeItemChange implements IMessage, IMessageHandler<PacketRecipeItemChange, IMessage> {
public class PacketSlotStackChange implements IMessage, IMessageHandler<PacketSlotStackChange, IMessage> {
private ItemStack stack;
private List<Integer> craftingSlots;
public PacketRecipeItemChange() {
public PacketSlotStackChange() {
}
public PacketRecipeItemChange(ItemStack stack, List<Integer> craftingSlots) {
public PacketSlotStackChange(ItemStack stack, List<Integer> craftingSlots) {
this.stack = stack;
this.craftingSlots = craftingSlots;
}
@@ -60,13 +58,13 @@ public class PacketRecipeItemChange implements IMessage, IMessageHandler<PacketR
}
@Override
public IMessage onMessage(PacketRecipeItemChange message, MessageContext ctx) {
public IMessage onMessage(PacketSlotStackChange message, MessageContext ctx) {
Container container = ctx.getServerHandler().playerEntity.openContainer;
if (container instanceof ContainerPatternTerm || GuiUtils.isPatternTermExContainer(container)) {
ItemStack nextStack = message.getStack();
if (nextStack != null) {
for (Integer craftingSlot : message.getCraftingSlots()) {
Slot currentSlot = container.getSlot(craftingSlot);
ItemStack nextStack = message.getStack();
if (nextStack != null) {
for (Integer craftingSlot : message.getCraftingSlots()) {
Slot currentSlot = container.getSlot(craftingSlot);
if (currentSlot != null) {
currentSlot.putStack(nextStack);
}
}
@@ -1,7 +1,7 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerPatternTerm;
import com.github.vfyjxf.nee.utils.GuiUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -9,6 +9,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* @author vfyjxf
@@ -51,17 +52,28 @@ public class PacketStackCountChange implements IMessage, IMessageHandler<PacketS
public IMessage onMessage(PacketStackCountChange message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if ((container instanceof ContainerPatternTerm && !((ContainerPatternTerm) container).isCraftingMode()) || GuiUtils.isPatternTermExContainer(container)) {
Slot currentSlot = container.getSlot(message.getSlotIndex());
for (int i = 0; i < Math.abs(message.getChangeCount()); i++) {
int currentStackSize = message.getChangeCount() > 0 ? currentSlot.getStack().stackSize + 1 : currentSlot.getStack().stackSize - 1;
if (currentStackSize <= currentSlot.getStack().getMaxStackSize() && currentStackSize > 0) {
currentSlot.getStack().stackSize = currentStackSize;
} else {
break;
}
}
if (container instanceof AEBaseContainer) {
handleMessage(message, container);
}
return null;
}
private void handleMessage(PacketStackCountChange message, Container container) {
if (container instanceof ContainerPatternTerm && ((ContainerPatternTerm) container).isCraftingMode()) {
return;
}
Slot currentSlot = container.getSlot(message.getSlotIndex());
for (int i = 0; i < Math.abs(message.getChangeCount()); i++) {
int currentStackSize = message.getChangeCount() > 0 ? currentSlot.getStack().stackSize + 1 : currentSlot.getStack().stackSize - 1;
if (currentStackSize <= currentSlot.getStack().getMaxStackSize() && currentStackSize > 0) {
ItemStack nextStack = currentSlot.getStack().copy();
nextStack.stackSize = currentStackSize;
currentSlot.putStack(nextStack);
} else {
break;
}
}
}
}
@@ -15,12 +15,12 @@ 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());
FMLCommonHandler.instance().bus().register(GuiHandler.instance);
MinecraftForge.EVENT_BUS.register(GuiHandler.instance);
if (NEEConfig.noShift) {
MinecraftForge.EVENT_BUS.register(NEECraftingHelper.INSTANCE);
}
if(NEEConfig.drawHighlight){
if (NEEConfig.drawHighlight) {
MinecraftForge.EVENT_BUS.register(NEEContainerDrawHandler.instance);
}
}