cherry pick fix tooltip problem

This commit is contained in:
vfyjxf authored and Martin Robertz committed 2022-02-07 19:03:43 +01:00
1 parent ed66abebd5
commit 15a6344ba2
20 files changed
+323 -258

No files matched your search

+2 -1
View File
@@ -3,6 +3,8 @@ dependencies {
compile("com.github.GTNewHorizons:CodeChickenLib:1.1.5.3:dev")
compile("com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev")
compile("com.github.GTNewHorizons:NotEnoughItems:2.2.5-GTNH:dev")
compile("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.3:dev")
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.5.3-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.9:dev") { transitive = false }
@@ -11,7 +13,6 @@ dependencies {
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.40.31:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTplusplus:1.7.27:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.3.16-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.3:dev") { transitive = false }
compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") { transitive = false }
compileOnly("curse.maven:thaumcraft-nei-plugin-225095:2241913") { transitive = false }
compileOnly("curse.maven:thermal-expansion-69163:2388759") { transitive = false }
@@ -41,10 +41,6 @@ public class NEINeeConfig implements IConfigureNEI {
registerGuiHandler();
if (NEEConfig.drawHighlight) {
GuiContainerManager.addDrawHandler(NEEContainerDrawHandler.instance);
}
Set<String> defaultIdentifiers = new HashSet<>(
Arrays.asList("crafting", "crafting2x2", "brewing", "smelting", "fuel", null)
);
@@ -96,9 +96,9 @@ public class NEEClassTransformer implements IClassTransformer {
for (MethodNode methodNode : classNode.methods) {
if (TARGET_METHOD_MAPPING.matches(methodNode)) {
NotEnoughEnergistics.logger.info("Transforming : " + internalName + methodNode.name + methodNode.desc);
AbstractInsnNode aLoad = methodNode.instructions.getLast().getPrevious();
while (aLoad.getOpcode() != ALOAD) {
aLoad = aLoad.getPrevious();
AbstractInsnNode aLoad = methodNode.instructions.getFirst();
while (aLoad.getOpcode() != ILOAD) {
aLoad = aLoad.getNext();
}
InsnList insnList = new InsnList();
insnList.add(new VarInsnNode(ILOAD, 1));
@@ -9,7 +9,6 @@ import com.github.vfyjxf.nee.network.NEEGuiHandler;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -37,12 +36,12 @@ public class BlockPatternInterface extends AEBaseTileBlock {
return false;
}
if (!world.isRemote) {
TilePatternInterface tile = this.getTileEntity(world,x, y, z);
if (tile != null) {
TilePatternInterface tile = this.getTileEntity(world, x, y, z);
if (tile != null) {
if (!world.isRemote) {
NEEGuiHandler.openGui(player, NEEGuiHandler.PATTERN_INTERFACE_ID, tile, ForgeDirection.UNKNOWN);
return true;
}
return true;
}
return false;
@@ -1,32 +1,43 @@
package com.github.vfyjxf.nee.client;
import appeng.client.gui.AEBaseGui;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.container.implementations.ContainerPatternTerm;
import appeng.container.slot.SlotFake;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import com.github.vfyjxf.nee.client.gui.widgets.GuiImgButtonEnableCombination;
import com.github.vfyjxf.nee.config.ItemCombination;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.client.gui.widgets.GuiImgButtonEnableCombination;
import com.github.vfyjxf.nee.container.ContainerCraftingConfirm;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.ModIDs;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import org.lwjgl.input.Mouse;
import java.util.ArrayList;
import java.util.Collections;
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.tracker;
public class GuiEventHandler implements INEIGuiHandler {
@@ -35,6 +46,63 @@ public class GuiEventHandler implements INEIGuiHandler {
private GuiImgButtonEnableCombination buttonCombination;
private boolean hasDoubleBtn = true;
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
GuiScreen old = Minecraft.getMinecraft().currentScreen;
GuiScreen next = event.gui;
if (old != null) {
if (GuiUtils.isGuiCraftConfirm(old) && isContainerCraftConfirm(((GuiContainer) old).inventorySlots)) {
if (tracker != null) {
if (GuiUtils.isGuiCraftingTerm(next)) {
if (tracker.hasNext()) {
tracker.requestNextIngredient();
} else {
tracker = null;
}
} else {
if (tracker != null) {
tracker = null;
}
}
}
}
}
}
@SubscribeEvent
public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Post event) {
if (tracker != null) {
if (event.gui instanceof GuiCraftConfirm) {
if (getCancelButton((GuiCraftConfirm) event.gui) == event.button) {
tracker = null;
}
}
if (GuiUtils.isWirelessGuiCraftConfirm(event.gui)) {
assert event.gui instanceof net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
if (getCancelButton((net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm) event.gui) == event.button) {
tracker = null;
}
}
}
}
private GuiButton getCancelButton(GuiCraftConfirm gui) {
return ObfuscationReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel");
}
@Optional.Method(modid = ModIDs.WCT)
private GuiButton getCancelButton(net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm gui) {
return ObfuscationReflectionHelper.getPrivateValue(net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm.class, gui, "cancel");
}
private boolean isContainerCraftConfirm(Container container) {
return (container instanceof ContainerCraftConfirm || GuiUtils.isContainerWirelessCraftingConfirm(container)) &&
!((container instanceof ContainerCraftingConfirm) || (GuiUtils.isWCTContainerCraftingConfirm(container)));
}
@SuppressWarnings("unchecked")
@SubscribeEvent
public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) {
@@ -86,17 +154,6 @@ public class GuiEventHandler implements INEIGuiHandler {
}
}
@SuppressWarnings("unchecked")
private List<Slot> getCraftingSlots(GuiContainer gui) {
List<Slot> craftingSlots = new ArrayList<>();
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
if (GuiUtils.isCraftingSlot(slot)) {
craftingSlots.add(slot);
}
}
return craftingSlots;
}
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
return null;
@@ -115,7 +172,7 @@ public class GuiEventHandler implements INEIGuiHandler {
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
//When NEIAddons exist, give them to NEIAddons to handle
if(Loader.isModLoaded("NEIAddons") && NEEConfig.useNEIDragFromNEIAddons){
if (Loader.isModLoaded("NEIAddons") && NEEConfig.useNEIDragFromNEIAddons) {
return false;
}
@@ -1,20 +1,18 @@
package com.github.vfyjxf.nee.client;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.guihook.IContainerDrawHandler;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.Ingredient;
import com.github.vfyjxf.nee.utils.IngredientTracker;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Slot;
import net.minecraft.util.EnumChatFormatting;
@@ -31,15 +29,20 @@ import java.util.*;
/**
* Please note the difference between the GTNH NEI and the official NEI
*/
public class NEEContainerDrawHandler implements IContainerDrawHandler {
public class NEEContainerDrawHandler {
public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler();
public static final Map<String, IngredientTracker> trackerMap = new HashMap<>();
public static boolean isGtnhNei;
private static final Color craftableColor = new Color(0.0f, 0.0f, 1.0f, 0.4f);
private static final Color missingColor = new Color(1.0f, 0.0f, 0.0f, 0.4f);
public boolean isGtnhNei;
private final List<GuiButton> overlayButtons = new ArrayList<>();
private final Map<Integer, IngredientTracker> trackerMap = new HashMap<>();
private boolean isCraftingTerm;
private boolean isPatternTerm;
private int oldPage;
private int oldType;
public Field overlayButtonsField;
public Method recipesPerPageMethod;
@@ -60,166 +63,178 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler {
}
}
@Override
public void onPreDraw(GuiContainer gui) {
@SubscribeEvent
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
if (NEEConfig.drawHighlight && event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
this.isCraftingTerm = GuiUtils.isGuiCraftingTerm(guiRecipe.firstGui);
this.isPatternTerm = GuiUtils.isPatternTerm(guiRecipe.firstGui);
}
@Override
public void renderObjects(GuiContainer gui, int mouseX, int mouseY) {
}
@Override
public void postRenderObjects(GuiContainer gui, int mouseX, int mouseY) {
}
@Override
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
}
@SuppressWarnings("ALL")
@Override
public void renderSlotOverlay(GuiContainer gui, Slot slot) {
if (NEEConfig.drawHighlight && gui instanceof GuiRecipe && !overlayButtons.isEmpty()) {
GuiRecipe guiRecipe = (GuiRecipe) gui;
for (GuiButton overlayButton : overlayButtons) {
if (GuiUtils.isMouseOverButton(overlayButton)) {
IngredientTracker tracker = trackerMap.get("button" + overlayButton.id);
if (tracker != null) {
for (Ingredient ingredient : tracker.getIngredients()) {
Point point = guiRecipe.getRecipePosition(tracker.getRecipeIndex());
Slot currentSlot = guiRecipe.slotcontainer.getSlotWithStack(ingredient.getIngredient(), point.x, point.y);
if (slot.equals(currentSlot)) {
GuiContainer firstGui = guiRecipe.firstGui;
boolean renderAutoAbleItems = (GuiUtils.isCraftingTerm(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft();
boolean renderCraftableItems = (GuiUtils.isPatternTerm(firstGui)) && ingredient.isCraftable();
boolean renderMissingItems = (GuiUtils.isCraftingTerm(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft();
if (renderAutoAbleItems || renderCraftableItems) {
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;
}
if (renderMissingItems) {
Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition,
slot.xDisplayPosition + 16, slot.yDisplayPosition + 16,
new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB());
this.drawMissingTooltip = true;
}
}
}
}
}
if (this.isCraftingTerm || this.isPatternTerm) {
this.oldPage = guiRecipe.page;
this.oldType = guiRecipe.recipetype;
setOverlayButton(guiRecipe);
}
}
}
@SubscribeEvent
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
if (event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
GuiContainer firstGui = guiRecipe.firstGui;
boolean isGuiPatternTerm = GuiUtils.isPatternTerm(firstGui);
boolean isCraftingTerm = GuiUtils.isCraftingTerm(firstGui);
if (isCraftingTerm || isGuiPatternTerm) {
if (overlayButtons.isEmpty()) {
setOverlayButtons(guiRecipe);
}
if (NEEConfig.drawHighlight && event.gui instanceof GuiRecipe) {
if (this.isCraftingTerm || this.isPatternTerm) {
GuiRecipe gui = (GuiRecipe) event.gui;
if (!checkTracker()) {
trackerMap.clear();
for (GuiButton button : overlayButtons) {
if (GuiUtils.isMouseOverButton(button)) {
trackerMap.put("button" + button.id, getTracker(guiRecipe, button, isCraftingTerm));
}
if (gui.getHandler() != null && NEECraftingHandler.isCraftingTableRecipe(gui.getHandler())) {
if (this.trackerMap.isEmpty()) {
initIngredientTracker(gui);
}
if (this.oldPage != gui.page) {
this.oldPage = gui.page;
setOverlayButton(gui);
initIngredientTracker(gui);
}
if (this.oldType != gui.recipetype) {
this.oldType = gui.recipetype;
setOverlayButton(gui);
initIngredientTracker(gui);
}
}
if (this.drawCraftableTooltip || this.drawRequestTooltip || this.drawMissingTooltip) {
for (GuiButton button : overlayButtons) {
if (button.visible && button.enabled && GuiUtils.isMouseOverButton(button)) {
drawCraftingHelperTooltip(guiRecipe, event.mouseX, event.mouseY);
this.drawCraftableTooltip = false;
this.drawRequestTooltip = false;
this.drawMissingTooltip = false;
if (isMouseOverButton(button, event.mouseX, event.mouseY)) {
if (!trackerMap.isEmpty()) {
IngredientTracker tracker = trackerMap.get(button.id);
if (tracker != null) {
Point offset = gui.getRecipePosition(tracker.getRecipeIndex());
for (int i = 0; i < tracker.getIngredients().size(); i++) {
Ingredient ingredient = tracker.getIngredients().get(i);
Slot slot = gui.slotcontainer.getSlotWithStack(ingredient.getIngredient(), offset.x, offset.y);
if (slot != null) {
if (this.isCraftingTerm) {
if (ingredient.isCraftable() && ingredient.requiresToCraft()) {
GuiDraw.drawRect(slot.xDisplayPosition + gui.guiLeft, slot.yDisplayPosition + gui.guiTop,
16, 16,
craftableColor.getRGB());
this.drawRequestTooltip = true;
}
if (ingredient.requiresToCraft() && !ingredient.isCraftable()) {
GuiDraw.drawRect(slot.xDisplayPosition + gui.guiLeft, slot.yDisplayPosition + gui.guiTop,
16, 16,
missingColor.getRGB());
this.drawMissingTooltip = true;
}
} else if (this.isPatternTerm) {
if (ingredient.isCraftable()) {
GuiDraw.drawRect(slot.xDisplayPosition + gui.guiLeft, slot.yDisplayPosition + gui.guiTop,
16, 16,
craftableColor.getRGB());
this.drawCraftableTooltip = true;
}
}
}
}
drawCraftingHelperTooltip((GuiRecipe) event.gui, event.mouseX, event.mouseY);
}
}
}
}
}
}
}
}
private void setOverlayButton(GuiRecipe guiRecipe) {
//get all overlay buttons.
overlayButtons.clear();
trackerMap.clear();
List<GuiButton> overlayButtonList = null;
if (isGtnhNei) {
try {
overlayButtonList = new ArrayList<>(Arrays.asList((GuiButton[]) NEEContainerDrawHandler.instance.overlayButtonsField.get(guiRecipe)));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} else {
overlayButtonList = new ArrayList<>();
overlayButtonList.add(ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1"));
overlayButtonList.add(ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2"));
}
if (overlayButtonList != null) {
overlayButtons.addAll(overlayButtonList);
}
}
private void initIngredientTracker(GuiRecipe gui) {
for (int i = 0; i < overlayButtons.size(); i++) {
GuiButton overlayButton = overlayButtons.get(i);
if (overlayButton.visible) {
IRecipeHandler handler = gui.currenthandlers.get(gui.recipetype);
int recipeIndex = -1;
if (isGtnhNei) {
try {
int OVERLAY_BUTTON_ID_START = 4;
recipeIndex = gui.page * (int) recipesPerPageMethod.invoke(gui) + overlayButton.id - OVERLAY_BUTTON_ID_START;
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} else {
recipeIndex = gui.page * handler.recipiesPerPage() + i;
}
if (recipeIndex >= 0 && handler != null) {
IngredientTracker tracker = this.isCraftingTerm ? new IngredientTracker(gui.firstGui, handler, recipeIndex) : new IngredientTracker(gui, handler, recipeIndex);
trackerMap.put(overlayButton.id, tracker);
}
}
}
}
private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) {
List<String> tooltips = new ArrayList<>();
if (GuiUtils.isCraftingTerm(guiRecipe.firstGui)) {
if (this.isCraftingTerm) {
if (this.drawRequestTooltip) {
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 (NEECraftingHelper.isIsPatternInterfaceExists()) {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting.text1"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
} else {
tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " +
EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting.text2"),
EnumChatFormatting.YELLOW + Keyboard.getKeyName(NEIClientConfig.getKeyBinding("nee.preview"))));
}
}
if (this.drawMissingTooltip) {
tooltips.add(EnumChatFormatting.RED + I18n.format("neenergistics.gui.tooltip.missing"));
}
}
if (this.drawCraftableTooltip && GuiUtils.isPatternTerm(guiRecipe.firstGui)) {
if (this.drawCraftableTooltip && this.isPatternTerm) {
tooltips.add(EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.pattern"));
}
//drawHoveringText
guiRecipe.func_146283_a(tooltips, mouseX, mouseY);
this.drawCraftableTooltip = false;
this.drawRequestTooltip = false;
this.drawMissingTooltip = false;
}
private void setOverlayButtons(GuiRecipe guiRecipe) {
List<GuiButton> overlayButtons = null;
if (isGtnhNei) {
try {
overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) NEEContainerDrawHandler.instance.overlayButtonsField.get(guiRecipe)));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} else {
overlayButtons = new ArrayList<>();
GuiButton overlay1 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay1");
GuiButton overlay2 = ReflectionHelper.getPrivateValue(GuiRecipe.class, guiRecipe, "overlay2");
overlayButtons.add(overlay1);
overlayButtons.add(overlay2);
}
if (overlayButtons != null) {
this.overlayButtons.addAll(overlayButtons);
}
private boolean isMouseOverButton(GuiButton button, int mouseX, int mouseY) {
return mouseX >= button.xPosition &&
mouseY >= button.yPosition &&
mouseX < button.xPosition + button.width &&
mouseY < button.yPosition + button.height;
}
private boolean checkTracker() {
for (GuiButton overlayButton : overlayButtons) {
if (trackerMap.get("button" + overlayButton.id) != null) {
return true;
}
}
return false;
}
private IngredientTracker getTracker(GuiRecipe guiRecipe, GuiButton overlayButton, boolean isCraftingTerm) {
if (overlayButton.enabled && overlayButton.visible) {
final int OVERLAY_BUTTON_ID_START = 4;
IRecipeHandler handler = guiRecipe.currenthandlers.get(guiRecipe.recipetype);
int recipesPerPage = 2;
if (isGtnhNei) {
try {
recipesPerPage = (int) NEEContainerDrawHandler.instance.recipesPerPageMethod.invoke(guiRecipe);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
if (recipesPerPage >= 0 && handler != null) {
int recipeIndex = guiRecipe.page * recipesPerPage + overlayButton.id - OVERLAY_BUTTON_ID_START;
return isCraftingTerm ? new IngredientTracker(guiRecipe.firstGui, handler, recipeIndex) : new IngredientTracker(guiRecipe, handler, recipeIndex);
}
}
return null;
}
}
@@ -1,29 +0,0 @@
package com.github.vfyjxf.nee.client.gui;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.util.item.AEItemStack;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import net.minecraft.entity.player.InventoryPlayer;
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*;
public class GuiCraftingConfirm extends GuiCraftConfirm {
public GuiCraftingConfirm(InventoryPlayer inventoryPlayer, ITerminalHost te) {
super(inventoryPlayer, te);
}
@Override
public void onGuiClosed() {
if (tracker != null && tracker.getRequireStacks().size() > 1 && stackIndex < tracker.getRequireStacks().size()) {
IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(stackIndex));
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
stackIndex++;
} else {
tracker = null;
}
}
}
@@ -50,12 +50,15 @@ public class GuiPatternInterface extends AEBaseGui {
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
if (button == this.removeButton) {
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("Gui.PatternInterface"));
//We shouldn't delete a null, right?
if (container.getSelectedSlot() != null) {
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("Gui.PatternInterface"));
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int btn) {
protected void mouseClicked(int mouseX, int mouseY, int btn) {
if (btn == 0 && this.theSlot instanceof SlotRestrictedInput) {
SlotRestrictedInput slot = (SlotRestrictedInput) this.theSlot;
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("Container.selectedSlot", Integer.toString(slot.slotNumber)));
@@ -28,11 +28,9 @@ public class ContainerCraftingConfirm extends ContainerCraftConfirm {
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
if(Platform.isServer()) {
if (tile != null && !hasWorkCommitted) {
this.tile.getPatternInventory().setInventorySlotContents(patternIndex, null);
this.tile.updateCraftingList();
}
if (Platform.isServer() && tile != null && !hasWorkCommitted) {
this.tile.getPatternInventory().setInventorySlotContents(patternIndex, null);
this.tile.updateCraftingList();
}
}
@@ -1,6 +1,7 @@
package com.github.vfyjxf.nee.container;
import appeng.api.storage.ITerminalHost;
import appeng.util.Platform;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -18,14 +19,16 @@ public class WCTContainerCraftingConfirm extends ContainerCraftConfirm {
@Override
public void startJob() {
if (Platform.isServer()) {
hasWorkCommitted = true;
}
super.startJob();
hasWorkCommitted = true;
}
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
if (tile != null && !hasWorkCommitted) {
if (Platform.isServer() && tile != null && !hasWorkCommitted) {
this.tile.getPatternInventory().setInventorySlotContents(patternIndex, null);
this.tile.updateCraftingList();
}
@@ -1,6 +1,5 @@
package com.github.vfyjxf.nee.nei;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotCraftingMatrix;
@@ -10,7 +9,6 @@ import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
@@ -20,9 +18,7 @@ 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.PacketCraftingRequest;
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
import com.github.vfyjxf.nee.network.packet.PacketSetRecipe;
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;
import com.github.vfyjxf.nee.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.IngredientTracker;
@@ -59,7 +55,6 @@ import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
public class NEECraftingHelper implements IOverlayHandler {
public static final NEECraftingHelper INSTANCE = new NEECraftingHelper();
public static IngredientTracker tracker = null;
public static int stackIndex = 1;
public static boolean noPreview = false;
private static boolean isPatternInterfaceExists = false;
@@ -68,22 +63,18 @@ public class NEECraftingHelper implements IOverlayHandler {
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
if (GuiUtils.isCraftingTerm(firstGui) && NEECraftingHandler.isCraftingTableRecipe(recipe)) {
if (GuiUtils.isGuiCraftingTerm(firstGui) && NEECraftingHandler.isCraftingTableRecipe(recipe)) {
boolean doCraftingHelp = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview")) || Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"));
noPreview = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"));
if (doCraftingHelp) {
if (isPatternInterfaceExists) {
// NEENetworkHandler.getInstance().sendToServer(new PacketSetRecipe(packCraftingRecipe(recipe, recipeIndex)));
NEENetworkHandler.getInstance().sendToServer(new PacketOpenCraftAmount(packCraftingRecipe(recipe,recipeIndex)));
NEENetworkHandler.getInstance().sendToServer(new PacketOpenCraftAmount(packCraftingRecipe(recipe, recipeIndex)));
isPatternInterfaceExists = false;
} else {
tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
if (!tracker.getRequireStacks().isEmpty()) {
IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(0));
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
stackIndex = 1;
tracker.requestNextIngredient();
} else {
moveItems(firstGui, recipe, recipeIndex);
}
@@ -299,7 +290,7 @@ public class NEECraftingHelper implements IOverlayHandler {
if (event.gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
GuiContainer firstGui = guiRecipe.firstGui;
if (GuiUtils.isCraftingTerm(firstGui)) {
if (GuiUtils.isGuiCraftingTerm(firstGui)) {
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("PatternInterface.check"));
}
}
@@ -308,4 +299,8 @@ public class NEECraftingHelper implements IOverlayHandler {
public static void setIsPatternInterfaceExists(boolean isPatternInterfaceExists) {
NEECraftingHelper.isPatternInterfaceExists = isPatternInterfaceExists;
}
public static boolean isIsPatternInterfaceExists() {
return isPatternInterfaceExists;
}
}
@@ -5,12 +5,12 @@ import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.storage.ITerminalHost;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.parts.reporting.PartCraftingTerminal;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import com.github.vfyjxf.nee.client.gui.GuiCraftingAmount;
import com.github.vfyjxf.nee.client.gui.GuiCraftingConfirm;
import com.github.vfyjxf.nee.client.gui.GuiPatternInterface;
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
import com.github.vfyjxf.nee.container.ContainerCraftingConfirm;
@@ -25,8 +25,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler;
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm;
import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
@@ -115,7 +113,7 @@ public class NEEGuiHandler implements IGuiHandler {
return null;
case CRAFTING_CONFIRM_ID:
if (part instanceof PartCraftingTerminal) {
return updateGui(new GuiCraftingConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part);
return updateGui(new GuiCraftConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part);
}
return null;
@@ -141,7 +139,7 @@ public class NEEGuiHandler implements IGuiHandler {
if (guiId == CRAFTING_AMOUNT_WIRELESS_ID) {
return new GuiCraftingAmount(player.inventory, wirelessTerminal);
} else {
return new GuiCraftConfirm(player.inventory, wirelessTerminal);
return new net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm(player.inventory, wirelessTerminal);
}
} else {
@@ -9,7 +9,6 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
public class PacketValueConfigClient implements IMessage, IMessageHandler<PacketValueConfigClient, IMessage> {
@@ -50,7 +49,7 @@ public class PacketValueConfigClient implements IMessage, IMessageHandler<Packet
if ("PatternInterface.check".equals(message.name) && Boolean.parseBoolean(message.value)) {
if (gui instanceof GuiRecipe) {
GuiRecipe guiRecipe = (GuiRecipe) gui;
if (GuiUtils.isCraftingTerm(guiRecipe.firstGui)) {
if (GuiUtils.isGuiCraftingTerm(guiRecipe.firstGui)) {
NEECraftingHelper.setIsPatternInterfaceExists(true);
}
}
@@ -8,6 +8,7 @@ import appeng.container.slot.SlotRestrictedInput;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import com.github.vfyjxf.nee.container.ContainerPatternInterface;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
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;
@@ -16,6 +17,8 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
public class PacketValueConfigServer implements IMessage, IMessageHandler<PacketValueConfigServer, IMessage> {
@@ -62,7 +65,7 @@ public class PacketValueConfigServer implements IMessage, IMessageHandler<Packet
cpc.setSelectedSlotIndex(slot.slotNumber);
}
}
}else if ("Gui.PatternInterface".equals(message.name)) {
} else if ("Gui.PatternInterface".equals(message.name)) {
if (container instanceof ContainerPatternInterface) {
ContainerPatternInterface cpc = (ContainerPatternInterface) container;
TilePatternInterface tile = (TilePatternInterface) cpc.getTileEntity();
@@ -70,11 +73,11 @@ public class PacketValueConfigServer implements IMessage, IMessageHandler<Packet
cpc.removeCurrentRecipe();
tile.updateCraftingList();
}
}else if ("PatternInterface.check".equals(message.name)) {
if (container instanceof AEBaseContainer) {
AEBaseContainer abc = (AEBaseContainer) container;
IGrid grid = getNetwork(abc);
} else if ("PatternInterface.check".equals(message.name)) {
if (container instanceof AEBaseContainer || GuiUtils.isWirelessCraftingTermContainer(container)) {
IGrid grid = container instanceof AEBaseContainer ? getNetwork((AEBaseContainer) container) : getNetwork((ContainerWirelessCraftingTerminal) container);
if (grid != null) {
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
if (gridNode.getMachine() instanceof TilePatternInterface) {
@@ -100,4 +103,13 @@ public class PacketValueConfigServer implements IMessage, IMessageHandler<Packet
return null;
}
private IGrid getNetwork(ContainerWirelessCraftingTerminal container) {
if (container.getTarget() instanceof WirelessTerminalGuiObject) {
return ((WirelessTerminalGuiObject) container.getTarget()).getTargetGrid();
}
return null;
}
}
@@ -1,5 +1,6 @@
package com.github.vfyjxf.nee.utils;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.implementations.ContainerPatternTerm;
@@ -7,11 +8,9 @@ import appeng.helpers.IContainerCraftingPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import org.lwjgl.input.Mouse;
/**
* @author vfyjxf
@@ -51,20 +50,6 @@ public class GuiUtils {
}
}
public static boolean isMouseOverButton(GuiButton button) {
Minecraft mc = Minecraft.getMinecraft();
final ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int i = scaledresolution.getScaledWidth();
int j = scaledresolution.getScaledHeight();
final int mouseX = Mouse.getX() * i / mc.displayWidth;
final int mouseY = j - Mouse.getY() * j / mc.displayHeight - 1;
return mouseX >= button.xPosition &&
mouseY >= button.yPosition &&
mouseX < button.xPosition + button.width &&
mouseY < button.yPosition + button.height;
}
public static boolean isGuiWirelessCrafting(GuiScreen gui) {
try {
@@ -94,6 +79,24 @@ public class GuiUtils {
}
}
public static boolean isContainerWirelessCraftingConfirm(Container container) {
try {
Class<?> wirelessCraftingConfirmClass = Class.forName("net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm");
return wirelessCraftingConfirmClass.isInstance(container);
} catch (ClassNotFoundException e) {
return false;
}
}
public static boolean isWCTContainerCraftingConfirm(Container container) {
try {
Class<?> wctCraftingConfirmClass = Class.forName("com.github.vfyjxf.nee.container.WCTContainerCraftingConfirm");
return wctCraftingConfirmClass.isInstance(container);
} catch (ClassNotFoundException e) {
return false;
}
}
public static boolean isWirelessTerminalGuiObject(Object guiObj) {
try {
Class<?> wirelessTerminalGuiObjClass = Class.forName("net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject");
@@ -103,7 +106,7 @@ public class GuiUtils {
}
}
public static boolean isCraftingTerm(GuiScreen guiScreen) {
public static boolean isGuiCraftingTerm(GuiScreen guiScreen) {
return guiScreen instanceof GuiCraftingTerm || isGuiWirelessCrafting(guiScreen);
}
@@ -111,4 +114,8 @@ public class GuiUtils {
return guiScreen instanceof GuiPatternTerm || isPatternTermExGui(guiScreen);
}
public static boolean isGuiCraftConfirm(GuiScreen gui) {
return gui instanceof GuiCraftConfirm || isWirelessGuiCraftConfirm(gui);
}
}
@@ -4,10 +4,13 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.client.gui.implementations.GuiMEMonitorable;
import appeng.client.me.ItemRepo;
import appeng.util.item.AEItemStack;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
import cpw.mods.fml.relauncher.ReflectionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -18,16 +21,18 @@ import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTermi
import java.util.ArrayList;
import java.util.List;
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.noPreview;
public class IngredientTracker {
private final List<Ingredient> ingredients = new ArrayList<>();
private int craftingAmount = 1;
private final GuiContainer termGui;
private List<ItemStack> requireStacks;
private final int recipeIndex;
private int currentIndex = 0;
/**
* For NEECraftingHelper
* For {@link com.github.vfyjxf.nee.nei.NEECraftingHelper}
*/
public IngredientTracker(GuiContainer termGui, IRecipeHandler recipe, int recipeIndex) {
this.termGui = termGui;
@@ -49,6 +54,9 @@ public class IngredientTracker {
this.calculateIngredients();
}
/**
* For {@link com.github.vfyjxf.nee.client.NEEContainerDrawHandler}
*/
public IngredientTracker(GuiRecipe guiRecipe, IRecipeHandler recipe, int recipeIndex) {
this.termGui = guiRecipe.firstGui;
this.recipeIndex = recipeIndex;
@@ -69,7 +77,6 @@ public class IngredientTracker {
}
@SuppressWarnings("unchecked")
private List<IAEItemStack> getCraftableStacks() {
List<IAEItemStack> craftableStacks = new ArrayList<>();
@@ -156,6 +163,18 @@ public class IngredientTracker {
return requireStacks;
}
public boolean hasNext() {
return currentIndex < getRequireStacks().size();
}
public void requestNextIngredient() {
IAEItemStack stack = AEItemStack.create(this.getRequiredStack(currentIndex));
if (stack != null) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
}
currentIndex++;
}
public ItemStack getRequiredStack(int index) {
return this.getRequireStacks().get(index);
}
@@ -164,10 +183,6 @@ public class IngredientTracker {
return recipeIndex;
}
public void setCraftingAmount(int craftingAmount) {
this.craftingAmount = craftingAmount;
}
public void addAvailableStack(ItemStack stack) {
for (Ingredient ingredient : this.ingredients) {
if (ingredient.requiresToCraft()) {
@@ -202,12 +217,6 @@ public class IngredientTracker {
@SuppressWarnings("unchecked")
public void calculateIngredients() {
//set requireCount and reset currentCount
for (Ingredient ingredient : this.getIngredients()) {
ingredient.setRequireCount(ingredient.getDefaultRequireCount() * craftingAmount);
ingredient.setCurrentCount(0);
}
List<IAEItemStack> stacks = NEEConfig.matchOtherItems ? getStorageStacks() : getCraftableStacks();
for (Ingredient ingredient : this.ingredients) {
for (IAEItemStack stack : stacks) {
@@ -1,4 +1,5 @@
neenergistics.gui.tooltip.helper.crafting=click to request missing items
neenergistics.gui.tooltip.helper.crafting.text1=click to request missing items
neenergistics.gui.tooltip.helper.crafting.text2=click to request the recipe result.
neenergistics.gui.tooltip.missing=Missing Items
neenergistics.gui.tooltip.helper.pattern=Autocrafting available
@@ -1,4 +1,4 @@
neenergistics.gui.tooltip.helper.crafting=Нажмите, чтобы запоросить отсутсвующие предметы
neenergistics.gui.tooltip.helper.crafting.text1=Нажмите, чтобы запоросить отсутсвующие предметы
neenergistics.gui.tooltip.missing=Отсутствуют требуемые предметы
neenergistics.gui.tooltip.helper.pattern=Автокрафт доступен
nei.options.keys.nee=NotEnoughEnergistics
@@ -1,4 +1,5 @@
neenergistics.gui.tooltip.helper.crafting=点击以请求缺失的物品
neenergistics.gui.tooltip.helper.crafting.text1=点击以请求缺失的物品
neenergistics.gui.tooltip.helper.crafting.text2=点击来请求配方成品。
neenergistics.gui.tooltip.missing=缺失物品
neenergistics.gui.tooltip.helper.pattern=自动合成已可用
Whitespace-only changes.