This commit is contained in:
vfyjxf committed 2021-10-02 01:33:50 +08:00
1 parent 0bed08ffcd
commit f58898df06
5 files changed
+37 -15

No files matched your search

@@ -85,6 +85,7 @@ public class NEECommands extends CommandBase {
newList.add(modid);
NEEConfig.config.getCategory("client").get("transformPriorityModList").set(newList.toArray(new String[0]));
NEEConfig.config.save();
NEEConfig.reload();
}
}
} else if ("reload".equalsIgnoreCase(args[0])) {
@@ -1,28 +1,17 @@
package com.github.vfyjxf.nee;
import appeng.client.gui.implementations.GuiPatternTerm;
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;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.client.ClientCommandHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Mouse;
import java.io.File;
@@ -51,7 +51,7 @@ public class NEECraftingHelper implements IOverlayHandler {
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);
tracker = createTracker((GuiCraftingTerm) firstGui, (ContainerCraftingTerm) container, recipe, recipeIndex);
if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview"))) {
if (!tracker.getRequireToCraftStacks().isEmpty()) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingHelper(tracker.getRequireToCraftStacks().get(0), false));
@@ -83,7 +83,7 @@ public class NEECraftingHelper implements IOverlayHandler {
}
}
private IngredientTracker createTracker(GuiCraftingTerm firstGui, IRecipeHandler recipe, int recipeIndex) {
private IngredientTracker createTracker(GuiCraftingTerm firstGui, ContainerCraftingTerm container, IRecipeHandler recipe, int recipeIndex) {
IngredientTracker tracker = new IngredientTracker(firstGui);
List<PositionedStack> requiredIngredient = new ArrayList<>();
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
@@ -105,8 +105,15 @@ public class NEECraftingHelper implements IOverlayHandler {
for (ItemStack currentStack : currentIngredient.items) {
if (tracker.hasCraftableStack(currentStack)) {
ItemStack requiredStack = currentStack.copy();
for (ItemStack stack : GuiUtils.getStacksFromCraftingTerminal(container)) {
if (stack.isItemEqual(requiredStack) && ItemStack.areItemStackTagsEqual(stack, requiredStack)) {
currentIngredient.items[0].stackSize -= stack.stackSize;
}
}
requiredStack.stackSize = currentIngredient.items[0].stackSize;
tracker.addRequireToCraftStack(requiredStack);
if (requiredStack.stackSize > 0) {
tracker.addRequireToCraftStack(requiredStack);
}
break;
}
}
@@ -1,6 +1,7 @@
package com.github.vfyjxf.nee.utils;
import appeng.client.gui.AEBaseGui;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.helpers.IContainerCraftingPacket;
import codechicken.nei.PositionedStack;
@@ -19,6 +20,8 @@ import net.minecraft.nbt.NBTTagCompound;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* @author vfyjxf
@@ -64,6 +67,28 @@ public class GuiUtils {
return false;
}
public static List<ItemStack> getStacksFromCraftingTerminal(ContainerCraftingTerm container) {
List<ItemStack> stacks = new ArrayList<>();
IInventory craftingGrid = container.getInventoryByName("crafting");
for (int i = 0; i < craftingGrid.getSizeInventory(); i++) {
ItemStack currentStack = craftingGrid.getStackInSlot(i);
boolean find = false;
if (currentStack != null) {
for (ItemStack stack : stacks) {
boolean isStackEqual = stack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(stack, currentStack);
if (isStackEqual && stack.stackSize + currentStack.stackSize <= stack.getMaxStackSize()) {
stack.stackSize = stack.stackSize + currentStack.stackSize;
find = true;
}
}
}
if (!find && currentStack != null) {
stacks.add(currentStack.copy());
}
}
return stacks;
}
public static void handleRecipeIngredientChange(Slot currentSlot, int dWheel) {
PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlot.getSlotIndex());