mirror of
https://github.com/GTNewHorizons/NotEnoughEnergistics.git
synced 2026-11-17 19:05:01 +00:00
1 parent
8603274b1d
commit
c9daf24aad
47 files changed
+2484
-2680
No files matched your search
@@ -12,11 +12,15 @@ import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTermi
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.github.vfyjxf.nee.client.GuiEventHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingTerminalHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEExtremeAutoCrafterHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEKnowledgeInscriberHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEETerminalBookmarkContainerHandler;
|
||||
import com.github.vfyjxf.nee.processor.IRecipeProcessor;
|
||||
import com.github.vfyjxf.nee.processor.RecipeProcessor;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftingWireless;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternExWireless;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx;
|
||||
@@ -24,6 +28,8 @@ import com.glodblock.github.client.gui.GuiFluidPatternWireless;
|
||||
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.client.gui.implementations.GuiInterface;
|
||||
import appeng.client.gui.implementations.GuiMEMonitorable;
|
||||
import appeng.client.gui.implementations.GuiMEPortableCell;
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.client.gui.implementations.GuiPatternTermEx;
|
||||
import codechicken.nei.NEIController;
|
||||
@@ -31,7 +37,10 @@ import codechicken.nei.api.API;
|
||||
import codechicken.nei.api.IConfigureNEI;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.recipe.DefaultOverlayHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import fox.spiteful.avaritia.gui.GUIExtremeCrafting;
|
||||
import thaumicenergistics.client.gui.GuiArcaneCraftingTerminal;
|
||||
import thaumicenergistics.client.gui.GuiKnowledgeInscriber;
|
||||
import wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter;
|
||||
|
||||
@@ -58,22 +67,26 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
|
||||
for (String ident : identifiers) {
|
||||
API.registerGuiOverlay(GuiPatternTerm.class, ident);
|
||||
API.registerGuiOverlayHandler(GuiPatternTerm.class, NEECraftingHandler.INSTANCE, ident);
|
||||
API.registerGuiOverlayHandler(GuiPatternTerm.class, NEEPatternTerminalHandler.instance, ident);
|
||||
}
|
||||
|
||||
installCraftingTermSupport();
|
||||
|
||||
installWirelessCraftingTermSupport();
|
||||
|
||||
installFluidPatternTerminalSupport(new HashSet<String>(identifiers));
|
||||
installFluidPatternTerminalSupport(new HashSet<>(identifiers));
|
||||
|
||||
installThaumicEnergisticsSupport();
|
||||
|
||||
installAvaritiaSupport();
|
||||
|
||||
installAvaritiaddonsSupport();
|
||||
|
||||
installPatternTerminalExSupport(new HashSet<String>(identifiers));
|
||||
installPatternTerminalExSupport(new HashSet<>(identifiers));
|
||||
|
||||
installFluidPatternTerminalExSupport(new HashSet<String>(identifiers));
|
||||
installFluidPatternTerminalExSupport(new HashSet<>(identifiers));
|
||||
|
||||
installlBookmarkContainerHandler();
|
||||
}
|
||||
|
||||
private void installFluidPatternTerminalExSupport(Set<String> identifiers) {
|
||||
@@ -83,8 +96,15 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
for (String ident : identifiers) {
|
||||
API.registerGuiOverlay(GuiFluidPatternTerminalEx.class, ident);
|
||||
API.registerGuiOverlay(GuiFluidPatternExWireless.class, ident);
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternTerminalEx.class, NEECraftingHandler.INSTANCE, ident);
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternExWireless.class, NEECraftingHandler.INSTANCE, ident);
|
||||
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiFluidPatternTerminalEx.class,
|
||||
NEEPatternTerminalHandler.instance,
|
||||
ident);
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiFluidPatternExWireless.class,
|
||||
NEEPatternTerminalHandler.instance,
|
||||
ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,12 +114,53 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
for (String ident : identifiers) {
|
||||
API.registerGuiOverlay(GuiFluidPatternTerminal.class, ident);
|
||||
API.registerGuiOverlay(GuiFluidPatternWireless.class, ident);
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternTerminal.class, NEECraftingHandler.INSTANCE, ident);
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternWireless.class, NEECraftingHandler.INSTANCE, ident);
|
||||
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternTerminal.class, NEEPatternTerminalHandler.instance, ident);
|
||||
API.registerGuiOverlayHandler(GuiFluidPatternWireless.class, NEEPatternTerminalHandler.instance, ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installlBookmarkContainerHandler() {
|
||||
API.registerBookmarkContainerHandler(GuiPatternTerm.class, NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(GuiPatternTermEx.class, NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(GuiCraftingTerm.class, NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(GuiMEMonitorable.class, NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(GuiMEPortableCell.class, NEETerminalBookmarkContainerHandler.instance);
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.FC)) {
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiFluidPatternWireless.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiFluidPatternTerminal.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiFluidPatternTerminalEx.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiFluidPatternExWireless.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiFluidCraftingWireless.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
}
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiWirelessCraftingTerminal.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
}
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.ThE)) {
|
||||
API.registerBookmarkContainerHandler(
|
||||
GuiArcaneCraftingTerminal.class,
|
||||
NEETerminalBookmarkContainerHandler.instance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NotEnoughEnergistics.NAME;
|
||||
@@ -119,6 +180,7 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
|
||||
private void registerGuiHandler() {
|
||||
API.registerNEIGuiHandler(GuiEventHandler.instance);
|
||||
GuiContainerManager.addTooltipHandler(GuiEventHandler.instance);
|
||||
// disable MouseScrollTransfer in some gui
|
||||
replaceNEIController();
|
||||
}
|
||||
@@ -150,32 +212,57 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
private void installCraftingTermSupport() {
|
||||
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting");
|
||||
API.registerGuiOverlay(GuiCraftingTerm.class, "crafting2x2");
|
||||
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingHelper.INSTANCE, "crafting");
|
||||
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingHelper.INSTANCE, "crafting2x2");
|
||||
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingTerminalHandler.instance, "crafting");
|
||||
API.registerGuiOverlayHandler(GuiCraftingTerm.class, NEECraftingTerminalHandler.instance, "crafting2x2");
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.FC)) {
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiFluidCraftingWireless.class,
|
||||
NEECraftingTerminalHandler.instance,
|
||||
"crafting");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiFluidCraftingWireless.class,
|
||||
NEECraftingTerminalHandler.instance,
|
||||
"crafting2x2");
|
||||
}
|
||||
}
|
||||
|
||||
private void installWirelessCraftingTermSupport() {
|
||||
if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, NEECraftingHelper.INSTANCE, "crafting");
|
||||
API.registerGuiOverlayHandler(GuiWirelessCraftingTerminal.class, NEECraftingHelper.INSTANCE, "crafting2x2");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiWirelessCraftingTerminal.class,
|
||||
NEECraftingTerminalHandler.instance,
|
||||
"crafting");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiWirelessCraftingTerminal.class,
|
||||
NEECraftingTerminalHandler.instance,
|
||||
"crafting2x2");
|
||||
}
|
||||
}
|
||||
|
||||
private void installThaumicEnergisticsSupport() {
|
||||
try {
|
||||
Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
if (Loader.isModLoaded("thaumcraftneiplugin")) {
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.ThE)) {
|
||||
NotEnoughEnergistics.logger.info("Install ThaumicEnergistics support");
|
||||
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes");
|
||||
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessrecipes");
|
||||
API.registerGuiOverlayHandler(GuiKnowledgeInscriber.class, new NEECraftingHandler(), "arcaneshapedrecipes");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiKnowledgeInscriber.class,
|
||||
new NEECraftingHandler(),
|
||||
"arcaneshapelessrecipes");
|
||||
|
||||
try {
|
||||
Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
|
||||
|
||||
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapedrecipes");
|
||||
API.registerGuiOverlay(GuiKnowledgeInscriber.class, "arcaneshapelessSrecipes");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiKnowledgeInscriber.class,
|
||||
NEEKnowledgeInscriberHandler.instance,
|
||||
"arcaneshapedrecipes");
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiKnowledgeInscriber.class,
|
||||
NEEKnowledgeInscriberHandler.instance,
|
||||
"arcaneshapelessrecipes");
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +272,7 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
// PatternTermEx Support
|
||||
for (String ident : identifiers) {
|
||||
API.registerGuiOverlay(GuiPatternTermEx.class, ident);
|
||||
API.registerGuiOverlayHandler(GuiPatternTermEx.class, new NEECraftingHandler(), ident);
|
||||
API.registerGuiOverlayHandler(GuiPatternTermEx.class, NEEPatternTerminalHandler.instance, ident);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,10 +282,27 @@ public class NEINeeConfig implements IConfigureNEI {
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Loader.isModLoaded("avaritiaddons")) {
|
||||
NotEnoughEnergistics.logger.info("Install Avaritiaddons support");
|
||||
API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme");
|
||||
API.registerGuiOverlayHandler(GuiExtremeAutoCrafter.class, new NEECraftingHandler(), "extreme");
|
||||
API.registerGuiOverlay(GuiExtremeAutoCrafter.class, "extreme", 181, 15);
|
||||
API.registerGuiOverlayHandler(
|
||||
GuiExtremeAutoCrafter.class,
|
||||
NEEExtremeAutoCrafterHandler.instance,
|
||||
"extreme");
|
||||
}
|
||||
}
|
||||
|
||||
private void installAvaritiaSupport() {
|
||||
try {
|
||||
Class.forName("fox.spiteful.avaritia.gui.GUIExtremeCrafting");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Loader.isModLoaded("Avaritia")) {
|
||||
API.registerGuiOverlay(GUIExtremeCrafting.class, "extreme", 9, 5);
|
||||
API.registerGuiOverlayHandler(GUIExtremeCrafting.class, new DefaultOverlayHandler(9, 5), "extreme");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class BlockPatternInterface extends AEBaseTileBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
TilePatternInterface tile = this.getTileEntity(world, x, y, z);
|
||||
final TilePatternInterface tile = this.getTileEntity(world, x, y, z);
|
||||
if (tile != null) {
|
||||
if (!world.isRemote) {
|
||||
NEEGuiHandler.openGui(player, NEEGuiHandler.PATTERN_INTERFACE_ID, tile, ForgeDirection.UNKNOWN);
|
||||
|
||||
@@ -433,8 +433,7 @@ public class TilePatternInterface extends AENetworkInvTile
|
||||
final ImmutableSet<ICraftingCPU> cpuSet = cg.getCpus();
|
||||
|
||||
for (ICraftingCPU cpu : cpuSet) {
|
||||
if (cpu instanceof CraftingCPUCluster) {
|
||||
CraftingCPUCluster cluster = (CraftingCPUCluster) cpu;
|
||||
if (cpu instanceof CraftingCPUCluster cluster) {
|
||||
final IItemList<IAEItemStack> pendingList = AEApi.instance().storage().createItemList();
|
||||
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
|
||||
for (IAEItemStack pendingStack : pendingList) {
|
||||
@@ -668,12 +667,10 @@ public class TilePatternInterface extends AENetworkInvTile
|
||||
try {
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final ImmutableSet<ICraftingCPU> cpuSet = cg.getCpus();
|
||||
|
||||
final IItemList<IAEItemStack> pendingList = AEApi.instance().storage().createItemList();
|
||||
|
||||
for (ICraftingCPU cpu : cpuSet) {
|
||||
if (cpu instanceof CraftingCPUCluster) {
|
||||
CraftingCPUCluster cluster = (CraftingCPUCluster) cpu;
|
||||
if (cpu instanceof CraftingCPUCluster cluster) {
|
||||
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,149 +2,166 @@ package com.github.vfyjxf.nee.client;
|
||||
|
||||
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.NEECraftingHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.tracker;
|
||||
import static com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.utils.GuiUtils.isPatternTerm;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.client.resources.I18n;
|
||||
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.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
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.container.ContainerCraftingConfirm;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.client.gui.GuiLevelMaintainer;
|
||||
import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal;
|
||||
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
|
||||
|
||||
import appeng.api.events.GuiScrollEvent;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.implementations.GuiCraftConfirm;
|
||||
import appeng.client.gui.implementations.GuiInterface;
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import codechicken.nei.api.INEIGuiAdapter;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.RecipeInfo;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class GuiEventHandler implements INEIGuiHandler {
|
||||
public class GuiEventHandler extends INEIGuiAdapter implements IContainerTooltipHandler {
|
||||
|
||||
public static GuiEventHandler instance = new GuiEventHandler();
|
||||
public static final GuiEventHandler instance = new GuiEventHandler();
|
||||
private final GuiImgButtonEnableCombination buttonCombination = new GuiImgButtonEnableCombination(
|
||||
0,
|
||||
0,
|
||||
ItemCombination.ENABLED);
|
||||
|
||||
private GuiImgButtonEnableCombination buttonCombination;
|
||||
private boolean hasDoubleBtn = true;
|
||||
private boolean hasBeSubstituteBtn = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GuiButton getCancelButton(GuiCraftConfirm gui) {
|
||||
return ObfuscationReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel");
|
||||
}
|
||||
|
||||
private boolean isContainerCraftConfirm(Container container) {
|
||||
return (container instanceof ContainerCraftConfirm || GuiUtils.isContainerWirelessCraftingConfirm(container))
|
||||
&& !((container instanceof ContainerCraftingConfirm)
|
||||
|| (GuiUtils.isWCTContainerCraftingConfirm(container)));
|
||||
}
|
||||
private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
|
||||
private List<GuiButton> buttonList;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SubscribeEvent
|
||||
public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (event.gui instanceof GuiPatternTerm) {
|
||||
GuiPatternTerm gui = (GuiPatternTerm) event.gui;
|
||||
try {
|
||||
GuiPatternTerm.class.getDeclaredField("doubleBtn");
|
||||
} catch (NoSuchFieldException e) {
|
||||
hasDoubleBtn = false;
|
||||
}
|
||||
try {
|
||||
GuiPatternTerm.class.getDeclaredField("beSubstitutionsEnabledBtn");
|
||||
} catch (NoSuchFieldException e) {
|
||||
hasBeSubstituteBtn = false;
|
||||
|
||||
if (isGuiPatternTerm(event.gui)) {
|
||||
event.buttonList.add(buttonCombination);
|
||||
this.buttonList = getButtonList((GuiContainer) event.gui, event.buttonList);
|
||||
updateCombinationButtonPosition((GuiContainer) event.gui);
|
||||
} else {
|
||||
this.buttonList = null;
|
||||
}
|
||||
|
||||
if (event.gui instanceof GuiRecipe<?>) {
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("PatternInterface.check"));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
|
||||
|
||||
if (this.buttonList != null && isGuiPatternTerm(event.gui)) {
|
||||
updateCombinationButtonPosition((GuiContainer) event.gui);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGuiPatternTerm(GuiScreen guiScreen) {
|
||||
if (guiScreen instanceof GuiContainer guiContainer) {
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.FC) && guiContainer instanceof FCGuiEncodeTerminal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int x, y;
|
||||
if (hasDoubleBtn && hasBeSubstituteBtn) {
|
||||
x = gui.guiLeft + 84;
|
||||
y = gui.guiTop + gui.ySize - 143;
|
||||
} else if (hasDoubleBtn) {
|
||||
x = gui.guiLeft + 84;
|
||||
y = gui.guiTop + gui.ySize - 153;
|
||||
} else {
|
||||
x = gui.guiLeft + 74;
|
||||
y = gui.guiTop + gui.ySize - 153;
|
||||
}
|
||||
buttonCombination = new GuiImgButtonEnableCombination(
|
||||
x,
|
||||
y,
|
||||
ItemCombination.valueOf(NEEConfig.itemCombinationMode));
|
||||
event.buttonList.add(buttonCombination);
|
||||
return RecipeInfo.getOverlayHandler(guiContainer, "crafting") instanceof NEEPatternTerminalHandler
|
||||
|| RecipeInfo.getOverlayHandler(guiContainer, "smelting") instanceof NEEPatternTerminalHandler;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<GuiButton> getButtonList(GuiContainer guiContainer, List<Object> items) {
|
||||
final Rectangle buttonsArea = new Rectangle(
|
||||
guiContainer.guiLeft + 70,
|
||||
guiContainer.guiTop + guiContainer.ySize - 165,
|
||||
38,
|
||||
68);
|
||||
return items.stream().filter(btn -> btn instanceof GuiButton && btn != buttonCombination)
|
||||
.map(GuiButton.class::cast).filter(btn -> buttonsArea.contains(btn.xPosition, btn.yPosition))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void updateCombinationButtonPosition(GuiContainer guiContainer) {
|
||||
final Point leftPoint = new Point(Integer.MAX_VALUE, 0);
|
||||
final Point rightPoint = new Point(0, 0);
|
||||
|
||||
for (GuiButton button : buttonList) {
|
||||
if (button.visible) {
|
||||
leftPoint.x = Math.min(leftPoint.x, button.xPosition);
|
||||
rightPoint.x = Math.max(rightPoint.x, button.xPosition);
|
||||
}
|
||||
}
|
||||
|
||||
for (GuiButton button : buttonList) {
|
||||
if (button.visible) {
|
||||
if (leftPoint.x == button.xPosition) {
|
||||
leftPoint.y = Math.max(leftPoint.y, button.yPosition + button.height);
|
||||
}
|
||||
|
||||
if (rightPoint.x == button.xPosition) {
|
||||
rightPoint.y = Math.max(rightPoint.y, button.yPosition + button.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rightPoint.y < leftPoint.y) {
|
||||
buttonCombination.xPosition = rightPoint.x;
|
||||
buttonCombination.yPosition = leftPoint.y - buttonCombination.height;
|
||||
} else if (rightPoint.y == leftPoint.y) {
|
||||
buttonCombination.xPosition = leftPoint.x;
|
||||
buttonCombination.yPosition = leftPoint.y + 2;
|
||||
} else {
|
||||
buttonCombination.xPosition = leftPoint.x;
|
||||
buttonCombination.yPosition = rightPoint.y - buttonCombination.height;
|
||||
}
|
||||
|
||||
buttonCombination.setValue(ItemCombination.valueOf(NEEConfig.itemCombinationMode));
|
||||
buttonCombination.enabled = buttonCombination.visible = guiContainer.inventorySlots instanceof AEBaseContainer
|
||||
&& !isCraftingMode((AEBaseContainer) guiContainer.inventorySlots);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onActionPerformed(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if (event.button == this.buttonCombination) {
|
||||
GuiImgButtonEnableCombination button = (GuiImgButtonEnableCombination) event.button;
|
||||
int ordinal = Mouse.getEventButton() != 2 ? button.getCurrentValue().ordinal() + 1
|
||||
: button.getCurrentValue().ordinal() - 1;
|
||||
int ordinal = this.buttonCombination.getCurrentValue().ordinal() + (Mouse.getEventButton() == 0 ? 1 : -1);
|
||||
|
||||
if (ordinal >= ItemCombination.values().length) {
|
||||
ordinal = 0;
|
||||
@@ -152,38 +169,21 @@ public class GuiEventHandler implements INEIGuiHandler {
|
||||
if (ordinal < 0) {
|
||||
ordinal = ItemCombination.values().length - 1;
|
||||
}
|
||||
button.setValue(ItemCombination.values()[ordinal]);
|
||||
|
||||
this.buttonCombination.setValue(ItemCombination.values()[ordinal]);
|
||||
NEEConfig.setItemCombinationMode(ItemCombination.values()[ordinal].name());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
|
||||
if (event.gui instanceof GuiPatternTerm) {
|
||||
ContainerPatternTerm container = (ContainerPatternTerm) ((GuiPatternTerm) event.gui).inventorySlots;
|
||||
if (container.isCraftingMode()) {
|
||||
buttonCombination.enabled = false;
|
||||
buttonCombination.visible = false;
|
||||
} else {
|
||||
buttonCombination.enabled = true;
|
||||
buttonCombination.visible = true;
|
||||
}
|
||||
private boolean isCraftingMode(AEBaseContainer container) {
|
||||
|
||||
if (container instanceof ContainerPatternTerm) {
|
||||
return ((ContainerPatternTerm) container).isCraftingMode();
|
||||
} else if (Loader.isModLoaded(ModIDs.FC) && container instanceof FCContainerEncodeTerminal) {
|
||||
return ((FCContainerEncodeTerminal) container).isCraftingMode();
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -193,56 +193,47 @@ public class GuiEventHandler implements INEIGuiHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NEEConfig.enableNEIDragDrop) {
|
||||
if (Loader.isModLoaded("ae2fc") && gui instanceof GuiLevelMaintainer) {
|
||||
return false;
|
||||
}
|
||||
if (gui instanceof AEBaseGui) {
|
||||
if (draggedStack != null) {
|
||||
Slot currentSlot = gui.getSlotAtPosition(mouseX, mouseY);
|
||||
if (currentSlot instanceof SlotFake) {
|
||||
ItemStack slotStack = currentSlot.getStack();
|
||||
ItemStack copyStack = draggedStack.copy();
|
||||
boolean sendPacket = false;
|
||||
int copySize = useStackSizeFromNEI ? copyStack.stackSize : draggedStackDefaultSize;
|
||||
if (button == 0) {
|
||||
boolean areStackEqual = slotStack != null && slotStack.isItemEqual(copyStack)
|
||||
&& ItemStack.areItemStackTagsEqual(slotStack, copyStack);
|
||||
copyStack.stackSize = areStackEqual ? slotStack.stackSize + copySize : copySize;
|
||||
sendPacket = true;
|
||||
} else if (button == 1) {
|
||||
boolean areStackEqual = slotStack != null && slotStack.isItemEqual(copyStack)
|
||||
&& ItemStack.areItemStackTagsEqual(slotStack, copyStack);
|
||||
if (areStackEqual) {
|
||||
copyStack.stackSize = slotStack.stackSize;
|
||||
} else {
|
||||
copyStack.stackSize = slotStack == null ? 1 : copySize;
|
||||
}
|
||||
sendPacket = true;
|
||||
}
|
||||
if (NEEConfig.enableNEIDragDrop && Loader.isModLoaded("ae2fc") && gui instanceof GuiLevelMaintainer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sendPacket) {
|
||||
NEENetworkHandler.getInstance().sendToServer(
|
||||
new PacketSlotStackChange(
|
||||
copyStack,
|
||||
Collections.singletonList(currentSlot.slotNumber)));
|
||||
if (!NEEConfig.keepGhostitems) {
|
||||
draggedStack.stackSize = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (NEEConfig.enableNEIDragDrop && draggedStack != null && gui instanceof AEBaseGui) {
|
||||
Slot currentSlot = gui.getSlotAtPosition(mouseX, mouseY);
|
||||
|
||||
if (currentSlot instanceof SlotFake) {
|
||||
ItemStack slotStack = currentSlot.getStack();
|
||||
ItemStack copyStack = draggedStack.copy();
|
||||
boolean sendPacket = false;
|
||||
int copySize = useStackSizeFromNEI ? copyStack.stackSize : draggedStackDefaultSize;
|
||||
if (button == 0) {
|
||||
copyStack.stackSize = NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotStack, copyStack)
|
||||
? slotStack.stackSize + copySize
|
||||
: copySize;
|
||||
sendPacket = true;
|
||||
} else if (button == 1) {
|
||||
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotStack, copyStack)) {
|
||||
copyStack.stackSize = slotStack.stackSize;
|
||||
} else {
|
||||
copyStack.stackSize = slotStack == null ? 1 : copySize;
|
||||
}
|
||||
if (button == 2) {
|
||||
sendPacket = true;
|
||||
}
|
||||
|
||||
if (sendPacket) {
|
||||
NEENetworkHandler.getInstance().sendToServer(
|
||||
new PacketSlotStackChange(copyStack, Collections.singletonList(currentSlot.slotNumber)));
|
||||
if (!NEEConfig.keepGhostitems) {
|
||||
draggedStack.stackSize = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||
if (button == 2) {
|
||||
draggedStack.stackSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -253,69 +244,118 @@ public class GuiEventHandler implements INEIGuiHandler {
|
||||
@SubscribeEvent
|
||||
public boolean handleMouseWheelInput(GuiScrollEvent event) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
boolean isPatternTerm = isPatternTerm(mc.currentScreen);
|
||||
boolean isInterface = event.guiScreen instanceof GuiInterface;
|
||||
if (isPatternTerm || isInterface) {
|
||||
Slot currentSlot = (event.guiScreen).getSlotAtPosition(event.mouseX, event.mouseY);
|
||||
if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) {
|
||||
// try to change current itemstack to next ingredient;
|
||||
if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.ingredient"))
|
||||
&& GuiUtils.isCraftingSlot(currentSlot)) {
|
||||
handleRecipeIngredientChange(event.guiScreen, currentSlot, event.scrollAmount);
|
||||
return true;
|
||||
} else if (Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.count"))) {
|
||||
NEENetworkHandler.getInstance()
|
||||
.sendToServer(new PacketStackCountChange(currentSlot.slotNumber, event.scrollAmount));
|
||||
return true;
|
||||
}
|
||||
Slot currentSlot = getFakeSlotAtPosition((GuiContainer) mc.currentScreen, event.mouseX, event.mouseY);
|
||||
|
||||
if (currentSlot != null) {
|
||||
// try to change current itemstack to next ingredient;
|
||||
if (NEIClientConfig.isKeyHashDown("nee.ingredient") && GuiUtils.isCraftingSlot(currentSlot)) {
|
||||
handleRecipeIngredientChange(event.guiScreen, currentSlot, event.scrollAmount);
|
||||
return true;
|
||||
} else if (NEIClientConfig.isKeyHashDown("nee.count")) {
|
||||
NEENetworkHandler.getInstance()
|
||||
.sendToServer(new PacketStackCountChange(currentSlot.slotNumber, event.scrollAmount));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) {
|
||||
List<Integer> craftingSlots = new ArrayList<>();
|
||||
int currentSlotIndex = currentSlot.getSlotIndex();
|
||||
PositionedStack currentIngredients = NEECraftingHandler.ingredients.get(INPUT_KEY + currentSlotIndex);
|
||||
if (currentIngredients != null && currentIngredients.items.length > 1) {
|
||||
int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients);
|
||||
if (currentStackIndex >= 0) {
|
||||
for (int j = 0; j < Math.abs(dWheel); j++) {
|
||||
currentStackIndex += (dWheel < 0) ? -1 : 1;
|
||||
if (currentStackIndex >= currentIngredients.items.length) {
|
||||
currentStackIndex = 0;
|
||||
} else if (currentStackIndex < 0) {
|
||||
currentStackIndex = currentIngredients.items.length - 1;
|
||||
}
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
|
||||
List<String> currenttip) {
|
||||
final Slot currentSlot = itemstack != null ? getFakeSlotAtPosition(gui, mousex, mousey) : null;
|
||||
|
||||
ItemStack currentStack = currentIngredients.items[currentStackIndex].copy();
|
||||
currentStack.stackSize = currentSlot.getStack().stackSize;
|
||||
if (currentSlot != null) {
|
||||
PositionedStack currentIngredients = NEEPatternTerminalHandler.ingredients
|
||||
.get(INPUT_KEY + currentSlot.getSlotIndex());
|
||||
if (currentIngredients != null && currentIngredients.items.length > 1
|
||||
&& currentIngredients.containsWithNBT(currentSlot.getStack())) {
|
||||
|
||||
if (NEEConfig.allowSynchronousSwitchIngredient) {
|
||||
for (Slot slot : getCraftingSlots(gui)) {
|
||||
if (this.acceptsFollowingTooltipLineHandler == null
|
||||
|| this.acceptsFollowingTooltipLineHandler.tooltipGUID != currentIngredients) {
|
||||
this.acceptsFollowingTooltipLineHandler = AcceptsFollowingTooltipLineHandler.of(
|
||||
currentIngredients,
|
||||
currentIngredients.getFilteredPermutations(),
|
||||
currentIngredients.item);
|
||||
}
|
||||
|
||||
PositionedStack slotIngredients = NEECraftingHandler.ingredients
|
||||
.get(INPUT_KEY + slot.getSlotIndex());
|
||||
|
||||
boolean areItemStackEqual = currentSlot.getHasStack() && slot.getHasStack()
|
||||
&& currentSlot.getStack().isItemEqual(slot.getStack())
|
||||
&& ItemStack.areItemStackTagsEqual(currentSlot.getStack(), slot.getStack());
|
||||
|
||||
boolean areIngredientEqual = slotIngredients != null
|
||||
&& currentIngredients.contains(slotIngredients.items[0]);
|
||||
|
||||
if (areItemStackEqual && areIngredientEqual) {
|
||||
craftingSlots.add(slot.slotNumber);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
craftingSlots.add(currentSlot.slotNumber);
|
||||
}
|
||||
NEENetworkHandler.getInstance()
|
||||
.sendToServer(new PacketSlotStackChange(currentStack, craftingSlots));
|
||||
if (this.acceptsFollowingTooltipLineHandler != null) {
|
||||
this.acceptsFollowingTooltipLineHandler.setActiveStack(currentIngredients.item);
|
||||
currenttip.add(
|
||||
GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsFollowingTooltipLineHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
final Slot currentSlot = getFakeSlotAtPosition(gui, mousex, mousey);
|
||||
|
||||
if (currentSlot != null) {
|
||||
|
||||
if (this.acceptsFollowingTooltipLineHandler != null) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName(
|
||||
"nee.ingredient",
|
||||
0,
|
||||
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
||||
I18n.format("neenergistics.gui.tooltip.ingredient.permutation"));
|
||||
}
|
||||
|
||||
hotkeys.put(
|
||||
NEIClientConfig
|
||||
.getKeyName("nee.count", 0, NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
||||
I18n.format("neenergistics.gui.tooltip.ingredient.count"));
|
||||
}
|
||||
|
||||
return hotkeys;
|
||||
}
|
||||
|
||||
private Slot getFakeSlotAtPosition(GuiContainer gui, int mousex, int mousey) {
|
||||
if (gui instanceof GuiInterface || isPatternTerm(gui)) {
|
||||
final Slot currentSlot = gui.getSlotAtPosition(mousex, mousey);
|
||||
if (currentSlot instanceof SlotFake && currentSlot.getHasStack()) {
|
||||
return currentSlot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) {
|
||||
final int currentSlotIndex = currentSlot.getSlotIndex();
|
||||
final PositionedStack currentIngredients = NEEPatternTerminalHandler.ingredients
|
||||
.get(INPUT_KEY + currentSlotIndex);
|
||||
|
||||
if (currentIngredients != null && currentIngredients.items.length > 1) {
|
||||
final List<Integer> craftingSlots = new ArrayList<>();
|
||||
final List<ItemStack> items = currentIngredients.getFilteredPermutations();
|
||||
final int currentStackIndex = ItemUtils.getPermutationIndex(currentSlot.getStack(), items);
|
||||
final ItemStack nextStack = items.get((items.size() - dWheel + currentStackIndex) % items.size());
|
||||
final ItemStack currentStack = currentIngredients.item;
|
||||
|
||||
if (NEEConfig.allowSynchronousSwitchIngredient) {
|
||||
for (Slot slot : getCraftingSlots(gui)) {
|
||||
final PositionedStack slotIngredients = NEEPatternTerminalHandler.ingredients
|
||||
.get(INPUT_KEY + slot.getSlotIndex());
|
||||
|
||||
if (slotIngredients != null && slotIngredients.containsWithNBT(nextStack)
|
||||
&& NEIServerUtils.areStacksSameTypeCraftingWithNBT(slotIngredients.item, currentStack)) {
|
||||
slotIngredients.setPermutationToRender(nextStack);
|
||||
craftingSlots.add(slot.slotNumber);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentIngredients.setPermutationToRender(nextStack);
|
||||
craftingSlots.add(currentSlot.slotNumber);
|
||||
}
|
||||
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(nextStack, craftingSlots));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
package com.github.vfyjxf.nee.client;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
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 codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
/**
|
||||
* Please note the difference between the GTNH NEI and the official NEI
|
||||
*/
|
||||
public class NEEContainerDrawHandler {
|
||||
|
||||
public static NEEContainerDrawHandler instance = new NEEContainerDrawHandler();
|
||||
|
||||
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 getRecipeIndicesMethod;
|
||||
private boolean drawRequestTooltip;
|
||||
private boolean drawMissingTooltip;
|
||||
private boolean drawCraftableTooltip;
|
||||
|
||||
public NEEContainerDrawHandler() {
|
||||
// gtnh nei support
|
||||
isGtnhNei = true;
|
||||
try {
|
||||
this.overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons");
|
||||
this.getRecipeIndicesMethod = GuiRecipe.class.getDeclaredMethod("getRecipeIndices");
|
||||
this.overlayButtonsField.setAccessible(true);
|
||||
this.getRecipeIndicesMethod.setAccessible(true);
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
isGtnhNei = false;
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
if (this.isCraftingTerm || this.isPatternTerm) {
|
||||
this.oldPage = guiRecipe.page;
|
||||
this.oldType = guiRecipe.recipetype;
|
||||
setOverlayButton(guiRecipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
|
||||
if (NEEConfig.drawHighlight && event.gui instanceof GuiRecipe) {
|
||||
if (this.isCraftingTerm || this.isPatternTerm) {
|
||||
GuiRecipe gui = (GuiRecipe) event.gui;
|
||||
|
||||
IRecipeHandler currentHandler = (IRecipeHandler) gui.currenthandlers.get(gui.recipetype);
|
||||
|
||||
if (NEECraftingHandler.isCraftingTableRecipe(currentHandler)) {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
for (GuiButton button : overlayButtons) {
|
||||
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 = (IRecipeHandler) gui.currenthandlers.get(gui.recipetype);
|
||||
int recipeIndex = -1;
|
||||
if (isGtnhNei) {
|
||||
try {
|
||||
final int OVERLAY_BUTTON_ID_START = 4;
|
||||
final List<Integer> indices = (List) getRecipeIndicesMethod.invoke(gui);
|
||||
final int refIndex = overlayButton.id - OVERLAY_BUTTON_ID_START;
|
||||
|
||||
if (refIndex >= 0 && refIndex < indices.size()) {
|
||||
recipeIndex = indices.get(refIndex);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
recipeIndex = gui.page * handler.recipiesPerPage() + i;
|
||||
}
|
||||
|
||||
if (recipeIndex >= 0 && handler != null && recipeIndex < handler.numRecipes()) {
|
||||
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 (this.isCraftingTerm) {
|
||||
if (this.drawRequestTooltip) {
|
||||
if (NEECraftingHelper.isIsPatternInterfaceExists()) {
|
||||
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"))));
|
||||
} else {
|
||||
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"))));
|
||||
}
|
||||
}
|
||||
if (this.drawMissingTooltip) {
|
||||
tooltips.add(EnumChatFormatting.RED + I18n.format("neenergistics.gui.tooltip.missing"));
|
||||
}
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
package com.github.vfyjxf.nee.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IDefinitions;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiNumberBox;
|
||||
import appeng.client.gui.widgets.GuiTabButton;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.parts.reporting.PartCraftingTerminal;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
public class GuiCraftingAmount extends AEBaseGui {
|
||||
|
||||
private GuiNumberBox amountToCraft;
|
||||
private GuiTabButton originalGuiBtn;
|
||||
|
||||
private GuiButton next;
|
||||
|
||||
private GuiButton plus1;
|
||||
private GuiButton plus10;
|
||||
private GuiButton plus100;
|
||||
private GuiButton plus1000;
|
||||
private GuiButton minus1;
|
||||
private GuiButton minus10;
|
||||
private GuiButton minus100;
|
||||
private GuiButton minus1000;
|
||||
|
||||
private GuiBridge originalGui;
|
||||
|
||||
private boolean isWirelessCrafting;
|
||||
|
||||
@Reflected
|
||||
public GuiCraftingAmount(final InventoryPlayer inventoryPlayer, final ITerminalHost te) {
|
||||
super(new ContainerCraftingAmount(inventoryPlayer, te));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
final int a = AEConfig.instance.craftItemsByStackAmounts(0);
|
||||
final int b = AEConfig.instance.craftItemsByStackAmounts(1);
|
||||
final int c = AEConfig.instance.craftItemsByStackAmounts(2);
|
||||
final int d = AEConfig.instance.craftItemsByStackAmounts(3);
|
||||
|
||||
this.buttonList.add(this.plus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 26, 22, 20, "+" + a));
|
||||
this.buttonList.add(this.plus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 26, 28, 20, "+" + b));
|
||||
this.buttonList.add(this.plus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 26, 32, 20, "+" + c));
|
||||
this.buttonList.add(this.plus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 26, 38, 20, "+" + d));
|
||||
|
||||
this.buttonList.add(this.minus1 = new GuiButton(0, this.guiLeft + 20, this.guiTop + 75, 22, 20, "-" + a));
|
||||
this.buttonList.add(this.minus10 = new GuiButton(0, this.guiLeft + 48, this.guiTop + 75, 28, 20, "-" + b));
|
||||
this.buttonList.add(this.minus100 = new GuiButton(0, this.guiLeft + 82, this.guiTop + 75, 32, 20, "-" + c));
|
||||
this.buttonList.add(this.minus1000 = new GuiButton(0, this.guiLeft + 120, this.guiTop + 75, 38, 20, "-" + d));
|
||||
|
||||
this.buttonList.add(
|
||||
this.next = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal()));
|
||||
|
||||
ItemStack myIcon = null;
|
||||
final Object target = ((AEBaseContainer) this.inventorySlots).getTarget();
|
||||
final IDefinitions definitions = AEApi.instance().definitions();
|
||||
final IParts parts = definitions.parts();
|
||||
|
||||
if (target instanceof PartCraftingTerminal) {
|
||||
for (final ItemStack stack : parts.craftingTerminal().maybeStack(1).asSet()) {
|
||||
myIcon = stack;
|
||||
}
|
||||
this.originalGui = GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
}
|
||||
if (Loader.isModLoaded(ModIDs.WCT) && GuiUtils.isWirelessTerminalGuiObject(target)) {
|
||||
myIcon = new ItemStack(ItemEnum.WIRELESS_CRAFTING_TERMINAL.getItem());
|
||||
this.isWirelessCrafting = true;
|
||||
}
|
||||
|
||||
if (this.originalGui != null && myIcon != null) {
|
||||
this.buttonList.add(
|
||||
this.originalGuiBtn = new GuiTabButton(
|
||||
this.guiLeft + 154,
|
||||
this.guiTop,
|
||||
myIcon,
|
||||
myIcon.getDisplayName(),
|
||||
itemRender));
|
||||
}
|
||||
if (this.isWirelessCrafting && myIcon != null) {
|
||||
this.buttonList.add(
|
||||
this.originalGuiBtn = new GuiTabButton(
|
||||
this.guiLeft + 154,
|
||||
this.guiTop,
|
||||
myIcon,
|
||||
myIcon.getDisplayName(),
|
||||
itemRender));
|
||||
}
|
||||
|
||||
this.amountToCraft = new GuiNumberBox(
|
||||
this.fontRendererObj,
|
||||
this.guiLeft + 62,
|
||||
this.guiTop + 57,
|
||||
59,
|
||||
this.fontRendererObj.FONT_HEIGHT,
|
||||
Integer.class);
|
||||
this.amountToCraft.setEnableBackgroundDrawing(false);
|
||||
this.amountToCraft.setMaxStringLength(16);
|
||||
this.amountToCraft.setTextColor(0xFFFFFF);
|
||||
this.amountToCraft.setVisible(true);
|
||||
this.amountToCraft.setFocused(true);
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.fontRendererObj.drawString(GuiText.SelectAmount.getLocal(), 8, 6, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) {
|
||||
this.next.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal();
|
||||
|
||||
this.bindTexture("guis/craftAmt.png");
|
||||
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
try {
|
||||
Long.parseLong(this.amountToCraft.getText());
|
||||
this.next.enabled = this.amountToCraft.getText().length() > 0;
|
||||
} catch (final NumberFormatException e) {
|
||||
this.next.enabled = false;
|
||||
}
|
||||
|
||||
this.amountToCraft.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float btn) {
|
||||
super.drawScreen(mouseX, mouseY, btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) {
|
||||
if (!this.checkHotbarKeys(key)) {
|
||||
if (key == 28) {
|
||||
this.actionPerformed(this.next);
|
||||
}
|
||||
if ((key == 211 || key == 205
|
||||
|| key == 203
|
||||
|| key == 14
|
||||
|| character == '-'
|
||||
|| Character.isDigit(character)) && this.amountToCraft.textboxKeyTyped(character, key)) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
final long result = Long.parseLong(out);
|
||||
if (result < 0) {
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
} else {
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(final GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
try {
|
||||
|
||||
if (btn == this.originalGuiBtn) {
|
||||
if (!this.isWirelessCrafting) {
|
||||
NetworkHandler.instance.sendToServer(new PacketSwitchGuis(this.originalGui));
|
||||
} else if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
openWirelessCraftingGui();
|
||||
}
|
||||
}
|
||||
|
||||
if (btn == this.next) {
|
||||
NEENetworkHandler.getInstance().sendToServer(
|
||||
new PacketCraftingRequest(Integer.parseInt(this.amountToCraft.getText()), isShiftKeyDown()));
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
// nope..
|
||||
this.amountToCraft.setText("1");
|
||||
}
|
||||
|
||||
final boolean isPlus = btn == this.plus1 || btn == this.plus10 || btn == this.plus100 || btn == this.plus1000;
|
||||
final boolean isMinus = btn == this.minus1 || btn == this.minus10
|
||||
|| btn == this.minus100
|
||||
|| btn == this.minus1000;
|
||||
|
||||
if (isPlus || isMinus) {
|
||||
this.addQty(this.getQty(btn));
|
||||
}
|
||||
}
|
||||
|
||||
private void addQty(final int i) {
|
||||
try {
|
||||
String out = this.amountToCraft.getText();
|
||||
|
||||
boolean fixed = false;
|
||||
while (out.startsWith("0") && out.length() > 1) {
|
||||
out = out.substring(1);
|
||||
fixed = true;
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
this.amountToCraft.setText(out);
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out = "0";
|
||||
}
|
||||
|
||||
long result = Integer.parseInt(out);
|
||||
|
||||
if (result == 1 && i > 1) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
result += i;
|
||||
if (result < 1) {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
out = Long.toString(result);
|
||||
Integer.parseInt(out);
|
||||
this.amountToCraft.setText(out);
|
||||
} catch (final NumberFormatException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBackground() {
|
||||
return "guis/craftAmt.png";
|
||||
}
|
||||
|
||||
@Optional.Method(modid = ModIDs.WCT)
|
||||
private void openWirelessCraftingGui() {
|
||||
net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer(
|
||||
new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketSwitchGuis(Reference.GUI_WCT));
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.github.vfyjxf.nee.container;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotInaccessible;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
|
||||
public class ContainerCraftingAmount extends AEBaseContainer {
|
||||
|
||||
private final Slot resultSlot;
|
||||
private ItemStack resultStack;
|
||||
private NBTTagCompound recipe;
|
||||
|
||||
public ContainerCraftingAmount(InventoryPlayer ip, Object anchor) {
|
||||
super(ip, anchor);
|
||||
this.resultSlot = new SlotInaccessible(new AppEngInternalInventory(null, 1), 0, 34, 53);
|
||||
this.addSlotToContainer(resultSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
this.verifyPermissions(SecurityPermissions.CRAFT, false);
|
||||
}
|
||||
|
||||
public IGrid getGrid() {
|
||||
final IActionHost h = ((IActionHost) this.getTarget());
|
||||
return h.getActionableNode().getGrid();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.getPlayerInv().player.worldObj;
|
||||
}
|
||||
|
||||
public BaseActionSource getActionSrc() {
|
||||
return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget());
|
||||
}
|
||||
|
||||
public NBTTagCompound getRecipe() {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public Slot getResultSlot() {
|
||||
return resultSlot;
|
||||
}
|
||||
|
||||
public ItemStack getResultStack() {
|
||||
return resultStack;
|
||||
}
|
||||
|
||||
public void setResultStack(ItemStack resultStack) {
|
||||
this.resultStack = resultStack;
|
||||
}
|
||||
|
||||
public void setRecipe(NBTTagCompound recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.github.vfyjxf.nee.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
|
||||
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ContainerCraftingConfirm extends ContainerCraftConfirm {
|
||||
|
||||
private TilePatternInterface tile;
|
||||
private int patternIndex;
|
||||
private boolean hasWorkCommitted = false;
|
||||
|
||||
public ContainerCraftingConfirm(InventoryPlayer ip, ITerminalHost te) {
|
||||
super(ip, te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJob() {
|
||||
if (Platform.isServer()) {
|
||||
hasWorkCommitted = true;
|
||||
}
|
||||
super.startJob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
if (Platform.isServer() && tile != null && !hasWorkCommitted) {
|
||||
this.tile.getPatternInventory().setInventorySlotContents(patternIndex, null);
|
||||
this.tile.updateCraftingList();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTile(TilePatternInterface tile) {
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public void setPatternIndex(int patternIndex) {
|
||||
this.patternIndex = patternIndex;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import appeng.util.Platform;
|
||||
|
||||
public class ContainerPatternInterface extends AEBaseContainer implements IAEAppEngInventory {
|
||||
|
||||
private final InventoryPlayer playerInventory;
|
||||
private final AppEngInternalInventory recipeInv;
|
||||
private final AppEngInternalInventory patterns;
|
||||
private final SlotRestrictedInput[] patternSlots = new SlotRestrictedInput[9];
|
||||
@@ -38,7 +37,6 @@ public class ContainerPatternInterface extends AEBaseContainer implements IAEApp
|
||||
|
||||
public ContainerPatternInterface(InventoryPlayer playerInventory, TilePatternInterface tile) {
|
||||
super(playerInventory, tile);
|
||||
this.playerInventory = playerInventory;
|
||||
this.recipeInv = tile.getGirdInventory();
|
||||
this.patterns = tile.getPatternInventory();
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.github.vfyjxf.nee.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
|
||||
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class WCTContainerCraftingConfirm extends ContainerCraftConfirm {
|
||||
|
||||
private TilePatternInterface tile;
|
||||
private int patternIndex;
|
||||
private boolean hasWorkCommitted = false;
|
||||
|
||||
public WCTContainerCraftingConfirm(InventoryPlayer ip, ITerminalHost te) {
|
||||
super(ip, te);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJob() {
|
||||
if (Platform.isServer()) {
|
||||
hasWorkCommitted = true;
|
||||
}
|
||||
super.startJob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
if (Platform.isServer() && tile != null && !hasWorkCommitted) {
|
||||
this.tile.getPatternInventory().setInventorySlotContents(patternIndex, null);
|
||||
this.tile.updateCraftingList();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTile(TilePatternInterface tile) {
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public void setPatternIndex(int patternIndex) {
|
||||
this.patternIndex = patternIndex;
|
||||
}
|
||||
}
|
||||
@@ -1,321 +0,0 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import static com.github.vfyjxf.nee.processor.RecipeProcessor.NULL_IDENTIFIER;
|
||||
import static com.github.vfyjxf.nee.utils.GuiUtils.isPatternTerm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.github.vfyjxf.nee.config.ItemCombination;
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
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.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.nei.FluidPatternTerminalRecipeTransferHandler;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class NEECraftingHandler implements IOverlayHandler {
|
||||
|
||||
public static final String INPUT_KEY = "#";
|
||||
public static final String OUTPUT_KEY = "Outputs";
|
||||
public static Map<String, PositionedStack> ingredients = new HashMap<>();
|
||||
|
||||
public static final NEECraftingHandler INSTANCE = new NEECraftingHandler();
|
||||
private static Class<?> knowledgeInscriberClz;
|
||||
private static Class<?> itemAspectClz;
|
||||
private static Class<?> guiExtremeAutoCrafterClz;
|
||||
|
||||
static {
|
||||
try {
|
||||
knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
try {
|
||||
itemAspectClz = Class.forName("com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect");
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
try {
|
||||
guiExtremeAutoCrafterClz = Class
|
||||
.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter");
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
}
|
||||
|
||||
public static boolean isCraftingTableRecipe(IRecipeHandler recipe) {
|
||||
if (recipe instanceof TemplateRecipeHandler) {
|
||||
TemplateRecipeHandler templateRecipeHandler = (TemplateRecipeHandler) recipe;
|
||||
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
|
||||
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Optional.Method(modid = ModIDs.FC)
|
||||
private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
FluidPatternTerminalRecipeTransferHandler.INSTANCE.overlayRecipe(firstGui, recipe, recipeIndex, shift);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if (isPatternTerm(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
|
||||
if (Loader.isModLoaded(ModIDs.FC)) fluidCraftOverlayRecipe(firstGui, recipe, recipeIndex, shift);
|
||||
} else {
|
||||
knowledgeInscriberHandler(firstGui, recipe, recipeIndex);
|
||||
extremeAutoCrafterHandler(firstGui, recipe, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
if (isCraftingTableRecipe(recipe)) {
|
||||
return packCraftingTableRecipe(recipe, recipeIndex);
|
||||
} else {
|
||||
return packProcessRecipe(recipe, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
NBTTagCompound recipeOutputs = new NBTTagCompound();
|
||||
String identifier = recipe instanceof TemplateRecipeHandler ? recipe.getOverlayIdentifier() : NULL_IDENTIFIER;
|
||||
if (identifier == null) {
|
||||
identifier = NULL_IDENTIFIER;
|
||||
}
|
||||
int inputIndex = 0;
|
||||
int outputIndex = 0;
|
||||
// get all recipe inputs and other stacks,use first item
|
||||
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
|
||||
if (processor.getAllOverlayIdentifier().contains(identifier)) {
|
||||
List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
|
||||
List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
|
||||
String recipeProcessorId = processor.getRecipeProcessorId();
|
||||
List<PositionedStack> mergedInputs = new ArrayList<>();
|
||||
|
||||
if (!inputs.isEmpty() && !outputs.isEmpty()) {
|
||||
NEECraftingHandler.ingredients.clear();
|
||||
for (PositionedStack positionedStack : inputs) {
|
||||
ItemStack currentStack = positionedStack.items[0];
|
||||
boolean find = false;
|
||||
ItemCombination currentValue = ItemCombination.valueOf(NEEConfig.itemCombinationMode);
|
||||
if (currentValue != ItemCombination.DISABLED
|
||||
&& processor.mergeStacks(recipe, recipeIndex, identifier)) {
|
||||
boolean isWhitelist = currentValue == ItemCombination.WHITELIST
|
||||
&& Arrays.asList(NEEConfig.itemCombinationWhitelist).contains(identifier);
|
||||
if (currentValue == ItemCombination.ENABLED || isWhitelist) {
|
||||
for (PositionedStack storedStack : mergedInputs) {
|
||||
ItemStack firstStack = storedStack.items[0];
|
||||
boolean areItemStackEqual = firstStack.isItemEqual(currentStack)
|
||||
&& ItemStack.areItemStackTagsEqual(firstStack, currentStack);
|
||||
if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize)
|
||||
<= firstStack.getMaxStackSize()) {
|
||||
find = true;
|
||||
storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
mergedInputs.add(positionedStack.copy());
|
||||
}
|
||||
}
|
||||
for (PositionedStack positionedStack : mergedInputs) {
|
||||
ItemStack currentStack = positionedStack.items[0];
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
|
||||
if (preferModItem != null) {
|
||||
currentStack = preferModItem;
|
||||
currentStack.stackSize = positionedStack.items[0].stackSize;
|
||||
}
|
||||
|
||||
for (ItemStack stack : positionedStack.items) {
|
||||
if (Platform.isRecipePrioritized(stack)
|
||||
|| ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
|
||||
currentStack = stack.copy();
|
||||
currentStack.stackSize = positionedStack.items[0].stackSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
currentStack.setItemDamage(0);
|
||||
}
|
||||
if (currentStack.stackSize < 1) {
|
||||
currentStack.stackSize = 1;
|
||||
}
|
||||
|
||||
recipeInputs.setTag(
|
||||
"#" + inputIndex,
|
||||
ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
|
||||
NEECraftingHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack);
|
||||
inputIndex++;
|
||||
}
|
||||
|
||||
for (PositionedStack positionedStack : outputs) {
|
||||
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack outputStack = positionedStack.item.copy();
|
||||
if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
outputStack.setItemDamage(0);
|
||||
}
|
||||
if (outputStack.stackSize < 1) {
|
||||
outputStack.stackSize = 1;
|
||||
}
|
||||
|
||||
recipeOutputs.setTag(
|
||||
OUTPUT_KEY + outputIndex,
|
||||
ItemUtils.writeItemStackToNBT(outputStack, new NBTTagCompound()));
|
||||
outputIndex++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PacketNEIPatternRecipe(recipeInputs, recipeOutputs);
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
NEECraftingHandler.ingredients.clear();
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
int slotIndex = col + row * 3;
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.items[0];
|
||||
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
if (preferModItem != null) {
|
||||
stack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
ItemUtils.transformGTTool(stack);
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
stack.setItemDamage(0);
|
||||
}
|
||||
|
||||
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
|
||||
NEECraftingHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
|
||||
}
|
||||
}
|
||||
return new PacketNEIPatternRecipe(recipeInputs, null);
|
||||
}
|
||||
|
||||
private void knowledgeInscriberHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
if (knowledgeInscriberClz != null && knowledgeInscriberClz.isInstance(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packetArcaneRecipe(recipe, recipeIndex));
|
||||
}
|
||||
}
|
||||
|
||||
private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
if (itemAspectClz != null) {
|
||||
ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem()));
|
||||
}
|
||||
for (PositionedStack positionedStack : ingredients) {
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely);
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.item;
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
return new PacketArcaneRecipe(recipeInputs);
|
||||
}
|
||||
|
||||
private void extremeAutoCrafterHandler(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
if (guiExtremeAutoCrafterClz != null && guiExtremeAutoCrafterClz.isInstance(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex));
|
||||
}
|
||||
}
|
||||
|
||||
private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
for (PositionedStack positionedStack : ingredients) {
|
||||
int col = (positionedStack.relx - 3) / 18;
|
||||
int row = (positionedStack.rely - 3) / 18;
|
||||
if (positionedStack.rely == 129) {
|
||||
col = (positionedStack.relx - 2) / 18;
|
||||
}
|
||||
int slotIndex = col + row * 9;
|
||||
ItemStack currentStack = positionedStack.items[0];
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
if (preferModItem != null) {
|
||||
currentStack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack stack : positionedStack.items) {
|
||||
if (ItemUtils.isPreferItems(stack)) {
|
||||
currentStack = stack.copy();
|
||||
}
|
||||
}
|
||||
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
|
||||
}
|
||||
return new PacketExtremeRecipe(recipeInputs);
|
||||
}
|
||||
|
||||
private int getSlotIndex(int xy) {
|
||||
switch (xy) {
|
||||
case 7533:
|
||||
return 1;
|
||||
case 10333:
|
||||
return 2;
|
||||
case 4960:
|
||||
return 3;
|
||||
case 7660:
|
||||
return 4;
|
||||
case 10360:
|
||||
return 5;
|
||||
case 4987:
|
||||
return 6;
|
||||
case 7687:
|
||||
return 7;
|
||||
case 10387:
|
||||
return 8;
|
||||
case 4832:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,332 +0,0 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.utils.GuiUtils.isGuiCraftingTerm;
|
||||
import static com.github.vfyjxf.nee.utils.GuiUtils.isPatternTerm;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.github.vfyjxf.nee.NotEnoughEnergistics;
|
||||
import com.github.vfyjxf.nee.client.NEEContainerDrawHandler;
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
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;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class NEECraftingHelper implements IOverlayHandler {
|
||||
|
||||
public static final NEECraftingHelper INSTANCE = new NEECraftingHelper();
|
||||
public static IngredientTracker tracker = null;
|
||||
public static boolean noPreview = false;
|
||||
|
||||
private static boolean isPatternInterfaceExists = false;
|
||||
|
||||
public static final int RECIPE_LENGTH = 9;
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
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 PacketOpenCraftAmount(packCraftingRecipe(recipe, recipeIndex)));
|
||||
isPatternInterfaceExists = false;
|
||||
} else {
|
||||
tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
|
||||
if (!tracker.getRequireStacks().isEmpty()) {
|
||||
tracker.requestNextIngredient();
|
||||
} else {
|
||||
moveItems(firstGui, recipe, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
moveItems(firstGui, recipe, recipeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NBTTagCompound packCraftingRecipe(IRecipeHandler recipeHandler, int recipeIndex) {
|
||||
final NBTTagCompound recipe = new NBTTagCompound();
|
||||
final List<PositionedStack> ingredients = recipeHandler.getIngredientStacks(recipeIndex);
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
int slotIndex = col + row * 3;
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.items[0];
|
||||
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
if (preferModItem != null) {
|
||||
stack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
stack.setItemDamage(0);
|
||||
}
|
||||
|
||||
recipe.setTag(INPUT_KEY + slotIndex, stack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
PositionedStack resultStack = recipeHandler.getResultStack(recipeIndex);
|
||||
if (resultStack.item != null) {
|
||||
recipe.setTag(OUTPUT_KEY, resultStack.item.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
private void moveItems(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
try {
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
if (firstGui instanceof GuiCraftingTerm) {
|
||||
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false));
|
||||
// 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));
|
||||
}
|
||||
if (packetSize >= 0) {
|
||||
NetworkHandler.instance.sendToServer(packet);
|
||||
} else {
|
||||
NotEnoughEnergistics.logger.error("Can't get packet size!");
|
||||
}
|
||||
} else if (GuiUtils.isGuiWirelessCrafting(firstGui)) {
|
||||
moveItemsForWirelessCrafting(firstGui, ingredients);
|
||||
}
|
||||
} catch (final Exception | Error ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
private boolean testSize(final NBTTagCompound recipe) throws IOException {
|
||||
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
final DataOutputStream outputStream = new DataOutputStream(bytes);
|
||||
CompressedStreamTools.writeCompressed(recipe, outputStream);
|
||||
return bytes.size() > 3 * 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private NBTTagCompound packIngredients(GuiContainer gui, List<PositionedStack> ingredients, boolean limited)
|
||||
throws IOException {
|
||||
final NBTTagCompound recipe = new NBTTagCompound();
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
for (final Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
|
||||
if (isCraftingMatrixSlot(gui, slot)) {
|
||||
if (slot.getSlotIndex() == col + row * 3) {
|
||||
final NBTTagList tags = new NBTTagList();
|
||||
final List<ItemStack> list = new LinkedList<>();
|
||||
|
||||
// prefer pure crystals.
|
||||
for (int x = 0; x < positionedStack.items.length; x++) {
|
||||
if (Platform.isRecipePrioritized(positionedStack.items[x])) {
|
||||
list.add(0, positionedStack.items[x]);
|
||||
} else {
|
||||
list.add(positionedStack.items[x]);
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : list) {
|
||||
final NBTTagCompound tag = new NBTTagCompound();
|
||||
is.writeToNBT(tag);
|
||||
tags.appendTag(tag);
|
||||
if (limited) {
|
||||
final NBTTagCompound test = new NBTTagCompound();
|
||||
test.setTag("#" + slot.getSlotIndex(), tags);
|
||||
if (testSize(test)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipe.setTag("#" + slot.getSlotIndex(), tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
private boolean isCraftingMatrixSlot(GuiContainer gui, Slot slot) {
|
||||
if (gui instanceof GuiCraftingTerm) {
|
||||
return slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix;
|
||||
} else if (GuiUtils.isGuiWirelessCrafting(gui)) {
|
||||
return slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix;
|
||||
}
|
||||
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 = ModIDs.WCT)
|
||||
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) {
|
||||
if (NEEConfig.noShift) {
|
||||
// make nei's transfer system doesn't require presses shift
|
||||
if (event.gui instanceof GuiRecipe) {
|
||||
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
|
||||
List<GuiButton> overlayButtons = null;
|
||||
final int OVERLAY_BUTTON_ID_START = 4;
|
||||
boolean isGtnhNei = true;
|
||||
try {
|
||||
Field overlayButtonsField = GuiRecipe.class.getDeclaredField("overlayButtons");
|
||||
overlayButtonsField.setAccessible(true);
|
||||
overlayButtons = new ArrayList<>(Arrays.asList((GuiButton[]) overlayButtonsField.get(guiRecipe)));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
isGtnhNei = false;
|
||||
}
|
||||
if (!isGtnhNei) {
|
||||
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 (event.button.id >= OVERLAY_BUTTON_ID_START
|
||||
&& event.button.id < OVERLAY_BUTTON_ID_START + overlayButtons.size()) {
|
||||
boolean isPatternTerm = isPatternTerm(guiRecipe.firstGui);
|
||||
boolean isCraftingTerm = isGuiCraftingTerm(guiRecipe.firstGui);
|
||||
if (isCraftingTerm || isPatternTerm) {
|
||||
IRecipeHandler handler = (IRecipeHandler) guiRecipe.currenthandlers.get(guiRecipe.recipetype);
|
||||
int recipeIndex = -1;
|
||||
if (isGtnhNei) {
|
||||
try {
|
||||
final List<Integer> indices = (List) NEEContainerDrawHandler.instance.getRecipeIndicesMethod
|
||||
.invoke(guiRecipe);
|
||||
final int refIndex = event.button.id - OVERLAY_BUTTON_ID_START;
|
||||
|
||||
if (refIndex >= 0 && refIndex < indices.size()) {
|
||||
recipeIndex = indices.get(refIndex);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
int recipesPerPage = 2;
|
||||
recipeIndex = guiRecipe.page * recipesPerPage + event.button.id - OVERLAY_BUTTON_ID_START;
|
||||
}
|
||||
|
||||
if (handler != null && recipeIndex >= 0 && recipeIndex < handler.numRecipes()) {
|
||||
final IOverlayHandler overlayHandler = handler
|
||||
.getOverlayHandler(guiRecipe.firstGui, recipeIndex);
|
||||
Minecraft.getMinecraft().displayGuiScreen(guiRecipe.firstGui);
|
||||
overlayHandler.overlayRecipe(
|
||||
guiRecipe.firstGui,
|
||||
(IRecipeHandler) guiRecipe.currenthandlers.get(guiRecipe.recipetype),
|
||||
recipeIndex,
|
||||
NEIClientUtils.shiftKey());
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (event.gui instanceof GuiRecipe) {
|
||||
GuiRecipe guiRecipe = (GuiRecipe) event.gui;
|
||||
GuiContainer firstGui = guiRecipe.firstGui;
|
||||
if (GuiUtils.isGuiCraftingTerm(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("PatternInterface.check"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setIsPatternInterfaceExists(boolean isPatternInterfaceExists) {
|
||||
NEECraftingHelper.isPatternInterfaceExists = isPatternInterfaceExists;
|
||||
}
|
||||
|
||||
public static boolean isIsPatternInterfaceExists() {
|
||||
return isPatternInterfaceExists;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.Ingredient;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.client.gui.GuiFluidCraftAmount;
|
||||
import com.glodblock.github.client.gui.base.FCGuiAmount;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.implementations.GuiAmount;
|
||||
import appeng.client.gui.implementations.GuiCraftAmount;
|
||||
import appeng.client.gui.implementations.GuiCraftConfirm;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import thaumicenergistics.common.network.packet.server.Packet_S_ArcaneCraftingTerminal;
|
||||
|
||||
public class NEECraftingPreviewHandler {
|
||||
|
||||
public static final NEECraftingPreviewHandler instance = new NEECraftingPreviewHandler();
|
||||
|
||||
private boolean isPatternInterfaceExists = false;
|
||||
|
||||
private NBTTagCompound patternCompound = null;
|
||||
private IngredientTracker tracker = null;
|
||||
private boolean isAutoStart = false;
|
||||
private int resultStackSize = 0;
|
||||
private String modID = "";
|
||||
|
||||
private NEECraftingPreviewHandler() {}
|
||||
|
||||
public boolean handle(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
final PositionedStack pStack = recipe.getResultStack(recipeIndex);
|
||||
this.isAutoStart = NEIClientConfig.isKeyHashDown("nee.nopreview");
|
||||
this.modID = getModID(firstGui.inventorySlots);
|
||||
this.resultStackSize = 0;
|
||||
this.patternCompound = null;
|
||||
this.tracker = null;
|
||||
|
||||
if ((this.isAutoStart || NEIClientConfig.isKeyHashDown("nee.preview")) && !this.modID.isEmpty()) {
|
||||
firstGui.mc.displayGuiScreen(firstGui);
|
||||
|
||||
if (pStack != null) {
|
||||
this.resultStackSize = pStack.item.stackSize;
|
||||
}
|
||||
|
||||
if (pStack != null && existsRecipeResult(firstGui, pStack)) {
|
||||
|
||||
if (this.isAutoStart) {
|
||||
final PacketCraftingRequest craftingRequest = new PacketCraftingRequest(
|
||||
this.modID,
|
||||
PacketCraftingRequest.COMMAND_OPEN_CRAFT_CONFIRM,
|
||||
pStack.item.writeToNBT(new NBTTagCompound()),
|
||||
pStack.item.stackSize,
|
||||
true);
|
||||
NEENetworkHandler.getInstance().sendToServer(craftingRequest);
|
||||
} else {
|
||||
openCraftAmount(firstGui, pStack.item);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (pStack != null && this.isPatternInterfaceExists && isCraftingTableRecipe(recipe)) {
|
||||
this.patternCompound = getPatternStack(recipe, recipeIndex, Minecraft.getMinecraft().theWorld);
|
||||
|
||||
if (this.isAutoStart) {
|
||||
final PacketCraftingRequest craftingRequest = new PacketCraftingRequest(
|
||||
this.modID,
|
||||
PacketCraftingRequest.COMMAND_CREATE_PATTERN,
|
||||
this.patternCompound,
|
||||
pStack.item.stackSize,
|
||||
true);
|
||||
NEENetworkHandler.getInstance().sendToServer(craftingRequest);
|
||||
} else {
|
||||
openCraftAmount(firstGui, pStack.item);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
||||
this.tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
|
||||
|
||||
if (this.tracker.hasNext()) {
|
||||
|
||||
if (this.isAutoStart) {
|
||||
requestNextIngredient();
|
||||
} else if (pStack != null) {
|
||||
openCraftAmount(firstGui, pStack.item);
|
||||
} else {
|
||||
PositionedStack otherStack = null;
|
||||
|
||||
for (PositionedStack positionedStack : recipe.getOtherStacks(recipeIndex)) {
|
||||
otherStack = positionedStack;
|
||||
break;
|
||||
}
|
||||
|
||||
if (otherStack != null) {
|
||||
this.resultStackSize = otherStack.item.stackSize;
|
||||
openCraftAmount(firstGui, otherStack.item);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
this.tracker = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void openCraftAmount(GuiContainer firstGui, ItemStack itemstack) {
|
||||
final IAEItemStack aeItemStack = AEItemStack.create(itemstack);
|
||||
|
||||
if (this.modID.equals(ModIDs.ThE)) {
|
||||
Packet_S_ArcaneCraftingTerminal.sendAutoCraft(Minecraft.getMinecraft().thePlayer, aeItemStack);
|
||||
} else if (this.modID.equals(ModIDs.FC)) {
|
||||
((AEBaseContainer) firstGui.inventorySlots).setTargetStack(aeItemStack);
|
||||
com.glodblock.github.network.CPacketInventoryAction packet = new com.glodblock.github.network.CPacketInventoryAction(
|
||||
InventoryAction.AUTO_CRAFT,
|
||||
0,
|
||||
0);
|
||||
com.glodblock.github.FluidCraft.proxy.netHandler.sendToServer(packet);
|
||||
} else if (this.modID.equals(ModIDs.WCT)) {
|
||||
((AEBaseContainer) firstGui.inventorySlots).setTargetStack(aeItemStack);
|
||||
net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction packet = new net.p455w0rd.wirelesscraftingterminal.core.sync.packets.PacketInventoryAction(
|
||||
InventoryAction.AUTO_CRAFT,
|
||||
0,
|
||||
0);
|
||||
net.p455w0rd.wirelesscraftingterminal.core.sync.network.NetworkHandler.instance.sendToServer(packet);
|
||||
} else if (this.modID.equals("AE")) {
|
||||
((AEBaseContainer) firstGui.inventorySlots).setTargetStack(aeItemStack);
|
||||
NetworkHandler.instance.sendToServer(new PacketInventoryAction(InventoryAction.AUTO_CRAFT, 0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiCraftConfirmOpen(GuiOpenEvent event) {
|
||||
final GuiScreen old = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if (this.patternCompound != null && old instanceof GuiCraftConfirm) {
|
||||
this.patternCompound = null;
|
||||
}
|
||||
|
||||
if (this.tracker != null && old instanceof GuiCraftConfirm) {
|
||||
if (old != null && this.tracker.hasNext()) {
|
||||
requestNextIngredient();
|
||||
} else {
|
||||
this.tracker = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
|
||||
if ((this.tracker != null || this.patternCompound != null) && event.gui instanceof GuiContainer gui) {
|
||||
final int craftAmount = getCraftAmount(gui, event.button);
|
||||
|
||||
if (craftAmount == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.tracker != null) {
|
||||
final int craftMultiplier = (int) Math.ceil((1f * craftAmount) / this.resultStackSize);
|
||||
this.isAutoStart = this.isAutoStart || GuiScreen.isShiftKeyDown();
|
||||
|
||||
for (Ingredient ingr : this.tracker.getIngredients()) {
|
||||
ingr.setRequireCount(ingr.getRequireCount() * craftMultiplier);
|
||||
}
|
||||
|
||||
this.tracker.calculateIngredients();
|
||||
|
||||
requestNextIngredient();
|
||||
event.setCanceled(true);
|
||||
} else if (this.patternCompound != null) {
|
||||
PacketCraftingRequest craftingRequest = new PacketCraftingRequest(
|
||||
this.modID,
|
||||
PacketCraftingRequest.COMMAND_CREATE_PATTERN,
|
||||
this.patternCompound,
|
||||
craftAmount,
|
||||
GuiScreen.isShiftKeyDown());
|
||||
NEENetworkHandler.getInstance().sendToServer(craftingRequest);
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Post event) {
|
||||
|
||||
if ((this.tracker != null || this.patternCompound != null) && event.gui instanceof GuiCraftConfirm guiConfirm
|
||||
&& getCancelButton(guiConfirm) == event.button) {
|
||||
|
||||
if (this.patternCompound != null) {
|
||||
PacketCraftingRequest craftingRequest = new PacketCraftingRequest(
|
||||
this.modID,
|
||||
PacketCraftingRequest.COMMAND_REMOVE_PATTERN,
|
||||
this.patternCompound,
|
||||
0,
|
||||
false);
|
||||
NEENetworkHandler.getInstance().sendToServer(craftingRequest);
|
||||
}
|
||||
|
||||
this.patternCompound = null;
|
||||
this.tracker = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static GuiButton getCancelButton(GuiCraftConfirm gui) {
|
||||
return ReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel");
|
||||
}
|
||||
|
||||
private static int getCraftAmount(GuiContainer screen, GuiButton button) {
|
||||
|
||||
try {
|
||||
if (Loader.isModLoaded(ModIDs.FC) && screen instanceof GuiFluidCraftAmount gui) {
|
||||
|
||||
if (ReflectionHelper.getPrivateValue(FCGuiAmount.class, gui, "submit") == button) {
|
||||
return (int) ReflectionHelper.findMethod(FCGuiAmount.class, gui, new String[] { "getAmount" })
|
||||
.invoke(gui);
|
||||
}
|
||||
|
||||
} else if (screen instanceof GuiCraftAmount gui) {
|
||||
|
||||
if (ReflectionHelper.getPrivateValue(GuiAmount.class, gui, "nextBtn") == button) {
|
||||
return (int) ReflectionHelper.findMethod(GuiAmount.class, gui, new String[] { "getAmount" })
|
||||
.invoke(gui);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static String getModID(Container container) {
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.ThE)
|
||||
&& container.getClass().getName().startsWith("thaumicenergistics.common.container")) {
|
||||
return ModIDs.ThE;
|
||||
} else if (Loader.isModLoaded(ModIDs.FC)
|
||||
&& container.getClass().getName().startsWith("com.glodblock.github.client.gui.container")) {
|
||||
return ModIDs.FC;
|
||||
} else
|
||||
if (Loader.isModLoaded(ModIDs.WCT) && container.getClass().getName()
|
||||
.startsWith("net.p455w0rd.wirelesscraftingterminal.common.container")) {
|
||||
return ModIDs.WCT;
|
||||
} else
|
||||
if (container instanceof AEBaseContainer) {
|
||||
return "AE";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private void requestNextIngredient() {
|
||||
final ItemStack stack = this.tracker.getNextIngredient();
|
||||
|
||||
if (stack != null) {
|
||||
PacketCraftingRequest craftingRequest = new PacketCraftingRequest(
|
||||
this.modID,
|
||||
PacketCraftingRequest.COMMAND_OPEN_CRAFT_CONFIRM,
|
||||
stack.writeToNBT(new NBTTagCompound()),
|
||||
stack.stackSize,
|
||||
this.isAutoStart);
|
||||
NEENetworkHandler.getInstance().sendToServer(craftingRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCraftingTableRecipe(IRecipeHandler recipe) {
|
||||
if (recipe instanceof TemplateRecipeHandler templateRecipeHandler) {
|
||||
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
|
||||
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private NBTTagCompound getPatternStack(IRecipeHandler recipeHandler, int recipeIndex, World world) {
|
||||
final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
final List<PositionedStack> ingredients = recipeHandler.getIngredientStacks(recipeIndex);
|
||||
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
final int slotIndex = col + row * 3;
|
||||
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.items[0];
|
||||
|
||||
final ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
|
||||
if (preferModItem != null) {
|
||||
stack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
stack.setItemDamage(0);
|
||||
}
|
||||
|
||||
ic.setInventorySlotContents(slotIndex, stack);
|
||||
} else {
|
||||
ic.setInventorySlotContents(slotIndex, null);
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack result = CraftingManager.getInstance().findMatchingRecipe(ic, world);
|
||||
|
||||
if (result != null) {
|
||||
final NBTTagCompound patternValue = new NBTTagCompound();
|
||||
final NBTTagList tagIn = new NBTTagList();
|
||||
|
||||
for (int slotIndex = 0; slotIndex < ic.getSizeInventory(); slotIndex++) {
|
||||
final ItemStack itemStack = ic.getStackInSlot(slotIndex);
|
||||
|
||||
if (itemStack != null) {
|
||||
tagIn.appendTag(itemStack.writeToNBT(new NBTTagCompound()));
|
||||
} else {
|
||||
tagIn.appendTag(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
|
||||
patternValue.setTag("in", tagIn);
|
||||
patternValue.setTag("out", result.writeToNBT(new NBTTagCompound()));
|
||||
patternValue.setBoolean("crafting", true);
|
||||
patternValue.setBoolean("substitute", false);
|
||||
|
||||
return patternValue;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setIsPatternInterfaceExists(boolean isPatternInterfaceExists) {
|
||||
this.isPatternInterfaceExists = isPatternInterfaceExists;
|
||||
}
|
||||
|
||||
public boolean canCraftRecipeResult(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
final PositionedStack pStack = recipe.getResultStack(recipeIndex);
|
||||
|
||||
if (pStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isPatternInterfaceExists && isCraftingTableRecipe(recipe)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return existsRecipeResult(firstGui, pStack);
|
||||
}
|
||||
|
||||
private boolean existsRecipeResult(GuiContainer firstGui, PositionedStack pStack) {
|
||||
return pStack != null && !GuiUtils
|
||||
.getStorageStacks(firstGui, aestack -> aestack.isCraftable() && aestack.isSameType(pStack.item))
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
|
||||
|
||||
import com.github.vfyjxf.nee.NotEnoughEnergistics;
|
||||
import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState;
|
||||
import com.github.vfyjxf.nee.utils.Ingredient;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
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;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeButton;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class NEECraftingTerminalHandler implements IOverlayHandler {
|
||||
|
||||
public static final NEECraftingTerminalHandler instance = new NEECraftingTerminalHandler();
|
||||
|
||||
private NEECraftingTerminalHandler() {}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficialr
|
||||
*/
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
try {
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.WCT) && firstGui instanceof GuiWirelessCraftingTerminal) {
|
||||
moveItemsForWirelessCrafting(firstGui, ingredients);
|
||||
} else {
|
||||
PacketNEIRecipe packet = new PacketNEIRecipe(packIngredients(firstGui, ingredients, false));
|
||||
// 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));
|
||||
}
|
||||
|
||||
if (packetSize >= 0) {
|
||||
NetworkHandler.instance.sendToServer(packet);
|
||||
} else {
|
||||
NotEnoughEnergistics.logger.error("Can't get packet size!");
|
||||
}
|
||||
}
|
||||
} catch (final Exception | Error ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFillCraftingGrid(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
||||
return presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
private boolean testSize(final NBTTagCompound recipe) throws IOException {
|
||||
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
final DataOutputStream outputStream = new DataOutputStream(bytes);
|
||||
CompressedStreamTools.writeCompressed(recipe, outputStream);
|
||||
return bytes.size() > 3 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemOverlayState> presenceOverlay(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
||||
final IngredientTracker tracker = new IngredientTracker(firstGui, handler, recipeIndex);
|
||||
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
|
||||
|
||||
for (Ingredient ingredient : tracker.getIngredients()) {
|
||||
itemPresenceSlots.add(new NEEItemOverlayState(ingredient, true));
|
||||
}
|
||||
|
||||
return itemPresenceSlots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from GTNewHorizons/Applied-Energistics-2-Unofficial
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private NBTTagCompound packIngredients(GuiContainer gui, List<PositionedStack> ingredients, boolean limited)
|
||||
throws IOException {
|
||||
final NBTTagCompound recipe = new NBTTagCompound();
|
||||
|
||||
for (final PositionedStack positionedStack : ingredients) {
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
for (final Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
|
||||
if (isCraftingMatrixSlot(gui, slot) && slot.getSlotIndex() == col + row * 3) {
|
||||
final NBTTagList tags = new NBTTagList();
|
||||
final List<ItemStack> list = new LinkedList<>();
|
||||
|
||||
// prefer pure crystals.
|
||||
for (ItemStack stack : positionedStack.getFilteredPermutations()) {
|
||||
stack = stack.copy();
|
||||
if (Platform.isRecipePrioritized(stack)) {
|
||||
list.add(0, stack);
|
||||
} else {
|
||||
list.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
for (final ItemStack is : list) {
|
||||
tags.appendTag(is.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
if (limited) {
|
||||
final NBTTagCompound test = new NBTTagCompound();
|
||||
test.setTag("#" + slot.getSlotIndex(), tags);
|
||||
if (testSize(test)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
recipe.setTag("#" + slot.getSlotIndex(), tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
private boolean isCraftingMatrixSlot(GuiContainer gui, Slot slot) {
|
||||
return slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix;
|
||||
}
|
||||
|
||||
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 = ModIDs.WCT)
|
||||
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 onActionPerformedEventPost(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) {
|
||||
if (event.gui instanceof GuiRecipe guiRecipe && isGuiCraftingTerm(guiRecipe)) {
|
||||
NEETerminalOverlayButton.updateRecipeButtons(guiRecipe, event.buttonList);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isGuiCraftingTerm(GuiRecipe<?> gui) {
|
||||
return gui.firstGui != null
|
||||
&& NEECraftingTerminalHandler.class.isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiOverlayButton;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeButton;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class NEEExtremeAutoCrafterHandler implements IOverlayHandler {
|
||||
|
||||
public static final NEEExtremeAutoCrafterHandler instance = new NEEExtremeAutoCrafterHandler();
|
||||
|
||||
private NEEExtremeAutoCrafterHandler() {}
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packetExtremeRecipe(recipe, recipeIndex));
|
||||
}
|
||||
|
||||
private PacketExtremeRecipe packetExtremeRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
|
||||
for (PositionedStack positionedStack : ingredients) {
|
||||
int col = (positionedStack.relx - 3) / 18;
|
||||
int row = (positionedStack.rely - 3) / 18;
|
||||
|
||||
if (positionedStack.rely == 129) {
|
||||
col = (positionedStack.relx - 2) / 18;
|
||||
}
|
||||
|
||||
int slotIndex = col + row * 9;
|
||||
ItemStack currentStack = positionedStack.item;
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
|
||||
if (preferModItem != null) {
|
||||
currentStack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack stack : positionedStack.items) {
|
||||
if (ItemUtils.isPreferItems(stack)) {
|
||||
currentStack = stack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(currentStack, currentStack.stackSize));
|
||||
}
|
||||
|
||||
return new PacketExtremeRecipe(recipeInputs);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onActionPerformedEventPost(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) {
|
||||
if (NEEConfig.noShift && event.gui instanceof GuiRecipe guiRecipe && isGuiExtremeTerm(guiRecipe)) {
|
||||
for (int i = 0; i < event.buttonList.size(); i++) {
|
||||
if (event.buttonList.get(i) instanceof GuiOverlayButton btn) {
|
||||
btn.setRequireShiftForOverlayRecipe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGuiExtremeTerm(GuiRecipe<?> gui) {
|
||||
return gui.firstGui != null && this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
|
||||
import com.github.vfyjxf.nee.utils.Ingredient;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiOverlayButton;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeButton;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class NEEKnowledgeInscriberHandler implements IOverlayHandler {
|
||||
|
||||
public class NEEArcaneOverlayButton extends NEETerminalOverlayButton {
|
||||
|
||||
public NEEArcaneOverlayButton(GuiOverlayButton button) {
|
||||
super(button.firstGui, button.handlerRef, button.xPosition, button.yPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemOverlayState> ingredientsOverlay() {
|
||||
List<PositionedStack> ingredients = this.handlerRef.handler
|
||||
.getIngredientStacks(this.handlerRef.recipeIndex);
|
||||
|
||||
if (this.itemPresenceCache.size() != ingredients.size()) {
|
||||
this.itemPresenceCache.clear();
|
||||
|
||||
final IngredientTracker tracker = new IngredientTracker(
|
||||
firstGui,
|
||||
this.handlerRef.handler,
|
||||
this.handlerRef.recipeIndex);
|
||||
|
||||
for (Ingredient ingredient : tracker.getIngredients()) {
|
||||
this.itemPresenceCache.add(new NEEItemOverlayState(ingredient, true));
|
||||
}
|
||||
|
||||
List<ItemStack> items = this.itemPresenceCache.stream().filter(state -> !state.isPresent())
|
||||
.map(state -> state.getSlot().item).collect(Collectors.toList());
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
this.missedMaterialsTooltipLineHandler = new ItemsTooltipLineHandler(
|
||||
NEIClientUtils.translate("recipe.overlay.missing"),
|
||||
items,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
} else {
|
||||
this.missedMaterialsTooltipLineHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
return this.itemPresenceCache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final NEEKnowledgeInscriberHandler instance = new NEEKnowledgeInscriberHandler();
|
||||
|
||||
private Class<?> knowledgeInscriberClz;
|
||||
private Class<?> itemAspectClz;
|
||||
|
||||
private NEEKnowledgeInscriberHandler() {
|
||||
|
||||
try {
|
||||
// "Knowledge Inscriber"
|
||||
knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
|
||||
try {
|
||||
itemAspectClz = Class.forName("com.djgiannuzz.thaumcraftneiplugin.items.ItemAspect");
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
if (knowledgeInscriberClz != null && knowledgeInscriberClz.isInstance(firstGui)) {
|
||||
NEENetworkHandler.getInstance().sendToServer(packetArcaneRecipe(recipe, recipeIndex));
|
||||
}
|
||||
}
|
||||
|
||||
private PacketArcaneRecipe packetArcaneRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (itemAspectClz != null) {
|
||||
ingredients.removeIf(positionedStack -> itemAspectClz.isInstance(positionedStack.item.getItem()));
|
||||
}
|
||||
|
||||
for (PositionedStack positionedStack : ingredients) {
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
final int slotIndex = getSlotIndex(positionedStack.relx * 100 + positionedStack.rely);
|
||||
final ItemStack[] currentStackList = positionedStack.items;
|
||||
ItemStack stack = positionedStack.item;
|
||||
|
||||
for (ItemStack currentStack : currentStackList) {
|
||||
if (Platform.isRecipePrioritized(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
recipeInputs.setTag("#" + slotIndex, ItemUtils.writeItemStackToNBT(stack, stack.stackSize));
|
||||
}
|
||||
}
|
||||
|
||||
return new PacketArcaneRecipe(recipeInputs);
|
||||
}
|
||||
|
||||
private int getSlotIndex(int xy) {
|
||||
switch (xy) {
|
||||
case 7533:
|
||||
return 1;
|
||||
case 10333:
|
||||
return 2;
|
||||
case 4960:
|
||||
return 3;
|
||||
case 7660:
|
||||
return 4;
|
||||
case 10360:
|
||||
return 5;
|
||||
case 4987:
|
||||
return 6;
|
||||
case 7687:
|
||||
return 7;
|
||||
case 10387:
|
||||
return 8;
|
||||
case 4832:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onActionPerformedEventPost(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) {
|
||||
|
||||
if (NEEConfig.noShift && event.gui instanceof GuiRecipe guiRecipe) {
|
||||
|
||||
if (isGuiArcaneCraftingTerm(guiRecipe)) {
|
||||
for (int i = 0; i < event.buttonList.size(); i++) {
|
||||
if (event.buttonList.get(i) instanceof GuiOverlayButton btn) {
|
||||
event.buttonList.set(i, new NEEArcaneOverlayButton(btn));
|
||||
}
|
||||
}
|
||||
} else if (isGuiKnowledgeInscriber(guiRecipe)) {
|
||||
for (int i = 0; i < event.buttonList.size(); i++) {
|
||||
if (event.buttonList.get(i) instanceof GuiOverlayButton btn) {
|
||||
btn.setRequireShiftForOverlayRecipe(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isGuiKnowledgeInscriber(GuiRecipe<?> gui) {
|
||||
return gui.firstGui != null && this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
|
||||
}
|
||||
|
||||
private boolean isGuiArcaneCraftingTerm(GuiRecipe<?> gui) {
|
||||
return Loader.isModLoaded(ModIDs.ThE)
|
||||
&& gui.firstGui instanceof thaumicenergistics.client.gui.GuiArcaneCraftingTerminal;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import static com.github.vfyjxf.nee.processor.RecipeProcessor.NULL_IDENTIFIER;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.github.vfyjxf.nee.config.ItemCombination;
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.nei.NEETerminalOverlayButton.NEEItemOverlayState;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
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.Ingredient;
|
||||
import com.github.vfyjxf.nee.utils.IngredientTracker;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.nei.FluidPatternTerminalRecipeTransferHandler;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeButton;
|
||||
import codechicken.nei.recipe.IRecipeHandler;
|
||||
import codechicken.nei.recipe.TemplateRecipeHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class NEEPatternTerminalHandler implements IOverlayHandler {
|
||||
|
||||
public static final String INPUT_KEY = "#";
|
||||
public static final String OUTPUT_KEY = "Outputs";
|
||||
|
||||
// Add the function of mouse wheel to switch materials
|
||||
public static Map<String, PositionedStack> ingredients = new HashMap<>();
|
||||
|
||||
public static final NEEPatternTerminalHandler instance = new NEEPatternTerminalHandler();
|
||||
|
||||
private NEEPatternTerminalHandler() {}
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, boolean shift) {
|
||||
transferRecipe(gui, handler, recipeIndex, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int transferRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, int multiplier) {
|
||||
multiplier = Math.max(1, multiplier);
|
||||
|
||||
NEENetworkHandler.getInstance().sendToServer(packRecipe(handler, recipeIndex, multiplier));
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.FC)
|
||||
&& (GuiUtils.isFluidCraftPatternTermEx(gui) || GuiUtils.isFluidCraftPatternTerm(gui))) {
|
||||
fluidCraftOverlayRecipe(gui, handler, recipeIndex);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemOverlayState> presenceOverlay(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
||||
final IngredientTracker tracker = new IngredientTracker(firstGui, handler, recipeIndex);
|
||||
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
|
||||
|
||||
for (Ingredient ingredient : tracker.getIngredients()) {
|
||||
itemPresenceSlots.add(new NEEItemOverlayState(ingredient, false));
|
||||
}
|
||||
|
||||
return itemPresenceSlots;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = ModIDs.FC)
|
||||
private void fluidCraftOverlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
FluidPatternTerminalRecipeTransferHandler.INSTANCE.overlayRecipe(firstGui, recipe, recipeIndex, true);
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) {
|
||||
if (isCraftingTableRecipe(recipe)) {
|
||||
return packCraftingTableRecipe(recipe, recipeIndex);
|
||||
} else {
|
||||
return packProcessRecipe(recipe, recipeIndex, (int) multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCraftingTableRecipe(IRecipeHandler recipe) {
|
||||
if (recipe instanceof TemplateRecipeHandler templateRecipeHandler) {
|
||||
String overlayIdentifier = templateRecipeHandler.getOverlayIdentifier();
|
||||
return "crafting".equals(overlayIdentifier) || "crafting2x2".equals(overlayIdentifier);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex, int multiplier) {
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
final NBTTagCompound recipeOutputs = new NBTTagCompound();
|
||||
String identifier = recipe instanceof TemplateRecipeHandler ? recipe.getOverlayIdentifier() : NULL_IDENTIFIER;
|
||||
if (identifier == null) {
|
||||
identifier = NULL_IDENTIFIER;
|
||||
}
|
||||
int inputIndex = 0;
|
||||
int outputIndex = 0;
|
||||
|
||||
// get all recipe inputs and other stacks,use first item
|
||||
for (IRecipeProcessor processor : RecipeProcessor.recipeProcessors) {
|
||||
if (processor.getAllOverlayIdentifier().contains(identifier)) {
|
||||
final List<PositionedStack> inputs = processor.getRecipeInput(recipe, recipeIndex, identifier);
|
||||
final List<PositionedStack> outputs = processor.getRecipeOutput(recipe, recipeIndex, identifier);
|
||||
final String recipeProcessorId = processor.getRecipeProcessorId();
|
||||
|
||||
if (!inputs.isEmpty() && !outputs.isEmpty()) {
|
||||
final List<PositionedStack> mergedInputs = getMergedInputs(
|
||||
inputs,
|
||||
processor,
|
||||
recipe,
|
||||
recipeIndex,
|
||||
identifier);
|
||||
|
||||
NEEPatternTerminalHandler.ingredients.clear();
|
||||
|
||||
for (PositionedStack positionedStack : mergedInputs) {
|
||||
ItemStack currentStack = positionedStack.getFilteredPermutations().get(0);
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
int stackSize = currentStack.stackSize;
|
||||
|
||||
if (preferModItem != null) {
|
||||
currentStack = preferModItem;
|
||||
currentStack.stackSize = stackSize;
|
||||
}
|
||||
|
||||
for (ItemStack stack : positionedStack.items) {
|
||||
if (Platform.isRecipePrioritized(stack)
|
||||
|| ItemUtils.isPreferItems(stack, recipeProcessorId, identifier)) {
|
||||
currentStack = stack.copy();
|
||||
currentStack.stackSize = stackSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemUtils.isInBlackList(currentStack, recipeProcessorId, identifier)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
currentStack.setItemDamage(0);
|
||||
}
|
||||
|
||||
if (currentStack.stackSize < 1) {
|
||||
currentStack.stackSize = 1;
|
||||
}
|
||||
|
||||
recipeInputs.setTag(
|
||||
INPUT_KEY + inputIndex,
|
||||
ItemUtils.writeItemStackToNBT(currentStack, currentStack.stackSize * multiplier));
|
||||
NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + inputIndex, positionedStack);
|
||||
inputIndex++;
|
||||
}
|
||||
|
||||
for (PositionedStack positionedStack : outputs) {
|
||||
if (outputIndex >= 4 || positionedStack == null || positionedStack.item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack outputStack = positionedStack.item.copy();
|
||||
|
||||
if (outputStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
outputStack.setItemDamage(0);
|
||||
}
|
||||
|
||||
if (outputStack.stackSize < 1) {
|
||||
outputStack.stackSize = 1;
|
||||
}
|
||||
|
||||
recipeOutputs.setTag(
|
||||
OUTPUT_KEY + outputIndex,
|
||||
ItemUtils.writeItemStackToNBT(outputStack, outputStack.stackSize * multiplier));
|
||||
outputIndex++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new PacketNEIPatternRecipe(recipeInputs, recipeOutputs);
|
||||
}
|
||||
|
||||
private List<PositionedStack> getMergedInputs(List<PositionedStack> inputs, IRecipeProcessor processor,
|
||||
IRecipeHandler recipe, int recipeIndex, String identifier) {
|
||||
List<PositionedStack> mergedInputs = new ArrayList<>();
|
||||
|
||||
for (PositionedStack positionedStack : inputs) {
|
||||
ItemStack currentStack = positionedStack.getFilteredPermutations().get(0);
|
||||
ItemCombination currentValue = ItemCombination.valueOf(NEEConfig.itemCombinationMode);
|
||||
boolean find = false;
|
||||
|
||||
if (currentValue != ItemCombination.DISABLED && processor.mergeStacks(recipe, recipeIndex, identifier)) {
|
||||
boolean isWhitelist = currentValue == ItemCombination.WHITELIST
|
||||
&& Arrays.asList(NEEConfig.itemCombinationWhitelist).contains(identifier);
|
||||
|
||||
if (currentValue == ItemCombination.ENABLED || isWhitelist) {
|
||||
for (PositionedStack storedStack : mergedInputs) {
|
||||
|
||||
ItemStack firstStack = storedStack.getFilteredPermutations().get(0);
|
||||
boolean areItemStackEqual = NEIServerUtils
|
||||
.areStacksSameTypeCraftingWithNBT(firstStack, currentStack);
|
||||
|
||||
if (areItemStackEqual
|
||||
&& (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) {
|
||||
storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize;
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!find) {
|
||||
mergedInputs.add(positionedStack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
return mergedInputs;
|
||||
}
|
||||
|
||||
private PacketNEIPatternRecipe packCraftingTableRecipe(IRecipeHandler recipe, int recipeIndex) {
|
||||
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
final NBTTagCompound recipeInputs = new NBTTagCompound();
|
||||
NEEPatternTerminalHandler.ingredients.clear();
|
||||
|
||||
for (PositionedStack positionedStack : ingredients) {
|
||||
final int col = (positionedStack.relx - 25) / 18;
|
||||
final int row = (positionedStack.rely - 6) / 18;
|
||||
int slotIndex = col + row * 3;
|
||||
|
||||
if (positionedStack.items != null && positionedStack.items.length > 0) {
|
||||
positionedStack = positionedStack.copy();
|
||||
ItemStack stack = positionedStack.getFilteredPermutations().get(0);
|
||||
|
||||
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
|
||||
if (preferModItem != null) {
|
||||
stack = preferModItem;
|
||||
}
|
||||
|
||||
for (ItemStack currentStack : positionedStack.items) {
|
||||
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
|
||||
stack = currentStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
ItemUtils.transformGTTool(stack);
|
||||
|
||||
if (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
stack.setItemDamage(0);
|
||||
}
|
||||
|
||||
positionedStack.item = stack;
|
||||
recipeInputs.setTag(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, stack.stackSize));
|
||||
NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new PacketNEIPatternRecipe(recipeInputs, null);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onActionPerformedEventPost(GuiRecipeButton.UpdateRecipeButtonsEvent.Post event) {
|
||||
if (event.gui instanceof GuiRecipe guiRecipe && isGuiPatternTerm(guiRecipe)) {
|
||||
NEETerminalOverlayButton.updateRecipeButtons(guiRecipe, event.buttonList);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGuiPatternTerm(GuiRecipe<?> gui) {
|
||||
return gui.firstGui != null && this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketNEIBookmark;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
|
||||
import codechicken.nei.api.IBookmarkContainerHandler;
|
||||
|
||||
public class NEETerminalBookmarkContainerHandler implements IBookmarkContainerHandler {
|
||||
|
||||
public static final NEETerminalBookmarkContainerHandler instance = new NEETerminalBookmarkContainerHandler();
|
||||
|
||||
private NEETerminalBookmarkContainerHandler() {}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getStorageStacks(GuiContainer guiContainer) {
|
||||
return GuiUtils.getStorageStacks(guiContainer, stack -> stack.getStackSize() > 0).stream()
|
||||
.map(stack -> stack.getItemStack().copy()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pullBookmarkItemsFromContainer(GuiContainer guiContainer, ArrayList<ItemStack> bookmarkItems) {
|
||||
final NBTTagCompound nbtBookmarkItems = new NBTTagCompound();
|
||||
|
||||
for (int i = 0; i < bookmarkItems.size(); i++) {
|
||||
nbtBookmarkItems.setTag("#" + i, packBookmarkItem(bookmarkItems.get(i)));
|
||||
}
|
||||
|
||||
NEENetworkHandler.getInstance().sendToServer(new PacketNEIBookmark(nbtBookmarkItems));
|
||||
}
|
||||
|
||||
private NBTTagCompound packBookmarkItem(ItemStack bookmarkItem) {
|
||||
return bookmarkItem.writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.github.vfyjxf.nee.nei;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.utils.Ingredient;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.Image;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.recipe.GuiOverlayButton;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.recipe.GuiRecipeButton;
|
||||
import codechicken.nei.recipe.RecipeHandlerRef;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public class NEETerminalOverlayButton extends GuiOverlayButton {
|
||||
|
||||
public static class NEEItemOverlayState extends ItemOverlayState {
|
||||
|
||||
private static final Image crossIcon = new DrawableBuilder(
|
||||
"neenergistics:textures/gui/states.png",
|
||||
16,
|
||||
36,
|
||||
8,
|
||||
8).build();
|
||||
|
||||
private static final Image checkIcon = new DrawableBuilder(
|
||||
"neenergistics:textures/gui/states.png",
|
||||
24,
|
||||
36,
|
||||
8,
|
||||
8).build();
|
||||
|
||||
protected Ingredient ingredient;
|
||||
protected boolean isCraftingTerm = true;
|
||||
|
||||
public NEEItemOverlayState(Ingredient ingredient, boolean isCraftingTerm) {
|
||||
super(ingredient.getIngredient(), !ingredient.requiresToCraft());
|
||||
this.ingredient = ingredient;
|
||||
this.isCraftingTerm = isCraftingTerm;
|
||||
}
|
||||
|
||||
public Ingredient getIngredient() {
|
||||
return this.ingredient;
|
||||
}
|
||||
|
||||
public boolean isCraftingTerm() {
|
||||
return this.isCraftingTerm;
|
||||
}
|
||||
|
||||
public void setIsCraftingTerm(boolean isCraftingTerm) {
|
||||
this.isCraftingTerm = isCraftingTerm;
|
||||
}
|
||||
|
||||
public void draw(ItemOverlayFormat format) {
|
||||
final boolean doCraftingHelp = NEIClientConfig.isKeyHashDown("nee.nopreview")
|
||||
|| NEIClientConfig.isKeyHashDown("nee.preview");
|
||||
|
||||
if (this.ingredient.isCraftable()
|
||||
&& (!this.isCraftingTerm || doCraftingHelp && this.ingredient.requiresToCraft())) {
|
||||
final Image icon = this.isPresent ? checkIcon : crossIcon;
|
||||
|
||||
if (format == ItemOverlayFormat.BACKGROUND) {
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GuiDraw.drawRect(this.slot.relx, this.slot.rely, 16, 16, 0x660000AA);
|
||||
GL11.glPopAttrib();
|
||||
} else {
|
||||
LayoutManager.drawIcon(this.slot.relx + 16 - icon.width, this.slot.rely + 16 - icon.height, icon);
|
||||
}
|
||||
|
||||
} else {
|
||||
super.draw(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NEETerminalOverlayButton(GuiContainer firstGui, RecipeHandlerRef handlerRef, int xPosition, int yPosition) {
|
||||
super(firstGui, handlerRef, xPosition, yPosition);
|
||||
if (NEEConfig.noShift) {
|
||||
setRequireShiftForOverlayRecipe(false);
|
||||
}
|
||||
}
|
||||
|
||||
public NEETerminalOverlayButton(GuiOverlayButton button) {
|
||||
this(button.firstGui, button.handlerRef, button.xPosition, button.yPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mousex, int mousey) {
|
||||
if (this.firstGui != null && !NEECraftingPreviewHandler.instance
|
||||
.handle(this.firstGui, this.handlerRef.handler, this.handlerRef.recipeIndex)) {
|
||||
super.mouseReleased(mousex, mousey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
hotkeys = super.handleHotkeys(gui, mousex, mousey, hotkeys);
|
||||
|
||||
if (ingredientsOverlay().stream().allMatch(
|
||||
state -> state.isPresent()
|
||||
|| state instanceof NEEItemOverlayState overlayState && showCraftingHotkeys(overlayState))) {
|
||||
|
||||
if (NEECraftingPreviewHandler.instance
|
||||
.canCraftRecipeResult(gui, this.handlerRef.handler, handlerRef.recipeIndex)) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("nee.preview", 0, NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
I18n.format("neenergistics.gui.tooltip.crafting.preview.result"));
|
||||
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("nee.nopreview", 0, NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
I18n.format("neenergistics.gui.tooltip.crafting.nopreview.result"));
|
||||
} else {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("nee.preview", 0, NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
I18n.format("neenergistics.gui.tooltip.crafting.preview"));
|
||||
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("nee.nopreview", 0, NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
I18n.format("neenergistics.gui.tooltip.crafting.nopreview"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return hotkeys;
|
||||
}
|
||||
|
||||
private static boolean showCraftingHotkeys(NEEItemOverlayState button) {
|
||||
return button.getIngredient().isCraftable() || !button.getIngredient().requiresToCraft();
|
||||
}
|
||||
|
||||
public static void updateRecipeButtons(GuiRecipe<?> guiRecipe, List<GuiRecipeButton> buttonList) {
|
||||
for (int i = 0; i < buttonList.size(); i++) {
|
||||
if (buttonList.get(i) instanceof GuiOverlayButton btn) {
|
||||
buttonList.set(i, new NEETerminalOverlayButton(btn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,104 +8,31 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
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.common.utils.RandomUtils;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
|
||||
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
|
||||
import com.github.vfyjxf.nee.client.gui.GuiCraftingAmount;
|
||||
import com.github.vfyjxf.nee.client.gui.GuiPatternInterface;
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingConfirm;
|
||||
import com.github.vfyjxf.nee.container.ContainerPatternInterface;
|
||||
import com.github.vfyjxf.nee.container.WCTContainerCraftingConfirm;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
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 cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
|
||||
public class NEEGuiHandler implements IGuiHandler {
|
||||
|
||||
public static final int CRAFTING_AMOUNT_ID = 0;
|
||||
public static final int CRAFTING_CONFIRM_ID = 1;
|
||||
public static final int PATTERN_INTERFACE_ID = 2;
|
||||
public static final int CRAFTING_CONFIRM_WIRELESS_ID = 3;
|
||||
public static final int CRAFTING_AMOUNT_WIRELESS_ID = 4;
|
||||
public static final int PATTERN_INTERFACE_ID = 0;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getServerGuiElement(int ordinal, EntityPlayer player, World world, int x, int y, int z) {
|
||||
final int guiId = ordinal >> 4;
|
||||
if (guiId != CRAFTING_AMOUNT_WIRELESS_ID && guiId != CRAFTING_CONFIRM_WIRELESS_ID) {
|
||||
final ForgeDirection side = ForgeDirection.getOrientation(ordinal & 7);
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (side != ForgeDirection.UNKNOWN) {
|
||||
if (tile instanceof IPartHost) {
|
||||
IPartHost partHost = (IPartHost) tile;
|
||||
IPart part = partHost.getPart(side);
|
||||
switch (guiId) {
|
||||
case CRAFTING_AMOUNT_ID:
|
||||
if (part instanceof PartCraftingTerminal) {
|
||||
return updateGui(
|
||||
new ContainerCraftingAmount(player.inventory, part),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
side,
|
||||
part);
|
||||
}
|
||||
return null;
|
||||
case CRAFTING_CONFIRM_ID:
|
||||
if (part instanceof PartCraftingTerminal) {
|
||||
return updateGui(
|
||||
new ContainerCraftingConfirm(player.inventory, (ITerminalHost) part),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
side,
|
||||
part);
|
||||
}
|
||||
return null;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tile != null) {
|
||||
if (guiId == PATTERN_INTERFACE_ID) {
|
||||
if (tile instanceof TilePatternInterface) {
|
||||
return new ContainerPatternInterface(player.inventory, (TilePatternInterface) tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (guiId == PATTERN_INTERFACE_ID) {
|
||||
final TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TilePatternInterface pattern) {
|
||||
return new ContainerPatternInterface(player.inventory, pattern);
|
||||
}
|
||||
} else if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
final IPortableCell wirelessTerminal = getWirelessTerminalGui(player, world, x, y, z);
|
||||
|
||||
if (wirelessTerminal != null) {
|
||||
if (guiId == CRAFTING_AMOUNT_WIRELESS_ID) {
|
||||
return new ContainerCraftingAmount(player.inventory, wirelessTerminal);
|
||||
} else {
|
||||
return new WCTContainerCraftingConfirm(player.inventory, wirelessTerminal);
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -113,87 +40,19 @@ public class NEEGuiHandler implements IGuiHandler {
|
||||
@Override
|
||||
public Object getClientGuiElement(int ordinal, EntityPlayer player, World world, int x, int y, int z) {
|
||||
final int guiId = ordinal >> 4;
|
||||
if (guiId != CRAFTING_AMOUNT_WIRELESS_ID && guiId != CRAFTING_CONFIRM_WIRELESS_ID) {
|
||||
final ForgeDirection side = ForgeDirection.getOrientation(ordinal & 7);
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (side != ForgeDirection.UNKNOWN) {
|
||||
if (tile instanceof IPartHost) {
|
||||
IPartHost partHost = (IPartHost) tile;
|
||||
IPart part = partHost.getPart(side);
|
||||
switch (guiId) {
|
||||
case CRAFTING_AMOUNT_ID:
|
||||
if (part instanceof PartCraftingTerminal) {
|
||||
return updateGui(
|
||||
new GuiCraftingAmount(player.inventory, (ITerminalHost) part),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
side,
|
||||
part);
|
||||
}
|
||||
return null;
|
||||
case CRAFTING_CONFIRM_ID:
|
||||
if (part instanceof PartCraftingTerminal) {
|
||||
return updateGui(
|
||||
new GuiCraftConfirm(player.inventory, (ITerminalHost) part),
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
side,
|
||||
part);
|
||||
}
|
||||
return null;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (guiId == PATTERN_INTERFACE_ID) {
|
||||
final TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
} else {
|
||||
if (tile != null) {
|
||||
if (guiId == PATTERN_INTERFACE_ID) {
|
||||
if (tile instanceof TilePatternInterface) {
|
||||
return new GuiPatternInterface(player.inventory, (TilePatternInterface) tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tile instanceof TilePatternInterface pattern) {
|
||||
return new GuiPatternInterface(player.inventory, pattern);
|
||||
}
|
||||
} else if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
|
||||
final IPortableCell wirelessTerminal = getWirelessTerminalGui(player, world, x, y, z);
|
||||
|
||||
if (wirelessTerminal != null) {
|
||||
if (guiId == CRAFTING_AMOUNT_WIRELESS_ID) {
|
||||
return new GuiCraftingAmount(player.inventory, wirelessTerminal);
|
||||
} else {
|
||||
return new net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm(
|
||||
player.inventory,
|
||||
wirelessTerminal);
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object updateGui(Object newContainer, final World w, final int x, final int y, final int z,
|
||||
final ForgeDirection side, final IPart part) {
|
||||
if (newContainer instanceof AEBaseContainer) {
|
||||
final AEBaseContainer bc = (AEBaseContainer) newContainer;
|
||||
bc.setOpenContext(new ContainerOpenContext(part));
|
||||
bc.getOpenContext().setWorld(w);
|
||||
bc.getOpenContext().setX(x);
|
||||
bc.getOpenContext().setY(y);
|
||||
bc.getOpenContext().setZ(z);
|
||||
bc.getOpenContext().setSide(side);
|
||||
}
|
||||
return newContainer;
|
||||
}
|
||||
|
||||
public static void openGui(EntityPlayer player, int ID, TileEntity tile, ForgeDirection side) {
|
||||
int x = tile.xCoord;
|
||||
int y = tile.yCoord;
|
||||
@@ -201,27 +60,11 @@ public class NEEGuiHandler implements IGuiHandler {
|
||||
player.openGui(instance, ID << 4 | (side.ordinal()), tile.getWorldObj(), x, y, z);
|
||||
}
|
||||
|
||||
public static void openGui(EntityPlayer player, int ID, World world) {
|
||||
public static void openGui(EntityPlayer player, int ID) {
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
player.openGui(instance, (ID << 4), world, x, y, z);
|
||||
player.openGui(instance, (ID << 4), player.worldObj, x, y, z);
|
||||
}
|
||||
|
||||
@Optional.Method(modid = ModIDs.WCT)
|
||||
private WirelessTerminalGuiObject getWirelessTerminalGui(EntityPlayer player, World world, int x, int y, int z) {
|
||||
final IWirelessCraftingTermHandler wh = (IWirelessCraftingTermHandler) AEApi.instance().registries().wireless()
|
||||
.getWirelessTerminalHandler(RandomUtils.getWirelessTerm(player.inventory));
|
||||
if (wh != null) {
|
||||
return new WirelessTerminalGuiObject(
|
||||
wh,
|
||||
RandomUtils.getWirelessTerm(player.inventory),
|
||||
player,
|
||||
world,
|
||||
x,
|
||||
y,
|
||||
z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,9 @@ import com.github.vfyjxf.nee.NotEnoughEnergistics;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketExtremeRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketNEIBookmark;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketNEIPatternRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketOpenGui;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketSetRecipe;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketStackCountChange;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketValueConfigClient;
|
||||
@@ -25,6 +24,10 @@ public class NEENetworkHandler {
|
||||
return packId++;
|
||||
}
|
||||
|
||||
private NEENetworkHandler() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static SimpleNetworkWrapper getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
@@ -52,13 +55,8 @@ public class NEENetworkHandler {
|
||||
PacketCraftingRequest.class,
|
||||
nextId(),
|
||||
Side.SERVER);
|
||||
INSTANCE.registerMessage(
|
||||
PacketOpenCraftAmount.Handler.class,
|
||||
PacketOpenCraftAmount.class,
|
||||
nextId(),
|
||||
Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketNEIBookmark.Handler.class, PacketNEIBookmark.class, nextId(), Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketOpenGui.Handler.class, PacketOpenGui.class, nextId(), Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketSetRecipe.Handler.class, PacketSetRecipe.class, nextId(), Side.SERVER);
|
||||
INSTANCE.registerMessage(
|
||||
PacketValueConfigServer.Handler.class,
|
||||
PacketValueConfigServer.class,
|
||||
|
||||
@@ -16,6 +16,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import thaumicenergistics.client.gui.GuiArcaneCraftingTerminal;
|
||||
import thaumicenergistics.common.container.ContainerKnowledgeInscriber;
|
||||
|
||||
/**
|
||||
@@ -68,7 +69,30 @@ public class PacketArcaneRecipe implements IMessage {
|
||||
}
|
||||
container.onCraftMatrixChanged(craftMatrix[0].inventory);
|
||||
}
|
||||
} else if (container.inventorySlots instanceof GuiArcaneCraftingTerminal) {
|
||||
ItemStack[] recipeInput = new ItemStack[9];
|
||||
NBTTagCompound currentStack;
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
|
||||
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
Field craftingSlots = ReflectionHelper.findField(GuiArcaneCraftingTerminal.class, "craftingSlots");
|
||||
SlotFakeCraftingMatrix[] craftMatrix = this
|
||||
.getCraftingSlots(craftingSlots, (GuiArcaneCraftingTerminal) container.inventorySlots);
|
||||
|
||||
if (craftMatrix != null && message.input != null) {
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
ItemStack currentItem = null;
|
||||
if (recipeInput[i] != null) {
|
||||
currentItem = recipeInput[i].copy();
|
||||
}
|
||||
craftMatrix[i].putStack(currentItem);
|
||||
}
|
||||
container.onCraftMatrixChanged(craftMatrix[0].inventory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,5 +104,14 @@ public class PacketArcaneRecipe implements IMessage {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private SlotFakeCraftingMatrix[] getCraftingSlots(Field field, GuiArcaneCraftingTerminal container) {
|
||||
try {
|
||||
return (SlotFakeCraftingMatrix[]) field.get(container);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +1,115 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.RECIPE_LENGTH;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.WCTGuiHandler;
|
||||
import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
|
||||
import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
import net.p455w0rd.wirelesscraftingterminal.reference.Reference;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingConfirm;
|
||||
import com.github.vfyjxf.nee.container.WCTContainerCraftingConfirm;
|
||||
import com.github.vfyjxf.nee.network.NEEGuiHandler;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.google.common.base.Optional;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.inventory.item.IWirelessTerminal;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.CraftingMode;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftConfirm;
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
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 thaumicenergistics.common.ThEGuiHandler;
|
||||
import thaumicenergistics.common.container.ContainerPartArcaneCraftingTerminal;
|
||||
|
||||
public class PacketCraftingRequest implements IMessage {
|
||||
|
||||
private IAEItemStack requireToCraftStack;
|
||||
public static int COMMAND_CREATE_PATTERN = 0;
|
||||
public static int COMMAND_REMOVE_PATTERN = 1;
|
||||
public static int COMMAND_OPEN_CRAFT_CONFIRM = 2;
|
||||
|
||||
private String modID = "";
|
||||
private int command = 3;
|
||||
private NBTTagCompound compound;
|
||||
private boolean isAutoStart;
|
||||
private int craftAmount;
|
||||
|
||||
public PacketCraftingRequest() {}
|
||||
|
||||
public PacketCraftingRequest(IAEItemStack requireToCraftStack, boolean isAutoStart) {
|
||||
this.requireToCraftStack = requireToCraftStack;
|
||||
this.isAutoStart = isAutoStart;
|
||||
}
|
||||
|
||||
public PacketCraftingRequest(int craftAmount, boolean isAutoStart) {
|
||||
public PacketCraftingRequest(String modID, int command, NBTTagCompound compound, int craftAmount,
|
||||
boolean isAutoStart) {
|
||||
this.modID = modID;
|
||||
this.command = command;
|
||||
this.compound = compound;
|
||||
this.craftAmount = craftAmount;
|
||||
this.isAutoStart = isAutoStart;
|
||||
}
|
||||
|
||||
public IAEItemStack getRequireToCraftStack() {
|
||||
return requireToCraftStack;
|
||||
public boolean isAutoStart() {
|
||||
return this.isAutoStart;
|
||||
}
|
||||
|
||||
public boolean isAutoStart() {
|
||||
return isAutoStart;
|
||||
public void setIsAutoStart(boolean isAutoStart) {
|
||||
this.isAutoStart = isAutoStart;
|
||||
}
|
||||
|
||||
public int getCraftAmount() {
|
||||
return craftAmount;
|
||||
return Math.max(1, this.craftAmount);
|
||||
}
|
||||
|
||||
public void setCraftAmount(int craftAmount) {
|
||||
this.craftAmount = craftAmount;
|
||||
}
|
||||
|
||||
public void getModID(String modID) {
|
||||
this.modID = modID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
if (buf.readBoolean()) {
|
||||
try {
|
||||
this.requireToCraftStack = AEItemStack.loadItemStackFromPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.modID = ByteBufUtils.readUTF8String(buf);
|
||||
this.command = buf.readInt();
|
||||
this.compound = ByteBufUtils.readTag(buf);
|
||||
this.isAutoStart = buf.readBoolean();
|
||||
this.craftAmount = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
if (this.requireToCraftStack != null) {
|
||||
try {
|
||||
buf.writeBoolean(true);
|
||||
this.requireToCraftStack.writeToPacket(buf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
ByteBufUtils.writeUTF8String(buf, this.modID);
|
||||
buf.writeInt(this.command);
|
||||
ByteBufUtils.writeTag(buf, this.compound);
|
||||
buf.writeBoolean(this.isAutoStart);
|
||||
buf.writeInt(this.craftAmount);
|
||||
}
|
||||
@@ -123,260 +118,249 @@ public class PacketCraftingRequest implements IMessage {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCraftingRequest message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
final Container container = player.openContainer;
|
||||
final IGrid grid = GuiUtils.getGrid(container);
|
||||
|
||||
if (GuiUtils.isWirelessCraftingTermContainer(container)) {
|
||||
message.handlerWirelessCraftingRequest((ContainerWirelessCraftingTerminal) container, message, player);
|
||||
} else if (container instanceof AEBaseContainer) {
|
||||
AEBaseContainer baseContainer = (AEBaseContainer) container;
|
||||
Object target = baseContainer.getTarget();
|
||||
if (target instanceof IGridHost) {
|
||||
final IGridHost gh = (IGridHost) target;
|
||||
final IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
|
||||
if (gn != null) {
|
||||
final IGrid grid = gn.getGrid();
|
||||
if (grid != null) {
|
||||
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
|
||||
if (security != null && security.hasPermission(player, SecurityPermissions.CRAFT)) {
|
||||
if (container instanceof ContainerCraftingTerm) {
|
||||
message.handlerCraftingTermRequest(
|
||||
(ContainerCraftingTerm) container,
|
||||
message,
|
||||
grid,
|
||||
player);
|
||||
}
|
||||
if (grid == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (container instanceof ContainerCraftingAmount) {
|
||||
message.handlerCraftingAmountRequest(
|
||||
(ContainerCraftingAmount) container,
|
||||
message,
|
||||
grid,
|
||||
player);
|
||||
}
|
||||
}
|
||||
}
|
||||
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
|
||||
|
||||
if (security == null || !security.hasPermission(player, SecurityPermissions.CRAFT)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (message.command == COMMAND_REMOVE_PATTERN) {
|
||||
final ItemStack resultStack = ItemStack.loadItemStackFromNBT(message.compound.getCompoundTag("out"));
|
||||
|
||||
if (resultStack != null) {
|
||||
removeRecipePattern(grid, resultStack, message.compound, player);
|
||||
container.detectAndSendChanges();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (message.command == COMMAND_OPEN_CRAFT_CONFIRM) {
|
||||
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
|
||||
final ItemStack resultStack = ItemStack.loadItemStackFromNBT(message.compound);
|
||||
final IAEItemStack requireToCraftStack = getrequireToCraftStack(
|
||||
inv.getItemInventory(),
|
||||
resultStack);
|
||||
|
||||
if (requireToCraftStack != null) {
|
||||
requireToCraftStack.setStackSize(message.getCraftAmount());
|
||||
message.openCraftConfirm(container, grid, requireToCraftStack, player);
|
||||
}
|
||||
} else if (message.command == COMMAND_CREATE_PATTERN) {
|
||||
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
|
||||
final ItemStack resultStack = ItemStack
|
||||
.loadItemStackFromNBT(message.compound.getCompoundTag("out"));
|
||||
createRecipePattern(grid, resultStack, message.compound, player);
|
||||
final IAEItemStack requireToCraftStack = getrequireToCraftStack(
|
||||
inv.getItemInventory(),
|
||||
resultStack);
|
||||
|
||||
if (requireToCraftStack != null) {
|
||||
requireToCraftStack.setStackSize(message.getCraftAmount());
|
||||
message.openCraftConfirm(container, grid, requireToCraftStack, player);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* For some reason,the output from jei is different from the actual one, so apply ItemStack.isItemEqual to
|
||||
* match.
|
||||
*/
|
||||
private IAEItemStack getrequireToCraftStack(IMEMonitor<IAEItemStack> storage, ItemStack resultStack) {
|
||||
|
||||
if (resultStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (IAEItemStack aeStack : storage.getStorageList()) {
|
||||
if (resultStack.isItemEqual(aeStack.getItemStack()) && aeStack.isCraftable()) {
|
||||
return aeStack.copy();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean createRecipePattern(IGrid grid, ItemStack resultStack, NBTTagCompound patternValue,
|
||||
EntityPlayer player) {
|
||||
ItemStack patternStack = AEApi.instance().definitions().items().encodedPattern().maybeStack(1).orNull();
|
||||
|
||||
if (patternStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface tpi) {
|
||||
if (tpi.getProxy().isActive() && tpi.canPutPattern(resultStack)) {
|
||||
patternStack = patternStack.copy();
|
||||
patternStack.setTagCompound(patternValue);
|
||||
tpi.putPattern(patternStack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeRecipePattern(IGrid grid, ItemStack resultStack, NBTTagCompound patternValue,
|
||||
EntityPlayer player) {
|
||||
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface tpi) {
|
||||
final AppEngInternalInventory inventory = tpi.getPatternInventory();
|
||||
|
||||
for (int slotIndex = 0; slotIndex < inventory.getSizeInventory(); slotIndex++) {
|
||||
final ItemStack patternStack = inventory.getStackInSlot(slotIndex);
|
||||
|
||||
if (patternStack != null && patternValue.equals(patternStack.getTagCompound())) {
|
||||
inventory.setInventorySlotContents(slotIndex, null);
|
||||
tpi.updateCraftingList();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handlerCraftingTermRequest(ContainerCraftingTerm container, PacketCraftingRequest message, IGrid grid,
|
||||
public void openCraftConfirm(Container container, IGrid grid, IAEItemStack requireToCraftStack,
|
||||
EntityPlayerMP player) {
|
||||
if (message.getRequireToCraftStack() != null) {
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
|
||||
futureJob = cg.beginCraftingJob(
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.ThE) && this.modID.equals(ModIDs.ThE)
|
||||
&& container instanceof ContainerPartArcaneCraftingTerminal cpact) {
|
||||
openTHContainerCraftConfirm(grid, requireToCraftStack, (IActionHost) cpact.terminal, player);
|
||||
} else if (container instanceof AEBaseContainer baseContainer) {
|
||||
if (Loader.isModLoaded(ModIDs.ThE) && this.modID.equals(ModIDs.ThE)) {
|
||||
openTHContainerCraftConfirm(grid, requireToCraftStack, (IActionHost) baseContainer.getTarget(), player);
|
||||
} else if (Loader.isModLoaded(ModIDs.FC) && this.modID.equals(ModIDs.FC)) {
|
||||
openFCContainerCraftConfirm(baseContainer, grid, requireToCraftStack, player);
|
||||
} else if (Loader.isModLoaded(ModIDs.WCT) && this.modID.equals(ModIDs.WCT)) {
|
||||
openWCTContainerCraftConfirm(baseContainer, grid, requireToCraftStack, player);
|
||||
} else {
|
||||
openAEContainerCraftConfirm(baseContainer, grid, requireToCraftStack, player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void openContainerCraftConfirm(IGrid grid, IAEItemStack requireToCraftStack, EntityPlayerMP player,
|
||||
BaseActionSource actionSource, Consumer<Future<ICraftingJob>> consumer) {
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
|
||||
try {
|
||||
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
|
||||
|
||||
if (cg instanceof CraftingGridCache cgc) {
|
||||
futureJob = cgc.beginCraftingJob(
|
||||
player.worldObj,
|
||||
grid,
|
||||
container.getActionSource(),
|
||||
message.getRequireToCraftStack(),
|
||||
actionSource,
|
||||
requireToCraftStack,
|
||||
CraftingMode.STANDARD,
|
||||
null);
|
||||
|
||||
final ContainerOpenContext context = container.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
Platform.openGUI(player, te, container.getOpenContext().getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
|
||||
if (player.openContainer instanceof ContainerCraftConfirm) {
|
||||
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
|
||||
ccc.setItemToCraft(message.getRequireToCraftStack());
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setAutoStart(message.isAutoStart());
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
} else {
|
||||
futureJob = cg.beginCraftingJob(player.worldObj, grid, actionSource, requireToCraftStack, null);
|
||||
}
|
||||
|
||||
consumer.accept(futureJob);
|
||||
|
||||
if (player.openContainer instanceof ContainerCraftConfirm ccc) {
|
||||
ccc.setItemToCraft(requireToCraftStack);
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setAutoStart(this.isAutoStart);
|
||||
ccc.detectAndSendChanges();
|
||||
}
|
||||
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handlerCraftingAmountRequest(ContainerCraftingAmount container, PacketCraftingRequest message,
|
||||
IGrid grid, EntityPlayerMP player) {
|
||||
if (container.getResultStack() != null) {
|
||||
private void openAEContainerCraftConfirm(AEBaseContainer baseContainer, IGrid grid,
|
||||
IAEItemStack requireToCraftStack, EntityPlayerMP player) {
|
||||
|
||||
Pair<TilePatternInterface, Integer> pair = setRecipe(grid, container.getRecipe(), player);
|
||||
if (pair != null) {
|
||||
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
|
||||
final IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
|
||||
final IItemList<IAEItemStack> all = storage.getStorageList();
|
||||
ItemStack resultStack = container.getResultStack().copy();
|
||||
IAEItemStack result = null;
|
||||
/*
|
||||
* For some reason,the output from jei is different from the actual one, so apply ItemStack.isItemEqual
|
||||
* to match.
|
||||
*/
|
||||
for (IAEItemStack aeStack : all) {
|
||||
if (resultStack.isItemEqual(aeStack.getItemStack()) && aeStack.isCraftable()) {
|
||||
result = aeStack.copy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
openContainerCraftConfirm(grid, requireToCraftStack, player, baseContainer.getActionSource(), job -> {
|
||||
final ContainerOpenContext openContext = baseContainer.getOpenContext();
|
||||
Platform.openGUI(player, openContext.getTile(), openContext.getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
|
||||
});
|
||||
|
||||
if (result != null) {
|
||||
result.setStackSize(message.getCraftAmount());
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
|
||||
futureJob = cg
|
||||
.beginCraftingJob(player.worldObj, grid, container.getActionSource(), result, null);
|
||||
|
||||
final ContainerOpenContext context = container.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity te = context.getTile();
|
||||
NEEGuiHandler.openGui(player, NEEGuiHandler.CRAFTING_CONFIRM_ID, te, context.getSide());
|
||||
if (player.openContainer instanceof ContainerCraftingConfirm) {
|
||||
final ContainerCraftingConfirm ccc = (ContainerCraftingConfirm) player.openContainer;
|
||||
ccc.setItemToCraft(result);
|
||||
ccc.setAutoStart(message.isAutoStart());
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setTile(pair.getLeft());
|
||||
ccc.setPatternIndex(pair.getRight());
|
||||
ccc.detectAndSendChanges();
|
||||
}
|
||||
} else if (Loader.isModLoaded(ModIDs.WCT)) {
|
||||
|
||||
NEEGuiHandler.openGui(player, NEEGuiHandler.CRAFTING_CONFIRM_WIRELESS_ID, player.worldObj);
|
||||
|
||||
if (player.openContainer instanceof WCTContainerCraftingConfirm) {
|
||||
final WCTContainerCraftingConfirm ccc = (WCTContainerCraftingConfirm) player.openContainer;
|
||||
ccc.setItemToCraft(result);
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setAutoStart(message.isAutoStart());
|
||||
ccc.setTile(pair.getLeft());
|
||||
ccc.setPatternIndex(pair.getRight());
|
||||
ccc.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlerWirelessCraftingRequest(ContainerWirelessCraftingTerminal container,
|
||||
PacketCraftingRequest message, EntityPlayerMP player) {
|
||||
Object target = container.getTarget();
|
||||
if (target instanceof WirelessTerminalGuiObject) {
|
||||
IGrid grid = ((WirelessTerminalGuiObject) target).getTargetGrid();
|
||||
if (grid != null) {
|
||||
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
|
||||
if (security != null && security.hasPermission(player, SecurityPermissions.CRAFT)
|
||||
&& message.getRequireToCraftStack() != null) {
|
||||
Future<ICraftingJob> futureJob = null;
|
||||
try {
|
||||
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
|
||||
futureJob = cg.beginCraftingJob(
|
||||
player.worldObj,
|
||||
grid,
|
||||
container.getActionSource(),
|
||||
message.getRequireToCraftStack(),
|
||||
null);
|
||||
@Optional.Method(modid = ModIDs.ThE)
|
||||
private void openTHContainerCraftConfirm(IGrid grid, IAEItemStack requireToCraftStack, IActionHost host,
|
||||
EntityPlayerMP player) {
|
||||
|
||||
int x = (int) player.posX;
|
||||
int y = (int) player.posY;
|
||||
int z = (int) player.posZ;
|
||||
openContainerCraftConfirm(
|
||||
grid,
|
||||
requireToCraftStack,
|
||||
player,
|
||||
new PlayerSource(player, host),
|
||||
job -> {
|
||||
ThEGuiHandler.launchGui(ThEGuiHandler.AUTO_CRAFTING_CONFIRM, player, player.worldObj, 0, 0, 0);
|
||||
});
|
||||
|
||||
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
|
||||
|
||||
if (player.openContainer instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) {
|
||||
final net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm ccc = (net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm) player.openContainer;
|
||||
ccc.setItemToCraft(message.getRequireToCraftStack());
|
||||
ccc.setJob(futureJob);
|
||||
ccc.setAutoStart(message.isAutoStart());
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
if (futureJob != null) {
|
||||
futureJob.cancel(true);
|
||||
}
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Pair<TilePatternInterface, Integer> setRecipe(IGrid grid, NBTTagCompound recipe, EntityPlayer player) {
|
||||
@Optional.Method(modid = ModIDs.FC)
|
||||
private void openFCContainerCraftConfirm(AEBaseContainer baseContainer, IGrid grid,
|
||||
IAEItemStack requireToCraftStack, EntityPlayerMP player) {
|
||||
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
openContainerCraftConfirm(grid, requireToCraftStack, player, baseContainer.getActionSource(), job -> {
|
||||
final ContainerOpenContext openContext = baseContainer.getOpenContext();
|
||||
final TileEntity tileEntity = openContext.getTile();
|
||||
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface) {
|
||||
|
||||
TilePatternInterface tpi = (TilePatternInterface) gridNode.getMachine();
|
||||
NBTTagCompound currentTag = recipe.getCompoundTag(OUTPUT_KEY);
|
||||
ItemStack result = currentTag == null ? null : ItemStack.loadItemStackFromNBT(currentTag);
|
||||
|
||||
if (tpi.getProxy().isActive() && tpi.canPutPattern(result)) {
|
||||
|
||||
ItemStack patternStack = getPatternStack(player, recipe);
|
||||
|
||||
if (patternStack != null) {
|
||||
|
||||
int patternIndex = tpi.putPattern(patternStack);
|
||||
if (patternIndex >= 0) {
|
||||
return Pair.of(tpi, patternIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tileEntity != null) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(tileEntity),
|
||||
Objects.requireNonNull(openContext.getSide()),
|
||||
GuiType.FLUID_CRAFTING_CONFIRM);
|
||||
} else if (baseContainer.getTarget() instanceof IWirelessTerminal wireless) {
|
||||
InventoryHandler.openGui(
|
||||
player,
|
||||
player.worldObj,
|
||||
new BlockPos(wireless.getInventorySlot(), 0, 0),
|
||||
Objects.requireNonNull(openContext.getSide()),
|
||||
GuiType.FLUID_CRAFTING_CONFIRM_ITEM);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private ItemStack getPatternStack(EntityPlayer player, NBTTagCompound recipe) {
|
||||
ItemStack[] recipeInputs = new ItemStack[RECIPE_LENGTH];
|
||||
NBTTagCompound currentStack;
|
||||
for (int i = 0; i < recipeInputs.length; i++) {
|
||||
currentStack = recipe.getCompoundTag(INPUT_KEY + i);
|
||||
recipeInputs[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
for (int i = 0; i < RECIPE_LENGTH; i++) {
|
||||
ic.setInventorySlotContents(i, recipeInputs[i]);
|
||||
}
|
||||
@Optional.Method(modid = ModIDs.WCT)
|
||||
private void openWCTContainerCraftConfirm(AEBaseContainer baseContainer, IGrid grid,
|
||||
IAEItemStack requireToCraftStack, EntityPlayerMP player) {
|
||||
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(ic, player.worldObj);
|
||||
if (result != null) {
|
||||
ItemStack patternStack = null;
|
||||
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
|
||||
if (maybePattern.isPresent()) {
|
||||
patternStack = maybePattern.get();
|
||||
}
|
||||
if (patternStack != null) {
|
||||
final NBTTagCompound patternValue = new NBTTagCompound();
|
||||
final NBTTagList tagIn = new NBTTagList();
|
||||
for (ItemStack stack : recipeInputs) {
|
||||
tagIn.appendTag(crateItemTag(stack));
|
||||
}
|
||||
patternValue.setTag("in", tagIn);
|
||||
patternValue.setTag("out", result.writeToNBT(new NBTTagCompound()));
|
||||
patternValue.setBoolean("crafting", true);
|
||||
patternValue.setBoolean("substitute", false);
|
||||
openContainerCraftConfirm(grid, requireToCraftStack, player, baseContainer.getActionSource(), job -> {
|
||||
final int x = (int) player.posX;
|
||||
final int y = (int) player.posY;
|
||||
final int z = (int) player.posZ;
|
||||
|
||||
patternStack.setTagCompound(patternValue);
|
||||
return patternStack;
|
||||
}
|
||||
}
|
||||
WCTGuiHandler.launchGui(Reference.GUI_CRAFT_CONFIRM, player, player.worldObj, x, y, z);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private NBTTagCompound crateItemTag(ItemStack itemStack) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
if (itemStack != null) {
|
||||
itemStack.writeToNBT(tag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.implementations.ContainerMEMonitorable;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
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 cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import thaumicenergistics.common.container.ContainerPartArcaneCraftingTerminal;
|
||||
|
||||
public class PacketNEIBookmark implements IMessage {
|
||||
|
||||
private NBTTagCompound bookmarkItems;
|
||||
|
||||
public PacketNEIBookmark() {}
|
||||
|
||||
public PacketNEIBookmark(NBTTagCompound bookmarkItems) {
|
||||
this.bookmarkItems = bookmarkItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.bookmarkItems = ByteBufUtils.readTag(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, this.bookmarkItems);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketNEIBookmark, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNEIBookmark message, MessageContext ctx) {
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
final Container container = player.openContainer;
|
||||
|
||||
if (message.bookmarkItems == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (container instanceof ContainerMEMonitorable monitorable) {
|
||||
final IMEMonitor<IAEItemStack> monitor = monitorable.getMonitor();
|
||||
if (monitor != null) {
|
||||
final IEnergySource energy = monitorable.getPowerSource();
|
||||
final BaseActionSource actionSource = monitorable.getActionSource();
|
||||
|
||||
for (Object key : message.bookmarkItems.func_150296_c()) {
|
||||
final ItemStack bookmarkItem = ItemUtils
|
||||
.loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key));
|
||||
bookmarkItem.stackSize = getFreeStackSize(player, bookmarkItem);
|
||||
|
||||
if (bookmarkItem.stackSize > 0) {
|
||||
final AEItemStack requestStack = AEItemStack.create(bookmarkItem);
|
||||
final IAEItemStack extractedStack = Platform
|
||||
.poweredExtraction(energy, monitor, requestStack, actionSource);
|
||||
|
||||
if (extractedStack != null) {
|
||||
InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN)
|
||||
.addItems(extractedStack.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (Loader.isModLoaded(ModIDs.ThE) && container instanceof ContainerPartArcaneCraftingTerminal act) {
|
||||
final IMEMonitor<IAEItemStack> monitor = getMonitor(container);
|
||||
final IGrid grid = act.getHostGrid();
|
||||
if (grid == null || monitor == null) return null;
|
||||
final IEnergyGrid energy = grid.getCache(IEnergyGrid.class);
|
||||
final BaseActionSource actionSource = new PlayerSource(player, act.terminal);
|
||||
|
||||
for (Object key : message.bookmarkItems.func_150296_c()) {
|
||||
final ItemStack bookmarkItem = ItemUtils
|
||||
.loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key));
|
||||
bookmarkItem.stackSize = getFreeStackSize(player, bookmarkItem);
|
||||
|
||||
if (bookmarkItem.stackSize > 0) {
|
||||
final AEItemStack requestStack = AEItemStack.create(bookmarkItem);
|
||||
final IAEItemStack extractedStack = Platform
|
||||
.poweredExtraction(energy, monitor, requestStack, actionSource);
|
||||
|
||||
if (extractedStack != null) {
|
||||
InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN)
|
||||
.addItems(extractedStack.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getFreeStackSize(EntityPlayer player, ItemStack itemStack) {
|
||||
int freeStackSize = 0;
|
||||
|
||||
for (ItemStack slotStack : player.inventory.mainInventory) {
|
||||
if (slotStack == null) { // Empty slot, stack fits completely
|
||||
freeStackSize += itemStack.getMaxStackSize();
|
||||
} else if (slotStack.isItemEqual(itemStack)) {
|
||||
freeStackSize += itemStack.getMaxStackSize() - slotStack.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.min(itemStack.stackSize, freeStackSize);
|
||||
}
|
||||
|
||||
private IMEMonitor<IAEItemStack> getMonitor(Container container) {
|
||||
|
||||
try {
|
||||
return (IMEMonitor<IAEItemStack>) ReflectionHelper.findField(container.getClass(), "monitor")
|
||||
.get(container);
|
||||
} catch (UnableToFindFieldException | IllegalAccessException e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler.OUTPUT_KEY;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -13,7 +14,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.github.vfyjxf.nee.utils.ModIDs;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -21,10 +21,8 @@ import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.container.implementations.ContainerPatternTermEx;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
@@ -68,50 +66,53 @@ public class PacketNEIPatternRecipe implements IMessage {
|
||||
public IMessage onMessage(PacketNEIPatternRecipe message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof ContainerPatternTerm && message.output == null) {
|
||||
((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(true);
|
||||
message.craftingTableRecipeHandler((ContainerPatternTerm) container, message);
|
||||
} else if (container instanceof ContainerPatternTerm) {
|
||||
((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(false);
|
||||
message.processRecipeHandler((ContainerPatternTerm) container, message);
|
||||
} else if (container instanceof ContainerPatternTermEx && message.output != null) {
|
||||
((ContainerPatternTermEx) container).getPatternTerminal().setInverted(false);
|
||||
message.processRecipeHandler((ContainerPatternTermEx) container, message);
|
||||
|
||||
if (message.input != null && container instanceof AEBaseContainer
|
||||
&& container instanceof IContainerCraftingPacket) {
|
||||
AEBaseContainer baseContainer = (AEBaseContainer) container;
|
||||
setCraftingRecipe(baseContainer, message.output == null);
|
||||
|
||||
if (message.output == null) {
|
||||
craftingRecipe(baseContainer, message);
|
||||
} else {
|
||||
processRecipe(baseContainer, message);
|
||||
}
|
||||
}
|
||||
if (Loader.isModLoaded(ModIDs.FC)) addFluidCraftSupport(message, ctx);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = ModIDs.FC)
|
||||
private void addFluidCraftSupport(PacketNEIPatternRecipe message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof ContainerFluidPatternTerminal && message.output == null) {
|
||||
((ContainerFluidPatternTerminal) container).getPatternTerminal().setCraftingRecipe(true);
|
||||
message.craftingTableRecipeHandler((ContainerFluidPatternTerminal) container, message);
|
||||
} else if (container instanceof ContainerFluidPatternTerminal) {
|
||||
((ContainerFluidPatternTerminal) container).getPatternTerminal().setCraftingRecipe(false);
|
||||
message.processRecipeHandler((ContainerFluidPatternTerminal) container, message);
|
||||
} else if (container instanceof ContainerFluidPatternTerminalEx) {
|
||||
message.processRecipeHandler((ContainerFluidPatternTerminalEx) container, message);
|
||||
private void setCraftingRecipe(AEBaseContainer container, boolean craftingMode) {
|
||||
|
||||
if (container instanceof ContainerPatternTerm cpt) {
|
||||
cpt.getPatternTerminal().setCraftingRecipe(craftingMode);
|
||||
} else if (Loader.isModLoaded(ModIDs.FC) && container instanceof ContainerFluidPatternTerminal cfpt) {
|
||||
cfpt.getPatternTerminal().setCraftingRecipe(craftingMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void craftingTableRecipeHandler(AEBaseContainer container, PacketNEIPatternRecipe message) {
|
||||
ItemStack[] recipeInput = new ItemStack[9];
|
||||
NBTTagCompound currentStack;
|
||||
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
currentStack = (NBTTagCompound) message.input.getTag("#" + i);
|
||||
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
|
||||
final IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
|
||||
final IGridNode node = cct.getNetworkNode();
|
||||
private ItemStack[] getMatrix(NBTTagCompound items, String prefix, int size) {
|
||||
ItemStack[] matrix = new ItemStack[size];
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
NBTTagCompound currentStack = (NBTTagCompound) items.getTag(prefix + i);
|
||||
matrix[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
private void craftingRecipe(AEBaseContainer container, PacketNEIPatternRecipe message) {
|
||||
final IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
|
||||
final IGridNode node = cct.getNetworkNode();
|
||||
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
final IGrid grid = node.getGrid();
|
||||
|
||||
if (grid == null) {
|
||||
return;
|
||||
}
|
||||
@@ -120,62 +121,53 @@ public class PacketNEIPatternRecipe implements IMessage {
|
||||
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
|
||||
final IInventory craftMatrix = cct.getInventoryByName("crafting");
|
||||
|
||||
if (inv != null && message.input != null && security != null) {
|
||||
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
||||
ItemStack currentItem = null;
|
||||
if (recipeInput[i] != null) {
|
||||
currentItem = recipeInput[i].copy();
|
||||
}
|
||||
craftMatrix.setInventorySlotContents(i, currentItem);
|
||||
if (inv != null && craftMatrix != null && security != null) {
|
||||
final ItemStack[] recipeInput = getMatrix(message.input, INPUT_KEY, craftMatrix.getSizeInventory());
|
||||
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
craftMatrix.setInventorySlotContents(i, recipeInput[i]);
|
||||
}
|
||||
|
||||
container.onCraftMatrixChanged(craftMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processRecipeHandler(AEBaseContainer container, PacketNEIPatternRecipe message) {
|
||||
final IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
|
||||
final IGridNode node = cct.getNetworkNode();
|
||||
private void processRecipe(AEBaseContainer container, PacketNEIPatternRecipe message) {
|
||||
final IContainerCraftingPacket cct = (IContainerCraftingPacket) container;
|
||||
final IGridNode node = cct.getNetworkNode();
|
||||
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
final IGrid grid = node.getGrid();
|
||||
|
||||
if (grid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
|
||||
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
|
||||
final IInventory craftMatrix = cct.getInventoryByName("crafting");
|
||||
final IInventory outputMatrix = cct.getInventoryByName("output");
|
||||
ItemStack[] recipeInput = new ItemStack[craftMatrix.getSizeInventory()];
|
||||
ItemStack[] recipeOutput = new ItemStack[outputMatrix.getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
NBTTagCompound currentStack = (NBTTagCompound) message.input.getTag("#" + i);
|
||||
recipeInput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
if (inv != null && craftMatrix != null && outputMatrix != null && security != null) {
|
||||
final ItemStack[] recipeInput = getMatrix(message.input, INPUT_KEY, craftMatrix.getSizeInventory());
|
||||
final ItemStack[] recipeOutput = getMatrix(message.output, OUTPUT_KEY, outputMatrix.getSizeInventory());
|
||||
|
||||
for (int i = 0; i < recipeOutput.length; i++) {
|
||||
NBTTagCompound currentStack = (NBTTagCompound) message.output.getTag(OUTPUT_KEY + i);
|
||||
recipeOutput[i] = currentStack == null ? null : ItemUtils.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
if (inv != null && message.input != null && security != null) {
|
||||
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
||||
ItemStack currentItem = null;
|
||||
if (recipeInput[i] != null) {
|
||||
currentItem = recipeInput[i].copy();
|
||||
}
|
||||
craftMatrix.setInventorySlotContents(i, currentItem);
|
||||
for (int i = 0; i < recipeInput.length; i++) {
|
||||
craftMatrix.setInventorySlotContents(i, recipeInput[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < outputMatrix.getSizeInventory(); i++) {
|
||||
ItemStack currentItem = null;
|
||||
if (recipeOutput[i] != null) {
|
||||
currentItem = recipeOutput[i].copy();
|
||||
}
|
||||
outputMatrix.setInventorySlotContents(i, currentItem);
|
||||
for (int i = 0; i < recipeOutput.length; i++) {
|
||||
outputMatrix.setInventorySlotContents(i, recipeOutput[i]);
|
||||
}
|
||||
|
||||
container.onCraftMatrixChanged(craftMatrix);
|
||||
container.onCraftMatrixChanged(outputMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.network.NEEGuiHandler.CRAFTING_AMOUNT_ID;
|
||||
import static com.github.vfyjxf.nee.network.NEEGuiHandler.CRAFTING_AMOUNT_WIRELESS_ID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.github.vfyjxf.nee.container.ContainerCraftingAmount;
|
||||
import com.github.vfyjxf.nee.network.NEEGuiHandler;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
|
||||
import appeng.container.ContainerOpenContext;
|
||||
import appeng.container.implementations.ContainerCraftingTerm;
|
||||
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;
|
||||
|
||||
public class PacketOpenCraftAmount implements IMessage {
|
||||
|
||||
private NBTTagCompound recipe;
|
||||
|
||||
public PacketOpenCraftAmount() {}
|
||||
|
||||
public PacketOpenCraftAmount(NBTTagCompound recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.recipe = ByteBufUtils.readTag(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, this.recipe);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketOpenCraftAmount, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketOpenCraftAmount message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof ContainerCraftingTerm) {
|
||||
final ContainerOpenContext context = ((ContainerCraftingTerm) container).getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity tile = context.getTile();
|
||||
|
||||
NEEGuiHandler.openGui(player, CRAFTING_AMOUNT_ID, tile, context.getSide());
|
||||
|
||||
if (player.openContainer instanceof ContainerCraftingAmount) {
|
||||
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
|
||||
if (message.recipe != null) {
|
||||
NBTTagCompound tag = message.recipe.getCompoundTag(OUTPUT_KEY);
|
||||
ItemStack result = tag == null ? null : ItemStack.loadItemStackFromNBT(tag);
|
||||
if (result != null) {
|
||||
cca.setResultStack(result);
|
||||
cca.getResultSlot().putStack(result);
|
||||
cca.setRecipe(message.recipe);
|
||||
}
|
||||
}
|
||||
cca.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} else if (GuiUtils.isWirelessCraftingTermContainer(container)) {
|
||||
|
||||
NEEGuiHandler.openGui(player, CRAFTING_AMOUNT_WIRELESS_ID, player.worldObj);
|
||||
|
||||
if (player.openContainer instanceof ContainerCraftingAmount) {
|
||||
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
|
||||
if (message.recipe != null) {
|
||||
NBTTagCompound tag = message.recipe.getCompoundTag(OUTPUT_KEY);
|
||||
ItemStack result = tag == null ? null : ItemStack.loadItemStackFromNBT(tag);
|
||||
cca.setResultStack(result);
|
||||
cca.getResultSlot().putStack(result);
|
||||
cca.setRecipe(message.recipe);
|
||||
}
|
||||
cca.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.github.vfyjxf.nee.network.NEEGuiHandler;
|
||||
@@ -37,15 +36,16 @@ public class PacketOpenGui implements IMessage {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketOpenGui message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
if (container instanceof AEBaseContainer) {
|
||||
final ContainerOpenContext context = ((AEBaseContainer) container).getOpenContext();
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
if (player.openContainer instanceof AEBaseContainer baseContainer) {
|
||||
final ContainerOpenContext context = baseContainer.getOpenContext();
|
||||
if (context != null) {
|
||||
final TileEntity tile = context.getTile();
|
||||
NEEGuiHandler.openGui(player, message.guiId, tile, context.getSide());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.github.vfyjxf.nee.network.packet;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.INPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY;
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.RECIPE_LENGTH;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.ContainerNull;
|
||||
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;
|
||||
|
||||
public class PacketSetRecipe implements IMessage {
|
||||
|
||||
private NBTTagCompound recipe;
|
||||
|
||||
public PacketSetRecipe() {}
|
||||
|
||||
public PacketSetRecipe(NBTTagCompound recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.recipe = ByteBufUtils.readTag(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, this.recipe);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketSetRecipe, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSetRecipe message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof AEBaseContainer) {
|
||||
AEBaseContainer aeContainer = (AEBaseContainer) container;
|
||||
IGrid grid = message.getNetwork(aeContainer);
|
||||
if (grid != null) {
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface) {
|
||||
|
||||
TilePatternInterface tpi = (TilePatternInterface) gridNode.getMachine();
|
||||
NBTTagCompound currentTag = message.recipe.getCompoundTag(OUTPUT_KEY);
|
||||
ItemStack result = currentTag == null ? null : ItemStack.loadItemStackFromNBT(currentTag);
|
||||
|
||||
if (tpi.getProxy().isActive() && tpi.canPutPattern(result)) {
|
||||
|
||||
ItemStack patternStack = message.getPatternStack(player, message.recipe);
|
||||
|
||||
if (patternStack != null) {
|
||||
|
||||
// if (tpi.putPattern(patternStack)) {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IGrid getNetwork(AEBaseContainer container) {
|
||||
if (container.getTarget() instanceof IActionHost) {
|
||||
IActionHost ah = (IActionHost) container.getTarget();
|
||||
IGridNode gn = ah.getActionableNode();
|
||||
return gn.getGrid();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack getPatternStack(EntityPlayer player, NBTTagCompound recipe) {
|
||||
ItemStack[] recipeInputs = new ItemStack[RECIPE_LENGTH];
|
||||
NBTTagCompound currentStack;
|
||||
for (int i = 0; i < recipeInputs.length; i++) {
|
||||
currentStack = recipe.getCompoundTag(INPUT_KEY + i);
|
||||
recipeInputs[i] = currentStack == null ? null : ItemStack.loadItemStackFromNBT(currentStack);
|
||||
}
|
||||
InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
|
||||
for (int i = 0; i < RECIPE_LENGTH; i++) {
|
||||
ic.setInventorySlotContents(i, recipeInputs[i]);
|
||||
}
|
||||
|
||||
ItemStack result = CraftingManager.getInstance().findMatchingRecipe(ic, player.worldObj);
|
||||
if (result != null) {
|
||||
ItemStack patternStack = null;
|
||||
Optional<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
|
||||
if (maybePattern.isPresent()) {
|
||||
patternStack = maybePattern.get();
|
||||
}
|
||||
if (patternStack != null) {
|
||||
final NBTTagCompound patternValue = new NBTTagCompound();
|
||||
final NBTTagList tagIn = new NBTTagList();
|
||||
for (ItemStack stack : recipeInputs) {
|
||||
tagIn.appendTag(crateItemTag(stack));
|
||||
}
|
||||
patternValue.setTag("in", tagIn);
|
||||
patternValue.setTag("out", result.writeToNBT(new NBTTagCompound()));
|
||||
patternValue.setBoolean("crafting", true);
|
||||
patternValue.setBoolean("substitute", false);
|
||||
|
||||
patternStack.setTagCompound(patternValue);
|
||||
return patternStack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private NBTTagCompound crateItemTag(ItemStack itemStack) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
if (itemStack != null) {
|
||||
itemStack.writeToNBT(tag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import java.util.List;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.utils.ItemUtils;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
@@ -52,7 +54,7 @@ public class PacketSlotStackChange implements IMessage {
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, ItemUtils.writeItemStackToNBT(this.stack, new NBTTagCompound()));
|
||||
ByteBufUtils.writeTag(buf, ItemUtils.writeItemStackToNBT(this.stack, this.stack.stackSize));
|
||||
buf.writeInt(this.craftingSlots.size());
|
||||
for (Integer craftingSlot : this.craftingSlots) {
|
||||
buf.writeInt(craftingSlot);
|
||||
@@ -66,6 +68,12 @@ public class PacketSlotStackChange implements IMessage {
|
||||
Container container = ctx.getServerHandler().playerEntity.openContainer;
|
||||
ItemStack nextStack = message.getStack();
|
||||
if (nextStack != null) {
|
||||
|
||||
if (GuiUtils.isFluidCraftPatternContainer(container)
|
||||
&& StackInfo.itemStackToNBT(nextStack).hasKey("gtFluidName")) {
|
||||
nextStack = ItemFluidPacket.newStack(StackInfo.getFluid(nextStack));
|
||||
}
|
||||
|
||||
for (Integer craftingSlot : message.getCraftingSlots()) {
|
||||
Slot currentSlot = container.getSlot(craftingSlot);
|
||||
if (currentSlot != null) {
|
||||
|
||||
@@ -4,9 +4,14 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.glodblock.github.common.item.ItemFluidPacket;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
@@ -66,15 +71,19 @@ public class PacketStackCountChange implements IMessage {
|
||||
}
|
||||
|
||||
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 > 0) {
|
||||
ItemStack nextStack = currentSlot.getStack().copy();
|
||||
nextStack.stackSize = currentStackSize;
|
||||
currentSlot.putStack(nextStack);
|
||||
|
||||
if (currentSlot.getHasStack()) {
|
||||
ItemStack stack = currentSlot.getStack();
|
||||
|
||||
if (GuiUtils.isFluidCraftPatternContainer(container)
|
||||
&& StackInfo.itemStackToNBT(stack).hasKey("gtFluidName")) {
|
||||
FluidStack fluid = StackInfo.getFluid(stack);
|
||||
fluid.amount = Math.max(1, fluid.amount + message.getChangeCount());
|
||||
currentSlot.putStack(ItemFluidPacket.newStack(fluid));
|
||||
} else {
|
||||
break;
|
||||
stack = stack.copy();
|
||||
stack.stackSize = Math.max(1, stack.stackSize + message.getChangeCount());
|
||||
currentSlot.putStack(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ package com.github.vfyjxf.nee.network.packet;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
|
||||
import com.github.vfyjxf.nee.utils.GuiUtils;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingPreviewHandler;
|
||||
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
@@ -22,30 +21,30 @@ import io.netty.buffer.ByteBuf;
|
||||
public class PacketValueConfigClient implements IMessage {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
private boolean value;
|
||||
|
||||
public PacketValueConfigClient() {}
|
||||
|
||||
public PacketValueConfigClient(String name, String value) {
|
||||
public PacketValueConfigClient(String name, boolean value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public PacketValueConfigClient(String name) {
|
||||
this.name = name;
|
||||
this.value = "";
|
||||
this.value = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.name = ByteBufUtils.readUTF8String(buf);
|
||||
this.value = ByteBufUtils.readUTF8String(buf);
|
||||
this.value = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, this.name);
|
||||
ByteBufUtils.writeUTF8String(buf, this.value);
|
||||
buf.writeBoolean(this.value);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<PacketValueConfigClient, IMessage> {
|
||||
@@ -60,15 +59,10 @@ public class PacketValueConfigClient implements IMessage {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void handMessage(PacketValueConfigClient message, MessageContext ctx) {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if ("PatternInterface.check".equals(message.name)) {
|
||||
if (gui instanceof GuiRecipe) {
|
||||
GuiRecipe guiRecipe = (GuiRecipe) gui;
|
||||
if (GuiUtils.isGuiCraftingTerm(guiRecipe.firstGui)) {
|
||||
boolean value = Boolean.parseBoolean(message.value);
|
||||
NEECraftingHelper.setIsPatternInterfaceExists(value);
|
||||
}
|
||||
}
|
||||
final GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
if ("PatternInterface.check".equals(message.name) && gui instanceof GuiRecipe<?>) {
|
||||
NEECraftingPreviewHandler.instance.setIsPatternInterfaceExists(message.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,13 @@ package com.github.vfyjxf.nee.network.packet;
|
||||
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;
|
||||
|
||||
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 appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
@@ -75,44 +71,23 @@ public class PacketValueConfigServer implements IMessage {
|
||||
tile.updateCraftingList();
|
||||
}
|
||||
} else if ("PatternInterface.check".equals(message.name)) {
|
||||
if (container instanceof AEBaseContainer) {
|
||||
IGrid grid = message.getNetwork((AEBaseContainer) container);
|
||||
if (grid != null) {
|
||||
final IGrid grid = GuiUtils.getGrid(container);
|
||||
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
if (grid != null) {
|
||||
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface) {
|
||||
NEENetworkHandler.getInstance()
|
||||
.sendTo(new PacketValueConfigClient("PatternInterface.check", "true"), player);
|
||||
return null;
|
||||
}
|
||||
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
|
||||
if (gridNode.getMachine() instanceof TilePatternInterface) {
|
||||
return new PacketValueConfigClient("PatternInterface.check", true);
|
||||
}
|
||||
|
||||
NEENetworkHandler.getInstance()
|
||||
.sendTo(new PacketValueConfigClient("PatternInterface.check", "false"), player);
|
||||
}
|
||||
|
||||
return new PacketValueConfigClient("PatternInterface.check", false);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IGrid getNetwork(AEBaseContainer container) {
|
||||
if (container.getTarget() instanceof IActionHost) {
|
||||
IActionHost ah = (IActionHost) container.getTarget();
|
||||
IGridNode gn = ah.getActionableNode();
|
||||
return gn.getGrid();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IGrid getNetwork(ContainerWirelessCraftingTerminal container) {
|
||||
|
||||
if (container.getTarget() instanceof WirelessTerminalGuiObject) {
|
||||
return ((WirelessTerminalGuiObject) container.getTarget()).getTargetGrid();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.github.vfyjxf.nee.NEECommands;
|
||||
import com.github.vfyjxf.nee.client.GuiEventHandler;
|
||||
import com.github.vfyjxf.nee.client.NEEContainerDrawHandler;
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingHelper;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingPreviewHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEECraftingTerminalHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEExtremeAutoCrafterHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEKnowledgeInscriberHandler;
|
||||
import com.github.vfyjxf.nee.nei.NEEPatternTerminalHandler;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
@@ -20,11 +22,10 @@ public class ClientProxy extends CommonProxy {
|
||||
ClientCommandHandler.instance.registerCommand(new NEECommands());
|
||||
FMLCommonHandler.instance().bus().register(GuiEventHandler.instance);
|
||||
MinecraftForge.EVENT_BUS.register(GuiEventHandler.instance);
|
||||
if (NEEConfig.noShift) {
|
||||
MinecraftForge.EVENT_BUS.register(NEECraftingHelper.INSTANCE);
|
||||
}
|
||||
if (NEEConfig.drawHighlight) {
|
||||
MinecraftForge.EVENT_BUS.register(NEEContainerDrawHandler.instance);
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.register(NEECraftingTerminalHandler.instance);
|
||||
MinecraftForge.EVENT_BUS.register(NEEPatternTerminalHandler.instance);
|
||||
MinecraftForge.EVENT_BUS.register(NEEExtremeAutoCrafterHandler.instance);
|
||||
MinecraftForge.EVENT_BUS.register(NEEKnowledgeInscriberHandler.instance);
|
||||
MinecraftForge.EVENT_BUS.register(NEECraftingPreviewHandler.instance);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,46 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.github.vfyjxf.nee.container.WCTContainerCraftingConfirm;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.GuiFluidPatternTerminalEx;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal;
|
||||
import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx;
|
||||
|
||||
import appeng.client.gui.implementations.GuiCraftConfirm;
|
||||
import appeng.client.gui.implementations.GuiCraftingTerm;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.gui.implementations.GuiPatternTerm;
|
||||
import appeng.client.gui.implementations.GuiPatternTermEx;
|
||||
import appeng.client.me.ItemRepo;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.container.implementations.ContainerPatternTermEx;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException;
|
||||
import thaumicenergistics.common.container.ContainerPartArcaneCraftingTerminal;
|
||||
|
||||
/**
|
||||
* @author vfyjxf
|
||||
*/
|
||||
public class GuiUtils {
|
||||
|
||||
private static final boolean isWirelessCraftingTerminalModLoaded = Loader.isModLoaded(ModIDs.WCT);
|
||||
private static final boolean isFluidCraftModloaded = Loader.isModLoaded(ModIDs.FC);
|
||||
|
||||
public static boolean isGuiWirelessCrafting(GuiScreen gui) {
|
||||
if (!isWirelessCraftingTerminalModLoaded) return false;
|
||||
return gui instanceof net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
|
||||
}
|
||||
|
||||
public static boolean isWirelessCraftingTermContainer(Container container) {
|
||||
if (!isWirelessCraftingTerminalModLoaded) return false;
|
||||
return container instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerWirelessCraftingTerminal;
|
||||
}
|
||||
|
||||
public static boolean isContainerWirelessCraftingConfirm(Container container) {
|
||||
if (!isWirelessCraftingTerminalModLoaded) return false;
|
||||
return container instanceof net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm;
|
||||
}
|
||||
|
||||
public static boolean isWirelessGuiCraftConfirm(GuiScreen gui) {
|
||||
if (!isWirelessCraftingTerminalModLoaded) return false;
|
||||
return gui instanceof net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm;
|
||||
}
|
||||
|
||||
public static boolean isWCTContainerCraftingConfirm(Container container) {
|
||||
return container instanceof WCTContainerCraftingConfirm;
|
||||
}
|
||||
|
||||
public static boolean isWirelessTerminalGuiObject(Object guiObj) {
|
||||
if (!isWirelessCraftingTerminalModLoaded) return false;
|
||||
return guiObj instanceof net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject;
|
||||
}
|
||||
|
||||
public static boolean isCraftingSlot(Slot slot) {
|
||||
if (slot == null) {
|
||||
return false;
|
||||
@@ -71,18 +54,14 @@ public class GuiUtils {
|
||||
return craftMatrix.equals(slot.inventory);
|
||||
}
|
||||
|
||||
public static boolean isPatternContainer(Container container) {
|
||||
if (isFluidCraftModloaded) {
|
||||
return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx
|
||||
|| container instanceof ContainerFluidPatternTerminal
|
||||
|| container instanceof ContainerFluidPatternTerminalEx;
|
||||
} else {
|
||||
return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx;
|
||||
}
|
||||
public static boolean isFluidCraftPatternContainer(Container container) {
|
||||
return isFluidCraftModloaded && (container instanceof ContainerFluidPatternTerminal
|
||||
|| container instanceof ContainerFluidPatternTerminalEx);
|
||||
}
|
||||
|
||||
public static boolean isGuiCraftingTerm(GuiScreen guiScreen) {
|
||||
return guiScreen instanceof GuiCraftingTerm || isGuiWirelessCrafting(guiScreen);
|
||||
public static boolean isPatternContainer(Container container) {
|
||||
return container instanceof ContainerPatternTerm || container instanceof ContainerPatternTermEx
|
||||
|| isFluidCraftPatternContainer(container);
|
||||
}
|
||||
|
||||
public static boolean isFluidCraftPatternTermEx(GuiScreen guiScreen) {
|
||||
@@ -90,21 +69,92 @@ public class GuiUtils {
|
||||
}
|
||||
|
||||
public static boolean isFluidCraftPatternTerm(GuiScreen guiScreen) {
|
||||
return isFluidCraftModloaded
|
||||
&& (guiScreen instanceof GuiFluidPatternTerminal || guiScreen instanceof GuiFluidPatternTerminalEx);
|
||||
return isFluidCraftModloaded && guiScreen instanceof GuiFluidPatternTerminal;
|
||||
}
|
||||
|
||||
public static boolean isPatternTerm(GuiScreen guiScreen) {
|
||||
if (isFluidCraftModloaded) {
|
||||
return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx
|
||||
|| guiScreen instanceof GuiFluidPatternTerminal
|
||||
|| guiScreen instanceof GuiFluidPatternTerminalEx;
|
||||
} else {
|
||||
return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx;
|
||||
}
|
||||
return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx
|
||||
|| isFluidCraftModloaded && (guiScreen instanceof GuiFluidPatternTerminal
|
||||
|| guiScreen instanceof GuiFluidPatternTerminalEx);
|
||||
}
|
||||
|
||||
public static boolean isGuiCraftConfirm(GuiScreen gui) {
|
||||
return gui instanceof GuiCraftConfirm || isWirelessGuiCraftConfirm(gui);
|
||||
public static ItemRepo getItemRepo(GuiContainer termGui) {
|
||||
Class<?> clazz = termGui.getClass();
|
||||
ItemRepo repo = null;
|
||||
|
||||
while (repo == null && clazz != null) {
|
||||
try {
|
||||
repo = (ItemRepo) ReflectionHelper.findField(clazz, "repo").get(termGui);
|
||||
} catch (UnableToFindFieldException | IllegalAccessException e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
}
|
||||
|
||||
return repo;
|
||||
}
|
||||
|
||||
public static List<IAEItemStack> getStorageStacks(GuiContainer termGui, Predicate<IAEItemStack> predicate) {
|
||||
final List<IAEItemStack> storageStacks = new ArrayList<>();
|
||||
|
||||
if (termGui != null) {
|
||||
final ItemRepo repo = GuiUtils.getItemRepo(termGui);
|
||||
|
||||
if (repo != null) {
|
||||
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
final IItemList<IAEItemStack> list = (IItemList<IAEItemStack>) ReflectionHelper
|
||||
.findField(ItemRepo.class, "list").get(repo);
|
||||
|
||||
for (IAEItemStack stack : list) {
|
||||
if (predicate.test(stack)) {
|
||||
storageStacks.add(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {}
|
||||
|
||||
try {
|
||||
final IAEItemStack[] pins = (IAEItemStack[]) ReflectionHelper.findField(ItemRepo.class, "pins")
|
||||
.get(repo);
|
||||
|
||||
for (int i = 0; i < pins.length; i++) {
|
||||
final IAEItemStack stack = pins[i];
|
||||
if (stack != null && predicate.test(stack)) {
|
||||
storageStacks.add(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return storageStacks;
|
||||
}
|
||||
|
||||
public static IGrid getGrid(Container container) {
|
||||
|
||||
if (Loader.isModLoaded(ModIDs.ThE) && container instanceof ContainerPartArcaneCraftingTerminal act) {
|
||||
final IGridNode gridNode = act.terminal.getGridNode(ForgeDirection.UNKNOWN);
|
||||
|
||||
if (gridNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return gridNode.getGrid();
|
||||
} else if (container instanceof AEBaseContainer baseContainer
|
||||
&& baseContainer.getTarget() instanceof IGridHost gridHost) {
|
||||
final IGridNode gridNode = gridHost.getGridNode(ForgeDirection.UNKNOWN);
|
||||
|
||||
if (gridNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return gridNode.getGrid();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.github.vfyjxf.nee.utils;
|
||||
|
||||
import static com.github.vfyjxf.nee.nei.NEECraftingHelper.noPreview;
|
||||
import static com.github.vfyjxf.nee.utils.GuiUtils.isFluidCraftPatternTerm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,22 +7,12 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiWirelessCraftingTerminal;
|
||||
|
||||
import com.github.vfyjxf.nee.config.NEEConfig;
|
||||
import com.github.vfyjxf.nee.network.NEENetworkHandler;
|
||||
import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest;
|
||||
import com.glodblock.github.client.gui.base.FCGuiMonitor;
|
||||
|
||||
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 cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class IngredientTracker {
|
||||
|
||||
@@ -35,20 +22,16 @@ public class IngredientTracker {
|
||||
private final int recipeIndex;
|
||||
private int currentIndex = 0;
|
||||
|
||||
/**
|
||||
* For {@link com.github.vfyjxf.nee.nei.NEECraftingHelper}
|
||||
*/
|
||||
public IngredientTracker(GuiContainer termGui, IRecipeHandler recipe, int recipeIndex) {
|
||||
this.termGui = termGui;
|
||||
this.recipeIndex = recipeIndex;
|
||||
|
||||
for (PositionedStack requiredIngredient : recipe.getIngredientStacks(recipeIndex)) {
|
||||
Ingredient ingredient = new Ingredient(requiredIngredient);
|
||||
ingredients.add(ingredient);
|
||||
this.ingredients.add(new Ingredient(requiredIngredient));
|
||||
}
|
||||
|
||||
for (Ingredient ingredient : this.ingredients) {
|
||||
for (IAEItemStack stack : getCraftableStacks()) {
|
||||
for (IAEItemStack stack : GuiUtils.getStorageStacks(this.termGui, IAEItemStack::isCraftable)) {
|
||||
if (ingredient.getIngredient().contains(stack.getItemStack())) {
|
||||
ingredient.setCraftableIngredient(stack.getItemStack());
|
||||
}
|
||||
@@ -58,94 +41,8 @@ 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;
|
||||
getCraftableStacks();
|
||||
|
||||
for (PositionedStack requiredIngredient : recipe.getIngredientStacks(recipeIndex)) {
|
||||
Ingredient ingredient = new Ingredient(requiredIngredient);
|
||||
ingredients.add(ingredient);
|
||||
}
|
||||
|
||||
for (Ingredient ingredient : this.ingredients) {
|
||||
for (IAEItemStack stack : getCraftableStacks()) {
|
||||
if (ingredient.getIngredient().contains(stack.getItemStack())) {
|
||||
ingredient.setCraftableIngredient(stack.getItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemRepo getRepo() throws IllegalAccessException {
|
||||
if (isFluidCraftPatternTerm(termGui)) {
|
||||
return (ItemRepo) ReflectionHelper.findField(FCGuiMonitor.class, "repo").get(termGui);
|
||||
} else {
|
||||
return (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(termGui);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<IAEItemStack> getCraftableStacks() {
|
||||
List<IAEItemStack> craftableStacks = new ArrayList<>();
|
||||
if (termGui != null) {
|
||||
IItemList<IAEItemStack> list = null;
|
||||
try {
|
||||
if (!GuiUtils.isGuiWirelessCrafting(termGui)) {
|
||||
ItemRepo repo = getRepo();
|
||||
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo);
|
||||
} else {
|
||||
// wireless crafting terminal support
|
||||
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo")
|
||||
.get(termGui);
|
||||
list = (IItemList<IAEItemStack>) ReflectionHelper.findField(ItemRepo.class, "list").get(repo);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (list != null) {
|
||||
for (IAEItemStack stack : list) {
|
||||
if (stack.isCraftable()) {
|
||||
craftableStacks.add(stack.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return craftableStacks;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<IAEItemStack> getStorageStacks() {
|
||||
List<IAEItemStack> list = new ArrayList<>();
|
||||
if (termGui != null) {
|
||||
try {
|
||||
if (!GuiUtils.isGuiWirelessCrafting(termGui)) {
|
||||
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiMEMonitorable.class, "repo").get(termGui);
|
||||
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper
|
||||
.findField(ItemRepo.class, "list").get(repo)) {
|
||||
list.add(stack.copy());
|
||||
}
|
||||
} else {
|
||||
// wireless crafting terminal support
|
||||
ItemRepo repo = (ItemRepo) ReflectionHelper.findField(GuiWirelessCraftingTerminal.class, "repo")
|
||||
.get(termGui);
|
||||
for (IAEItemStack stack : (IItemList<IAEItemStack>) ReflectionHelper
|
||||
.findField(ItemRepo.class, "list").get(repo)) {
|
||||
list.add(stack.copy());
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Ingredient> getIngredients() {
|
||||
return ingredients;
|
||||
return this.ingredients;
|
||||
}
|
||||
|
||||
public List<ItemStack> getRequireToCraftStacks() {
|
||||
@@ -173,27 +70,23 @@ public class IngredientTracker {
|
||||
}
|
||||
|
||||
public List<ItemStack> getRequireStacks() {
|
||||
return requireStacks;
|
||||
return this.requireStacks;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return currentIndex < getRequireStacks().size();
|
||||
return this.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 getNextIngredient() {
|
||||
return getRequiredStack(this.currentIndex++);
|
||||
}
|
||||
|
||||
public ItemStack getRequiredStack(int index) {
|
||||
return this.getRequireStacks().get(index);
|
||||
return getRequireStacks().get(index);
|
||||
}
|
||||
|
||||
public int getRecipeIndex() {
|
||||
return recipeIndex;
|
||||
return this.recipeIndex;
|
||||
}
|
||||
|
||||
public void addAvailableStack(ItemStack stack) {
|
||||
@@ -229,29 +122,28 @@ public class IngredientTracker {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void calculateIngredients() {
|
||||
final List<IAEItemStack> stacks = GuiUtils
|
||||
.getStorageStacks(this.termGui, stack -> NEEConfig.matchOtherItems || stack.isCraftable());
|
||||
|
||||
List<IAEItemStack> stacks = NEEConfig.matchOtherItems ? getStorageStacks() : getCraftableStacks();
|
||||
for (Ingredient ingredient : this.ingredients) {
|
||||
ingredient.setCurrentCount(0);
|
||||
for (IAEItemStack stack : stacks) {
|
||||
if (ingredient.getIngredient().contains(stack.getItemStack())) {
|
||||
if (stack.getStackSize() > 0) {
|
||||
ingredient.addCount(stack.getStackSize());
|
||||
if (ingredient.requiresToCraft()) {
|
||||
stack.setStackSize(0);
|
||||
} else {
|
||||
stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount());
|
||||
}
|
||||
if (stack.getStackSize() > 0 && ingredient.getIngredient().contains(stack.getItemStack())) {
|
||||
ingredient.addCount(stack.getStackSize());
|
||||
if (ingredient.requiresToCraft()) {
|
||||
stack.setStackSize(0);
|
||||
} else {
|
||||
stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> inventoryStacks = new ArrayList<>();
|
||||
final List<ItemStack> inventoryStacks = new ArrayList<>();
|
||||
|
||||
for (Slot slot : (List<Slot>) termGui.inventorySlots.inventorySlots) {
|
||||
boolean canGetStack = slot != null && slot.getHasStack()
|
||||
final boolean canGetStack = slot != null && slot.getHasStack()
|
||||
&& slot.getStack().stackSize > 0
|
||||
&& slot.isItemValid(slot.getStack())
|
||||
&& slot.canTakeStack(Minecraft.getMinecraft().thePlayer);
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.github.vfyjxf.nee.processor.RecipeProcessor;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
@@ -183,14 +183,11 @@ 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;
|
||||
public static int getPermutationIndex(ItemStack stack, List<ItemStack> items) {
|
||||
|
||||
for (int index = 0; index < items.size(); index++) {
|
||||
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(items.get(index), stack)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@@ -212,9 +209,9 @@ public final class ItemUtils {
|
||||
+ "}";
|
||||
}
|
||||
|
||||
public static NBTTagCompound writeItemStackToNBT(ItemStack itemStack, NBTTagCompound tag) {
|
||||
itemStack.writeToNBT(tag);
|
||||
tag.setInteger("Count", itemStack.stackSize);
|
||||
public static NBTTagCompound writeItemStackToNBT(ItemStack itemStack, int stackSize) {
|
||||
NBTTagCompound tag = itemStack.writeToNBT(new NBTTagCompound());
|
||||
tag.setInteger("Count", stackSize);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ public class ModIDs {
|
||||
|
||||
public static final String WCT = "ae2wct";
|
||||
public static final String FC = "ae2fc";
|
||||
public static final String ThE = "thaumicenergistics";
|
||||
}
|
||||
Reference in new issue
Block a user