mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-19 03:39:07 +00:00
Add the function of mouse wheel to switch materials
This commit is contained in:
1 parent
30df907002
commit
5dc0c6d338
12 files changed
+159
-40
No files matched your search
@@ -11,7 +11,9 @@ import cpw.mods.fml.common.Loader;
|
||||
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
|
||||
import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class NEINeeConfig implements IConfigureNEI {
|
||||
|
||||
@@ -58,14 +58,19 @@ public class NotEnoughEnergistics {
|
||||
public void onRenderTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.START) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
int i = Mouse.getDWheel();
|
||||
if (i != 0 && mc.currentScreen instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(mc.currentScreen)) {
|
||||
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()) {
|
||||
int changeCount = GuiContainer.isCtrlKeyDown() ? i / 60 : i / 120;
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount));
|
||||
//try to change current itemstack to next ingredient;
|
||||
if (GuiContainer.isShiftKeyDown() && GuiUtils.isCraftingSlot(currentSlot)) {
|
||||
GuiUtils.handleRecipeIngredientChange(currentSlot, dWheel);
|
||||
} else {
|
||||
int changeCount = GuiContainer.isCtrlKeyDown() ? dWheel / 60 : dWheel / 120;
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketStackCountChange(currentSlot.slotNumber, changeCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.client.gui.implementations.GuiPatternTermEx;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import appeng.util.Platform;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
|
||||
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
|
||||
import com.github.vfyjxf.nee.processor.RecipeProcessor;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
@@ -27,10 +29,11 @@ import java.util.List;
|
||||
public class NEECraftingHandler implements IOverlayHandler {
|
||||
|
||||
public static final String OUTPUT_KEY = "Outputs";
|
||||
public static Map<String, PositionedStack> ingredients = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if (firstGui instanceof GuiPatternTerm || (hasPatternTermExClz() && firstGui instanceof GuiPatternTermEx)) {
|
||||
if (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
|
||||
} else {
|
||||
knowledgeInscriberHandler(firstGui, recipe, recipeIndex);
|
||||
@@ -95,6 +98,7 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
continue;
|
||||
}
|
||||
recipeInputs.setTag("#" + inputIndex, currentStack.writeToNBT(new NBTTagCompound()));
|
||||
NEECraftingHandler.ingredients.put("input" + inputIndex, positionedStack);
|
||||
inputIndex++;
|
||||
}
|
||||
|
||||
@@ -133,6 +137,7 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
}
|
||||
|
||||
recipeInputs.setTag("#" + slotIndex, stack.writeToNBT(new NBTTagCompound()));
|
||||
NEECraftingHandler.ingredients.put("input" + slotIndex, positionedStack);
|
||||
}
|
||||
}
|
||||
return new PacketNEIPatternRecipe(recipeInputs, null);
|
||||
@@ -249,13 +254,4 @@ public class NEECraftingHandler implements IOverlayHandler {
|
||||
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
|
||||
}
|
||||
|
||||
private boolean hasPatternTermExClz() {
|
||||
try {
|
||||
Class.forName("appeng.client.gui.implementations.GuiPatternTermEx");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.github.vfyjxf.nee.network;
|
||||
|
||||
import com.github.vfyjxf.nee.NotEnoughEnergistics;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
|
||||
import com.github.vfyjxf.nee.network.packet.*;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
@@ -21,6 +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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,10 +17,11 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
|
||||
|
||||
public class PacketNEIPatternRecipe implements IMessage, IMessageHandler<PacketNEIPatternRecipe, IMessage> {
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class PacketRecipeItemChange implements IMessage, IMessageHandler<PacketRecipeItemChange,IMessage> {
|
||||
|
||||
private NBTTagCompound stack;
|
||||
private int slotNumber;
|
||||
|
||||
public PacketRecipeItemChange(){
|
||||
|
||||
}
|
||||
|
||||
public PacketRecipeItemChange(NBTTagCompound stack, int slotNumber) {
|
||||
this.stack = stack;
|
||||
this.slotNumber = slotNumber;
|
||||
}
|
||||
|
||||
public NBTTagCompound getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getSlotNumber() {
|
||||
return slotNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.stack = ByteBufUtils.readTag(buf);
|
||||
this.slotNumber = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf,this.stack);
|
||||
buf.writeInt(this.slotNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketRecipeItemChange message, MessageContext ctx) {
|
||||
Container container = ctx.getServerHandler().playerEntity.openContainer;
|
||||
if(container instanceof ContainerPatternTerm || GuiUtils.isPatternTermExContainer(container)){
|
||||
Slot currentSlot = container.getSlot(message.getSlotNumber());
|
||||
ItemStack nextStack = ItemStack.loadItemStackFromNBT(message.getStack());
|
||||
if(nextStack != null){
|
||||
currentSlot.putStack(nextStack);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -54,18 +54,11 @@ public class PacketStackCountChange implements IMessage, IMessageHandler<PacketS
|
||||
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++) {
|
||||
if (message.getChangeCount() > 0) {
|
||||
if (currentSlot.getStack().stackSize >= currentSlot.getStack().getMaxStackSize()) {
|
||||
break;
|
||||
}
|
||||
currentSlot.getStack().stackSize = (currentSlot.getStack().stackSize + 1);
|
||||
} else {
|
||||
if (currentSlot.getStack().stackSize - 1 <= 0) {
|
||||
break;
|
||||
}
|
||||
currentSlot.getStack().stackSize = currentSlot.getStack().stackSize - 1;
|
||||
int currentStackSize = message.getChangeCount() > 0 ? currentSlot.getStack().stackSize + 1 : currentSlot.getStack().stackSize - 1;
|
||||
if (currentSlot.getStack().stackSize >= currentSlot.getStack().getMaxStackSize() || currentSlot.getStack().stackSize - 1 <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
currentSlot.getStack().stackSize = currentStackSize;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketRecipeItemChange;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -14,6 +25,7 @@ import java.lang.reflect.Method;
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class GuiUtils {
|
||||
|
||||
public static Slot getSlotUnderMouse(GuiContainer guiContainer, int mouseX, int mouseY) {
|
||||
Method getSlotMethod = ReflectionHelper.findMethod(AEBaseGui.class, (AEBaseGui) guiContainer, new String[]{"getSlot"}, int.class, int.class);
|
||||
try {
|
||||
@@ -34,7 +46,7 @@ public class GuiUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPatternTermExContainer(Container container){
|
||||
public static boolean isPatternTermExContainer(Container container) {
|
||||
try {
|
||||
Class<?> patternTermExClz = Class.forName("appeng.container.implementations.ContainerPatternTermEx");
|
||||
return patternTermExClz.isInstance(container);
|
||||
@@ -43,4 +55,37 @@ public class GuiUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCraftingSlot(Slot slot) {
|
||||
Container container = Minecraft.getMinecraft().thePlayer.openContainer;
|
||||
if (container instanceof ContainerPatternTerm || GuiUtils.isPatternTermExContainer(container)) {
|
||||
IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
|
||||
IInventory craftMatrix = cct.getInventoryByName("crafting");
|
||||
return slot.inventory.equals(craftMatrix);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void handleRecipeIngredientChange(Slot currentSlot, int dWheel) {
|
||||
|
||||
PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlot.getSlotIndex());
|
||||
if (currentIngredients != null && currentIngredients.items.length > 1) {
|
||||
int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients);
|
||||
if (currentStackIndex >= 0) {
|
||||
int nextStackIndex = dWheel / 120;
|
||||
for (int i = 0; i < Math.abs(nextStackIndex); i++) {
|
||||
currentStackIndex = nextStackIndex > 0 ? currentStackIndex + 1 : currentStackIndex - 1;
|
||||
if (currentStackIndex >= currentIngredients.items.length) {
|
||||
currentStackIndex = 0;
|
||||
} else if (currentStackIndex < 0) {
|
||||
currentStackIndex = currentIngredients.items.length - 1;
|
||||
}
|
||||
ItemStack currentStack = currentIngredients.items[currentStackIndex].copy();
|
||||
currentStack.stackSize = currentSlot.getStack().stackSize;
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketRecipeItemChange(currentStack.writeToNBT(new NBTTagCompound()), currentSlot.slotNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import com.github.vfyjxf.nee.NotEnoughEnergistics;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
@@ -10,7 +11,6 @@ import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -88,7 +88,6 @@ public final class ItemUtils {
|
||||
return transformItemPriorityList;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isPreferItems(ItemStack itemStack, String recipeProcessor, String identifier) {
|
||||
for (StackProcessor processor : ItemUtils.transformItemPriorityList) {
|
||||
ItemStack copyStack = itemStack.copy();
|
||||
@@ -149,4 +148,18 @@ public final class ItemUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getIngredientIndex(ItemStack stack, PositionedStack positionedStack){
|
||||
ItemStack stackInput = stack.copy();
|
||||
stackInput.stackSize = 1;
|
||||
for(int i = 0; i < positionedStack.items.length; i++){
|
||||
ItemStack currentStack = positionedStack.items[i].copy();
|
||||
currentStack.stackSize = 1;
|
||||
if(ItemStack.areItemStacksEqual(currentStack,stackInput)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user