This commit is contained in:
vfyjxf committed 2021-10-31 02:56:09 +08:00
1 parent 02b51a24c1
commit f69a663fce
9 files changed
+137 -74

No files matched your search

@@ -13,6 +13,7 @@ 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 cpw.mods.fml.common.Optional;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
import org.lwjgl.input.Keyboard;
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
@@ -32,6 +33,10 @@ public class NEINeeConfig implements IConfigureNEI {
registerKeyBindings();
if (NEEConfig.drawHighlight) {
GuiContainerManager.addDrawHandler(NEEContainerDrawHandler.instance);
}
Set<String> defaultIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
);
@@ -46,10 +51,6 @@ public class NEINeeConfig implements IConfigureNEI {
API.registerGuiOverlayHandler(GuiPatternTerm.class, new NEECraftingHandler(), ident);
}
if (NEEConfig.drawHighlight) {
GuiContainerManager.addDrawHandler(NEEContainerDrawHandler.instance);
}
installCraftingTermSupport();
installWirelessCraftingTermSupport();
@@ -81,14 +82,14 @@ public class NEINeeConfig implements IConfigureNEI {
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");
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingHelper.INSTANCE, "crafting");
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingHelper.INSTANCE, "crafting2x2");
}
private void installWirelessCraftingTermSupport() {
if (Loader.isModLoaded("ae2wct")) {
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, new NEECraftingHelper(), "crafting");
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, new NEECraftingHelper(), "crafting2x2");
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, NEECraftingHelper.INSTANCE, "crafting");
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, NEECraftingHelper.INSTANCE, "crafting2x2");
}
}
@@ -26,7 +26,7 @@ public class NotEnoughEnergistics {
public static final String MODID = "neenergistics";
public static final String NAME = "NotEnoughEnergistics";
public static final String VERSION = "@VERSION@";
public static final String DEPENDENCIES = "required-after:NotEnoughItems;required-after:appliedenergistics2";
public static final String DEPENDENCIES = "required-after:NotEnoughItems;required-after:appliedenergistics2;after:ae2wct";
public static final String GUI_FACTORY = "com.github.vfyjxf.nee.config.NEEConfigGuiFactory";
public static final Logger logger = LogManager.getLogger("NotEnoughEnergistics");
@@ -37,6 +37,8 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
private final Field overlayButtonsField;
private final Field handlerField;
private Method recipesPerPageMethod;
private boolean drawRequestTooltip;
private boolean drawCraftableTooltip;
public NEEContainerDrawHandler() {
this.overlayButtonsField = ReflectionHelper.findField(GuiRecipe.class, "overlayButtons");
@@ -116,6 +118,8 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB());
this.drawCraftableTooltip = renderCraftableItems;
this.drawRequestTooltip = renderAutoAbleItems;
} else if (renderMissingItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
@@ -133,33 +137,38 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
@SubscribeEvent
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
if (event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
GuiButton[] overlayButtons = null;
try {
overlayButtons = (GuiButton[]) ReflectionHelper.findField(GuiRecipe.class, "overlayButtons").get(guiRecipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (overlayButtons != null) {
for (GuiButton button : overlayButtons) {
if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, event.mouseX, event.mouseY)) {
drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY);
if (this.drawCraftableTooltip || this.drawRequestTooltip) {
if (event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
GuiButton[] overlayButtons = null;
try {
overlayButtons = (GuiButton[]) ReflectionHelper.findField(GuiRecipe.class, "overlayButtons").get(guiRecipe);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
if (overlayButtons != null) {
for (GuiButton button : overlayButtons) {
if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button, event.mouseX, event.mouseY)) {
drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY);
this.drawCraftableTooltip = false;
this.drawRequestTooltip = false;
}
}
}
}
}
}
private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) {
List<String> tooltips = new ArrayList<>();
if (guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui)) {
boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui);
if (this.drawRequestTooltip && isCraftingTerm) {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
}
if (guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui)) {
boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui);
if (this.drawCraftableTooltip && isPatternTerm) {
tooltips.add(EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.pattern"));
}
try {
@@ -2,10 +2,10 @@ 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.AppEngPacket;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.util.Platform;
@@ -15,16 +15,19 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.config.NEEConfig;
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.Optional;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
import io.netty.buffer.ByteBuf;
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;
@@ -46,6 +49,8 @@ public class NEECraftingHelper implements IOverlayHandler {
public static int stackIndex = 1;
public static boolean noPreview = false;
public static final NEECraftingHelper INSTANCE = new NEECraftingHelper();
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
boolean isCraftingGuiTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui);
@@ -85,13 +90,19 @@ public class NEECraftingHelper implements IOverlayHandler {
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
if (firstGui instanceof GuiCraftingTerm) {
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false));
if (packet.size() >= 32 * 1024) {
//don't use gtnh ae2's method;
int packetSize = getPacketSize(packet);
if (packetSize >= 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);
if (packetSize >= 0) {
NetworkHandler.instance.sendToServer(packet);
}else {
NotEnoughEnergistics.logger.error("Can't get packet size!");
}
} else if (GuiUtils.isGuiWirelessCrafting(firstGui)) {
net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer(new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe(packIngredients(firstGui, ingredients, false)));
moveItemsForWirelessCrafting(firstGui, ingredients);
}
} catch (final Exception | Error ignored) {
}
@@ -164,36 +175,56 @@ public class NEECraftingHelper implements IOverlayHandler {
return false;
}
private int getPacketSize(AppEngPacket packet) {
try {
ByteBuf p = (ByteBuf) ReflectionHelper.findField(AppEngPacket.class, "p").get(packet);
return p.array().length;
} catch (IllegalAccessException e) {
return -1;
}
}
@Optional.Method(modid = "ae2wct")
private void moveItemsForWirelessCrafting(GuiContainer firstGui, List<PositionedStack> ingredients) {
try {
net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer(new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketNEIRecipe(packIngredients(firstGui, ingredients, false)));
} catch (IOException e) {
e.printStackTrace();
}
}
@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) {
boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui);
boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui);
if (isCraftingTerm || isPatternTerm) {
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);
if (NEEConfig.noShift) {
//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) {
boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui);
boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui);
if (isCraftingTerm || isPatternTerm) {
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);
}
}
}
}
@@ -18,7 +18,7 @@ public class ClientProxy extends CommonProxy {
FMLCommonHandler.instance().bus().register(new GuiHandler());
MinecraftForge.EVENT_BUS.register(new GuiHandler());
if (NEEConfig.noShift) {
MinecraftForge.EVENT_BUS.register(new NEECraftingHelper());
MinecraftForge.EVENT_BUS.register(NEECraftingHelper.INSTANCE);
}
if(NEEConfig.drawHighlight){
MinecraftForge.EVENT_BUS.register(NEEContainerDrawHandler.instance);
@@ -1,6 +1,5 @@
package com.github.vfyjxf.nee.utils;
import appeng.api.AEApi;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.implementations.GuiMEMonitorable;
@@ -18,11 +17,10 @@ import java.util.List;
public class IngredientTracker {
private List<IAEItemStack> craftbleAEItemStacks;
private List<Ingredient> ingredients = new ArrayList<>();
private final List<Ingredient> ingredients = new ArrayList<>();
public IngredientTracker(GuiContainer gui, IRecipeHandler recipe, int recipeIndex) {
this.craftbleAEItemStacks = getCraftableStacks(gui);
List<IAEItemStack> craftableStacks = getCraftableStacks(gui);
List<PositionedStack> requiredIngredients = new ArrayList<>();
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
boolean find = false;
@@ -43,7 +41,7 @@ public class IngredientTracker {
Ingredient ingredient = new Ingredient(requiredIngredient);
ingredients.add(ingredient);
for (IAEItemStack stack : NEEConfig.matchOtherItems ? this.getStorageStacks(gui) : craftbleAEItemStacks) {
for (IAEItemStack stack : NEEConfig.matchOtherItems ? this.getStorageStacks(gui) : craftableStacks) {
if (requiredIngredient.contains(stack.getItemStack())) {
if (stack.isCraftable()) {
ingredient.setCraftableIngredient(stack.getItemStack());
@@ -55,32 +53,56 @@ public class IngredientTracker {
}
public IngredientTracker(GuiContainer gui, List<PositionedStack> requiredIngredients) {
IItemList<IAEItemStack> aeItemStacks = this.getStorageStacks(gui);
for (PositionedStack positionedStack : requiredIngredients) {
this.ingredients.add(new Ingredient(positionedStack));
}
List<IAEItemStack> craftableStacks = this.getCraftableStacks(gui);
//set craftable stack
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : aeItemStacks) {
for (IAEItemStack stack : craftableStacks) {
if (ingredient.getIngredients().contains(stack.getItemStack())) {
if (ingredient.getCraftableIngredient() == null && stack.isCraftable()) {
if (!ingredient.isCraftable()) {
ingredient.setCraftableIngredient(stack.getItemStack());
}
if (stack.getStackSize() > 0) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount());
stack.setStackSize(stack.getStackSize() - missingCount);
}
}
}
}
}
if (NEEConfig.matchOtherItems) {
List<IAEItemStack> otherStacks = this.getStorageStacks(gui);
otherStacks.removeAll(craftableStacks);
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : otherStacks) {
if (ingredient.requiresToCraft() && ingredient.getIngredients().contains(stack.getItemStack())) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - missingCount);
}
}
}
}
}
}
@SuppressWarnings("unchecked")
private List<IAEItemStack> getCraftableStacks(GuiContainer gui) {
List<IAEItemStack> craftableAEItemSafcks = new ArrayList<>();
List<IAEItemStack> craftableStacks = new ArrayList<>();
IItemList<IAEItemStack> list = null;
try {
if (!GuiUtils.isGuiWirelessCrafting(gui)) {
@@ -98,16 +120,16 @@ public class IngredientTracker {
if (list != null) {
for (IAEItemStack stack : list) {
if (stack.isCraftable()) {
craftableAEItemSafcks.add(stack.copy());
craftableStacks.add(stack.copy());
}
}
}
return craftableAEItemSafcks;
return craftableStacks;
}
@SuppressWarnings("unchecked")
private IItemList<IAEItemStack> getStorageStacks(GuiContainer gui) {
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
private List<IAEItemStack> getStorageStacks(GuiContainer gui) {
List<IAEItemStack> list = new ArrayList<>();
try {
if (!GuiUtils.isGuiWirelessCrafting(gui)) {
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(gui);
@@ -149,7 +171,7 @@ public class IngredientTracker {
for (Ingredient ingredient : this.ingredients) {
if (ingredient.requiresToCraft()) {
if (NEEConfig.matchOtherItems) {
if (stack.stackSize > 0 && ingredient.getIngredients().contains(stack) && ItemStack.areItemStackTagsEqual(ingredient.getCraftableIngredient(), stack)) {
if (stack.stackSize > 0 && ingredient.getIngredients().contains(stack)) {
int missingCount = (int) ingredient.getMissingCount();
ingredient.addCurrentCount(stack.stackSize);
if (ingredient.requiresToCraft()) {