ME, FC, WC Terminals

This commit is contained in:
slprime committed 2024-09-07 20:24:54 +03:00
1 parent 342d1822f7
commit 79552ef17f
41 files changed
+1368 -3827

No files matched your search

+1 -7
View File
@@ -1,18 +1,12 @@
dependencies {
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-435-GTNH:dev")
api("com.github.GTNewHorizons:NotEnoughItems:2.6.26-GTNH:dev")
api("com.github.GTNewHorizons:NotEnoughItems:2.6.34-GTNH:dev")
implementation("com.github.GTNewHorizons:Baubles:1.0.4:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.11.6:dev")
compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.3.26-gtnh:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.7.1-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.17:dev") { transitive = false }
compileOnly('com.github.GTNewHorizons:EnderIO:2.8.17:dev') { transitive=false }
compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.7:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.49.55:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ThaumicEnergistics:1.6.22-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.3.26-gtnh:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.7.1-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.17:dev") { transitive = false }
@@ -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;
@@ -58,22 +62,24 @@ 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();
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 +89,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 +107,44 @@ 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);
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);
}
}
@Override
public String getName() {
return NotEnoughEnergistics.NAME;
@@ -150,14 +195,31 @@ 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");
}
}
@@ -167,14 +229,18 @@ public class NEINeeConfig implements IConfigureNEI {
} catch (ClassNotFoundException e) {
return;
}
if (Loader.isModLoaded("thaumcraftneiplugin")) {
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(),
NEEKnowledgeInscriberHandler.instance,
"arcaneshapedrecipes");
API.registerGuiOverlayHandler(
GuiKnowledgeInscriber.class,
NEEKnowledgeInscriberHandler.instance,
"arcaneshapelessrecipes");
}
}
@@ -185,7 +251,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 +261,14 @@ 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.registerGuiOverlayHandler(
GuiExtremeAutoCrafter.class,
NEEExtremeAutoCrafterHandler.instance,
"extreme");
}
}
}
@@ -8,7 +8,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.network.NEEGuiHandler;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.proxy.CommonProxy;
@@ -19,7 +18,6 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
@Mod(
modid = NotEnoughEnergistics.MODID,
@@ -59,7 +57,5 @@ public class NotEnoughEnergistics {
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(this, new NEEGuiHandler());
}
public void postInit(FMLPostInitializationEvent event) {}
}
@@ -1,52 +0,0 @@
package com.github.vfyjxf.nee.block;
import java.util.EnumSet;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import com.github.vfyjxf.nee.network.NEEGuiHandler;
import appeng.block.AEBaseItemBlock;
import appeng.block.AEBaseTileBlock;
import appeng.core.features.AEFeature;
/**
* @author vfyjxf
*/
public class BlockPatternInterface extends AEBaseTileBlock {
public static BlockPatternInterface BLOCK_INSTANCE = new BlockPatternInterface();
public static Item ITEM_INSTANCE = new AEBaseItemBlock(BLOCK_INSTANCE);
public BlockPatternInterface() {
super(Material.iron);
this.setTileEntity(TilePatternInterface.class);
this.setFeature(EnumSet.of(AEFeature.Core));
this.setBlockName(NotEnoughEnergistics.MODID + "." + "pattern_interface");
this.setBlockTextureName(NotEnoughEnergistics.MODID + ":" + "pattern_interface");
}
@Override
public boolean onActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY,
float hitZ) {
if (player.isSneaking()) {
return false;
}
TilePatternInterface tile = this.getTileEntity(world, x, y, z);
if (tile != null) {
if (!world.isRemote) {
NEEGuiHandler.openGui(player, NEEGuiHandler.PATTERN_INTERFACE_ID, tile, ForgeDirection.UNKNOWN);
}
return true;
}
return false;
}
}
@@ -1,720 +0,0 @@
package com.github.vfyjxf.nee.block.tile;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.IntStream;
import javax.annotation.Nonnull;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.google.common.collect.ImmutableSet;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.implementations.tiles.ICraftingMachine;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
import appeng.core.settings.TickRates;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.me.GridAccessException;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.WrapperInvSlot;
import cpw.mods.fml.relauncher.ReflectionHelper;
/**
* A ME interface for storing temporary patterns.
*/
public class TilePatternInterface extends AENetworkInvTile
implements IGridTickable, ICraftingProvider, IInventoryDestination {
private final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
private final AppEngInternalInventory gridInv;
private final AppEngInternalInventory patterns;
private final AppEngInternalInventory ejectInv;
private List<ICraftingPatternDetails> craftingList;
private List<ItemStack> waitingToSend;
private final MachineSource source;
private final WrapperInvSlot slotInv;
private final boolean[] workStarted = new boolean[9];
public TilePatternInterface() {
this.gridInv = new AppEngInternalInventory(this, 9 + 1);
this.gridInv.setMaxStackSize(1);
this.patterns = new AppEngInternalInventory(this, 9);
this.ejectInv = new AppEngInternalInventory(this, 9);
this.craftingList = new ArrayList<>();
this.source = new MachineSource(this);
this.slotInv = new WrapperInvSlot(this.ejectInv);
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.getProxy().setIdlePowerUsage(30D);
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
this.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
this.notifyNeighbors();
}
private void notifyNeighbors() {
if (this.getProxy().isActive()) {
try {
this.getProxy().getGrid()
.postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (GridAccessException e) {
// :P
}
Platform.notifyBlocksOfNeighbors(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord);
}
}
@Nonnull
@Override
public TickingRequest getTickingRequest(@Nonnull IGridNode node) {
return new TickingRequest(TickRates.Interface.getMin(), TickRates.Interface.getMax(), !hasItemToSend(), true);
}
@Nonnull
@Override
public TickRateModulation tickingRequest(@Nonnull IGridNode node, int ticksSinceLastCall) {
if (!this.getProxy().isActive()) {
return TickRateModulation.SLEEP;
}
if (hasItemToSend()) {
ejectItems();
}
if (this.hasItemsToPush()) {
this.pushItemsOut(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN)));
}
if (hasWorkFinished()) {
updateWorks();
}
if (hasWorks()) {
return TickRateModulation.URGENT;
}
return TickRateModulation.SLEEP;
}
@Nonnull
@Override
public IInventory getInternalInventory() {
return this.ejectInv;
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) {
if (inv == this.ejectInv || inv == patterns) {
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException e) {
// :P
}
}
}
@Override
public void onReady() {
super.onReady();
this.updateCraftingList();
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
return this.sides;
}
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker) {
if (this.getProxy().isActive()) {
if (this.craftingList.isEmpty()) {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails pattern = ((ICraftingPatternItem) stack.getItem())
.getPatternForItem(stack, worldObj);
if (pattern != null && pattern.isCraftable()) {
craftingList.add(pattern);
}
}
}
}
for (ICraftingPatternDetails details : this.craftingList) {
craftingTracker.addCraftingOption(this, details);
}
}
}
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
if (!isBusy() && this.getProxy().isActive()
&& craftingList.contains(patternDetails)
&& !this.hasItemsToPush()) {
final EnumSet<ForgeDirection> possibleDirections = EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN));
for (final ForgeDirection direction : possibleDirections) {
final TileEntity te = worldObj.getTileEntity(
xCoord + direction.offsetX,
yCoord + direction.offsetY,
zCoord + direction.offsetZ);
if (te instanceof IInterfaceHost) {
try {
if (this.sameGrid(getGridFromInterface(((IInterfaceHost) te).getInterfaceDuality()))) {
continue;
}
} catch (final GridAccessException e) {
continue;
}
}
if (te instanceof ICraftingMachine) {
final ICraftingMachine cm = (ICraftingMachine) te;
if (cm.acceptsPlans()) {
if (cm.pushPattern(patternDetails, table, direction.getOpposite())) {
setWorkStart(patternDetails);
return true;
}
continue;
}
}
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor(te, direction.getOpposite());
if (ad != null) {
if (this.acceptsItems(ad, table)) {
for (int x = 0; x < table.getSizeInventory(); x++) {
final ItemStack is = table.getStackInSlot(x);
if (is != null) {
final ItemStack added = ad.addItems(is);
this.addToSendList(added);
}
}
this.pushItemsOut(possibleDirections);
setWorkStart(patternDetails);
return true;
}
}
}
}
return false;
}
@Override
public boolean isBusy() {
return hasItemsToPush();
}
@Override
public void getDrops(final World w, final int x, final int y, final int z, final List<ItemStack> drops) {
if (hasItemsToPush()) {
for (ItemStack stack : waitingToSend) {
if (stack != null) {
drops.add(stack);
}
}
}
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
ItemStack stack = ejectInv.getStackInSlot(i);
if (stack != null) {
drops.add(stack);
}
}
}
public AppEngInternalInventory getGirdInventory() {
return gridInv;
}
public AppEngInternalInventory getPatternInventory() {
return patterns;
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir) {
return AECableType.SMART;
}
@Override
public boolean canInsert(ItemStack stack) {
if (stack == null || stack.getItem() == null) {
return false;
}
try {
final IAEItemStack out = this.getProxy().getStorage().getItemInventory()
.injectItems(AEApi.instance().storage().createItemStack(stack), Actionable.SIMULATE, this.source);
if (out == null) {
return true;
}
return out.getStackSize() != stack.stackSize;
} catch (GridAccessException e) {
return false;
}
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public NBTTagCompound writeToNBT_TilePatternInterface(NBTTagCompound data) {
this.patterns.writeToNBT(data, "patterns");
this.ejectInv.writeToNBT(data, "ejectInv");
final NBTTagList waitingToSend = new NBTTagList();
if (this.waitingToSend != null) {
for (final ItemStack is : this.waitingToSend) {
final NBTTagCompound item = new NBTTagCompound();
is.writeToNBT(item);
waitingToSend.appendTag(item);
}
}
data.setTag("waitingToSend", waitingToSend);
return data;
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBT_TilePatternInterface(NBTTagCompound data) {
this.waitingToSend = null;
final NBTTagList waitingList = data.getTagList("waitingToSend", 10);
if (waitingList != null) {
for (int x = 0; x < waitingList.tagCount(); x++) {
final NBTTagCompound c = waitingList.getCompoundTagAt(x);
if (c != null) {
final ItemStack is = ItemStack.loadItemStackFromNBT(c);
this.addToSendList(is);
}
}
}
this.patterns.readFromNBT(data, "patterns");
this.ejectInv.readFromNBT(data, "ejectInv");
this.updateCraftingList();
}
private boolean hasItemsToPush() {
return this.waitingToSend != null && !this.waitingToSend.isEmpty();
}
public boolean canPutPattern(ItemStack result) {
if (result == null) {
return false;
}
for (int i = 0; i < this.patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails pattern = ((ICraftingPatternItem) stack.getItem())
.getPatternForItem(stack, worldObj);
if (result.isItemEqual(pattern.getOutputs()[0].getItemStack())) {
return false;
}
}
}
return IntStream.range(0, this.patterns.getSizeInventory())
.anyMatch(slot -> patterns.getStackInSlot(slot) == null);
}
public int putPattern(ItemStack pattern) {
for (int i = 0; i < this.patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack == null) {
patterns.setInventorySlotContents(i, pattern);
updateCraftingList();
return i;
}
}
return -1;
}
public void updateCraftingList() {
final Boolean[] accountedFor = { false, false, false, false, false, false, false, false, false };
assert (accountedFor.length == this.patterns.getSizeInventory());
if (!this.getProxy().isReady()) {
return;
}
if (this.craftingList != null) {
final Iterator<ICraftingPatternDetails> i = this.craftingList.iterator();
while (i.hasNext()) {
final ICraftingPatternDetails details = i.next();
boolean found = false;
for (int x = 0; x < accountedFor.length; x++) {
final ItemStack is = this.patterns.getStackInSlot(x);
if (details.getPattern() == is) {
accountedFor[x] = found = true;
}
}
if (!found) {
i.remove();
}
}
}
for (int x = 0; x < accountedFor.length; x++) {
if (!accountedFor[x]) {
this.addToCraftingList(this.patterns.getStackInSlot(x));
}
}
try {
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
} catch (final GridAccessException e) {
// :P
}
}
public void cancelWork(int recipeIndex) {
IAEItemStack result = getResultStack(recipeIndex);
if (result != null) {
workStarted[recipeIndex] = false;
try {
final ICraftingGrid cg = this.getProxy().getCrafting();
final ImmutableSet<ICraftingCPU> cpuSet = cg.getCpus();
for (ICraftingCPU cpu : cpuSet) {
if (cpu instanceof CraftingCPUCluster) {
CraftingCPUCluster cluster = (CraftingCPUCluster) cpu;
final IItemList<IAEItemStack> pendingList = AEApi.instance().storage().createItemList();
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
for (IAEItemStack pendingStack : pendingList) {
if (pendingStack.isSameType(result)) {
cluster.cancel();
break;
}
}
}
}
} catch (GridAccessException e) {
e.printStackTrace();
}
}
}
private void addToCraftingList(final ItemStack is) {
if (is == null) {
return;
}
if (is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = cpi.getPatternForItem(is, worldObj);
if (details != null) {
if (this.craftingList == null) {
this.craftingList = new LinkedList<>();
}
this.craftingList.add(details);
}
}
}
private void addToSendList(final ItemStack is) {
if (is == null) {
return;
}
if (this.waitingToSend == null) {
this.waitingToSend = new LinkedList<>();
}
this.waitingToSend.add(is);
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
private boolean acceptsItems(final InventoryAdaptor ad, final InventoryCrafting table) {
for (int x = 0; x < table.getSizeInventory(); x++) {
final ItemStack is = table.getStackInSlot(x);
if (is == null) {
continue;
}
if (ad.simulateAdd(is.copy()) != null) {
return false;
}
}
return true;
}
private void pushItemsOut(final EnumSet<ForgeDirection> possibleDirections) {
if (!this.hasItemsToPush()) {
return;
}
final Iterator<ItemStack> i = this.waitingToSend.iterator();
while (i.hasNext()) {
ItemStack whatToSend = i.next();
for (final ForgeDirection s : possibleDirections) {
final TileEntity te = worldObj
.getTileEntity(this.xCoord + s.offsetX, this.yCoord + s.offsetY, this.zCoord + s.offsetZ);
if (te == null) {
continue;
}
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor(te, s.getOpposite());
if (ad != null) {
final ItemStack Result = ad.addItems(whatToSend);
if (Result == null) {
whatToSend = null;
} else {
whatToSend.stackSize -= whatToSend.stackSize - Result.stackSize;
}
if (whatToSend == null) {
break;
}
}
}
if (whatToSend == null) {
i.remove();
}
}
if (this.waitingToSend.isEmpty()) {
this.waitingToSend = null;
}
}
private boolean hasItemToSend() {
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
ItemStack stack = ejectInv.getStackInSlot(i);
if (stack != null) {
return true;
}
}
return false;
}
private void ejectItems() {
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
if (ejectInv.getStackInSlot(i) != null) {
ItemStack stack = ejectInv.getStackInSlot(i);
int itemCount = stack.stackSize;
final InventoryAdaptor adaptor = getAdaptor(i);
final ItemStack canExtract = adaptor.simulateRemove(itemCount, stack, null);
if (canExtract != null && canExtract.stackSize == itemCount) {
try {
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getItemInventory();
final IEnergyGrid energy = this.getProxy().getEnergy();
final IAEItemStack aeStack = AEApi.instance().storage().createItemStack(stack);
if (aeStack != null) {
final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source);
if (failed != null) {
itemCount -= failed.getStackSize();
}
if (itemCount != 0) {
final ItemStack removed = adaptor.removeItems(itemCount, null, null);
if (removed == null) {
throw new IllegalStateException(
"bad attempt at managing inventory. ( removeItems )");
} else if (removed.stackSize != itemCount) {
throw new IllegalStateException(
"bad attempt at managing inventory. ( removeItems )");
}
}
}
} catch (GridAccessException e) {
// :P
}
}
}
}
}
private InventoryAdaptor getAdaptor(final int slot) {
return new AdaptorIInventory(this.slotInv.getWrapper(slot));
}
private boolean hasWorks() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) != null) {
return true;
}
}
return false;
}
private void setWorkStart(ICraftingPatternDetails pattern) {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem())
.getPatternForItem(stack, worldObj);
if (currentPattern != null && currentPattern.equals(pattern)) {
workStarted[i] = true;
}
}
}
}
private boolean hasWorkFinished() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem())
.getPatternForItem(stack, worldObj);
if (currentPattern != null) {
IAEItemStack what = currentPattern.getOutputs().length > 0 ? currentPattern.getOutputs()[0] : null;
if (isNotRequesting(what) && workStarted[i]) {
return true;
}
}
}
}
return false;
}
private void updateWorks() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
IAEItemStack what = getResultStack(i);
if (isNotRequesting(what) && workStarted[i]) {
patterns.setInventorySlotContents(i, null);
workStarted[i] = false;
updateCraftingList();
}
}
}
private boolean isNotRequesting(IAEItemStack stack) {
if (stack == null) {
return true;
}
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;
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
}
}
for (IAEItemStack pendingStack : pendingList) {
if (pendingStack.isSameType(stack)) {
return false;
}
}
} catch (GridAccessException e) {
e.printStackTrace();
}
return true;
}
private IAEItemStack getResultStack(int pattern) {
ItemStack stack = patterns.getStackInSlot(pattern);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem())
.getPatternForItem(stack, worldObj);
if (currentPattern != null) {
return currentPattern.getOutputs().length > 0 ? currentPattern.getOutputs()[0] : null;
}
}
return null;
}
@Override
public void gridChanged() {
this.notifyNeighbors();
}
private boolean sameGrid(final IGrid grid) throws GridAccessException {
return grid == this.getProxy().getGrid();
}
private IGrid getGridFromInterface(DualityInterface iface) {
return ReflectionHelper.getPrivateValue(DualityInterface.class, iface, "gridProxy");
}
}
@@ -2,22 +2,22 @@ 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.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.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import org.lwjgl.input.Keyboard;
@@ -26,20 +26,20 @@ 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.utils.GuiUtils;
import com.github.vfyjxf.nee.utils.ItemUtils;
import com.github.vfyjxf.nee.utils.ModIDs;
import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal;
import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal;
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.nei.NEIClientConfig;
@@ -47,103 +47,111 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import codechicken.nei.recipe.RecipeInfo;
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 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 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;
}
}
@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) {
final GuiContainer guiContainer = (GuiContainer) guiScreen;
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 = Mouse.getEventButton() != 2 ? this.buttonCombination.getCurrentValue().ordinal() + 1
: this.buttonCombination.getCurrentValue().ordinal() - 1;
if (ordinal >= ItemCombination.values().length) {
ordinal = 0;
@@ -151,23 +159,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();
}
return false;
}
@Override
@@ -192,51 +198,49 @@ public class GuiEventHandler implements INEIGuiHandler {
return false;
}
if (NEEConfig.enableNEIDragDrop) {
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 && draggedStack != null && gui instanceof AEBaseGui) {
Slot currentSlot = gui.getSlotAtPosition(mouseX, mouseY);
if (sendPacket) {
NEENetworkHandler.getInstance().sendToServer(
new PacketSlotStackChange(
copyStack,
Collections.singletonList(currentSlot.slotNumber)));
if (!NEEConfig.keepGhostitems) {
draggedStack.stackSize = 0;
}
return true;
}
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 = areStackEqual(slotStack, copyStack) ? slotStack.stackSize + copySize
: copySize;
sendPacket = true;
} else if (button == 1) {
if (areStackEqual(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;
}
}
if (button == 2) {
draggedStack.stackSize = 0;
}
}
return false;
}
private boolean areStackEqual(ItemStack stackA, ItemStack stackB) {
return stackA != null && stackA.isItemEqual(stackB) && ItemStack.areItemStackTagsEqual(stackA, stackB);
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
return false;
@@ -252,7 +256,7 @@ public class GuiEventHandler implements INEIGuiHandler {
boolean isPatternTerm = isPatternTerm(mc.currentScreen);
boolean isInterface = event.guiScreen instanceof GuiInterface;
if (isPatternTerm || isInterface) {
Slot currentSlot = (event.guiScreen).getSlotAtPosition(event.mouseX, event.mouseY);
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"))
@@ -272,12 +276,13 @@ public class GuiEventHandler implements INEIGuiHandler {
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);
PositionedStack currentIngredients = NEEPatternTerminalHandler.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) {
@@ -290,7 +295,7 @@ public class GuiEventHandler implements INEIGuiHandler {
if (NEEConfig.allowSynchronousSwitchIngredient) {
for (Slot slot : getCraftingSlots(gui)) {
PositionedStack slotIngredients = NEECraftingHandler.ingredients
PositionedStack slotIngredients = NEEPatternTerminalHandler.ingredients
.get(INPUT_KEY + slot.getSlotIndex());
boolean areItemStackEqual = currentSlot.getHasStack() && slot.getHasStack()
@@ -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,71 +0,0 @@
package com.github.vfyjxf.nee.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import com.github.vfyjxf.nee.client.gui.widgets.GuiImgButtonRemove;
import com.github.vfyjxf.nee.container.ContainerPatternInterface;
import com.github.vfyjxf.nee.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;
import appeng.client.gui.AEBaseGui;
import appeng.container.slot.SlotRestrictedInput;
public class GuiPatternInterface extends AEBaseGui {
private final ContainerPatternInterface container;
private GuiImgButtonRemove removeButton;
public GuiPatternInterface(InventoryPlayer playerInventory, TilePatternInterface tile) {
super(new ContainerPatternInterface(playerInventory, tile));
this.xSize = 211;
this.ySize = 197;
this.container = (ContainerPatternInterface) this.inventorySlots;
}
@SuppressWarnings("unchecked")
@Override
public void initGui() {
super.initGui();
this.removeButton = new GuiImgButtonRemove(this.guiLeft + 85, this.guiTop + this.ySize - 173);
this.buttonList.add(removeButton);
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
this.mc.getTextureManager().bindTexture(getBackground());
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, 211 - 34, this.ySize);
}
@Override
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
if (button == this.removeButton) {
// We shouldn't delete a null, right?
if (container.getSelectedSlot() != null) {
NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("Gui.PatternInterface"));
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int btn) {
if (btn == 0 && this.theSlot instanceof SlotRestrictedInput) {
SlotRestrictedInput slot = (SlotRestrictedInput) this.theSlot;
NEENetworkHandler.getInstance().sendToServer(
new PacketValueConfigServer("Container.selectedSlot", Integer.toString(slot.slotNumber)));
container.setSelectedSlotIndex(slot.slotNumber);
}
super.mouseClicked(mouseX, mouseY, btn);
}
private ResourceLocation getBackground() {
return new ResourceLocation(NotEnoughEnergistics.MODID, "textures/gui/pattern_interface.png");
}
}
@@ -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;
}
}
@@ -1,163 +0,0 @@
package com.github.vfyjxf.nee.container;
import static appeng.container.slot.SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import appeng.api.implementations.ICraftingPatternItem;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerNull;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotDisabled;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
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];
private final AppEngSlot[] recipeSlots = new AppEngSlot[10];
@GuiSync(0)
private int selectedSlotIndex = -1;
public ContainerPatternInterface(InventoryPlayer playerInventory, TilePatternInterface tile) {
super(playerInventory, tile);
this.playerInventory = playerInventory;
this.recipeInv = tile.getGirdInventory();
this.patterns = tile.getPatternInventory();
for (int i = 0; i < patterns.getSizeInventory(); i++) {
addSlotToContainer(
patternSlots[i] = new SlotRestrictedInput(
ENCODED_PATTERN,
patterns,
i,
8 + 18 * i,
90 + 5,
playerInventory) {
@Override
public boolean isItemValid(ItemStack i) {
return false;
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
return false;
}
});
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) {
this.addSlotToContainer(
recipeSlots[x + y * 3] = new SlotDisabled(recipeInv, x + y * 3, 29 + x * 18, 30 + y * 18));
}
}
this.addSlotToContainer(recipeSlots[9] = new SlotDisabled(recipeInv, 9, 126, 48));
this.bindPlayerInventory(playerInventory, 0, 184 - 69);
}
@Override
public void onContainerClosed(EntityPlayer playerIn) {
super.onContainerClosed(playerIn);
clearRecipe();
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return isValidContainer();
}
public Slot getSelectedSlot() {
return selectedSlotIndex >= 0 && selectedSlotIndex <= 9 ? patternSlots[selectedSlotIndex] : null;
}
public AppEngInternalInventory getRecipeInventory() {
return recipeInv;
}
public int getSelectedSlotIndex() {
return selectedSlotIndex;
}
public void setSelectedSlotIndex(int index) {
this.selectedSlotIndex = index;
if (Platform.isServer()) {
Slot slot = this.getSelectedSlot();
if (slot instanceof SlotRestrictedInput) {
if (slot.getHasStack()) {
ItemStack maybePattern = slot.getStack();
if (maybePattern.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails details = ((ICraftingPatternItem) maybePattern.getItem())
.getPatternForItem(maybePattern, getTileEntity().getWorldObj());
if ((details.getInputs().length == 9) && (details.getOutputs().length > 0)) {
InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
for (int i = 0; i < details.getInputs().length; i++) {
IAEItemStack stack = details.getInputs()[i];
Slot currentSlot = getSlotFromInventory(this.getRecipeInventory(), i);
if (currentSlot != null) {
if (stack != null) {
ItemStack is = stack.getItemStack();
currentSlot.putStack(is);
ic.setInventorySlotContents(i, is);
} else {
currentSlot.putStack(null);
}
}
}
Slot outSlot = getSlotFromInventory(this.getRecipeInventory(), 9);
if (outSlot != null) {
outSlot.putStack(details.getOutput(ic, getTileEntity().getWorldObj()));
}
}
}
}
}
}
this.detectAndSendChanges();
}
public void removeCurrentRecipe() {
Slot patternSlot = this.getSelectedSlot();
if (patternSlot != null && patternSlot.getHasStack()) {
patternSlot.putStack(null);
clearRecipe();
}
this.detectAndSendChanges();
}
private void clearRecipe() {
for (Slot slot : this.recipeSlots) {
slot.putStack(null);
}
}
@Override
public void saveChanges() {}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack,
ItemStack newStack) {}
}
@@ -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,250 @@
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.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import org.lwjgl.input.Keyboard;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.nei.NEEGuiOverlayButton.NEEItemOverlayState;
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.ModIDs;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.container.implementations.ContainerCraftConfirm;
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.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.GuiOverlayButton;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
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 NEECraftingTerminalHandler implements IOverlayHandler {
public static final NEECraftingTerminalHandler instance = new NEECraftingTerminalHandler();
public static final int RECIPE_LENGTH = 9;
private IngredientTracker tracker = null;
private boolean noPreview = false;
private NEECraftingTerminalHandler() {}
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
this.noPreview = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"));
boolean doCraftingHelp = this.noPreview || Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview"));
this.tracker = null;
if (!doCraftingHelp) {
moveItems(firstGui, recipe, recipeIndex);
} else {
this.tracker = new IngredientTracker(firstGui, recipe, recipeIndex);
if (!this.tracker.getRequireStacks().isEmpty()) {
this.tracker.requestNextIngredient(this.noPreview);
} else {
moveItems(firstGui, recipe, recipeIndex);
}
}
}
/**
* 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;
}
@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 (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) {// todo change
if (gui instanceof GuiCraftingTerm || 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(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe && isGuiCraftingTerm((GuiRecipe<?>) event.gui)) {
for (int i = 0; i < event.buttonList.size(); i++) {
event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i)));
}
}
}
@SubscribeEvent
public void onGuiCraftConfirmOpen(GuiOpenEvent event) {
final GuiScreen old = Minecraft.getMinecraft().currentScreen;
if (old != null && this.tracker != null
&& old instanceof GuiCraftConfirm
&& isContainerCraftConfirm(((GuiContainer) old).inventorySlots)) {
if (this.tracker.hasNext()) {
this.tracker.requestNextIngredient(this.noPreview);
} else {
this.tracker = null;
}
}
}
@SubscribeEvent
public void onCraftConfirmActionPerformed(GuiScreenEvent.ActionPerformedEvent.Post event) {
if (this.tracker != null && event.gui instanceof GuiCraftConfirm
&& getCancelButton((GuiCraftConfirm) event.gui) == event.button) {
this.tracker = null;
}
}
private boolean isContainerCraftConfirm(Container container) {
return container instanceof ContainerCraftConfirm;
}
private GuiButton getCancelButton(GuiCraftConfirm gui) {
return ReflectionHelper.getPrivateValue(GuiCraftConfirm.class, gui, "cancel");
}
private boolean isGuiCraftingTerm(GuiRecipe<?> gui) {
return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
}
}
@@ -0,0 +1,99 @@
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.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.IRecipeHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
/**
* @author vfyjxf
*/
public class NEEExtremeAutoCrafterHandler implements IOverlayHandler {
public static final NEEExtremeAutoCrafterHandler instance = new NEEExtremeAutoCrafterHandler();
private Class<?> guiExtremeAutoCrafterClz;
private NEEExtremeAutoCrafterHandler() {
try {
guiExtremeAutoCrafterClz = Class
.forName("wanion.avaritiaddons.block.extremeautocrafter.GuiExtremeAutoCrafter");// "Dire
// Autocrafting
// Table"
} catch (ClassNotFoundException ignored) {}
}
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
System.out.println("shift: " + shift);
if (this.guiExtremeAutoCrafterClz != null && this.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.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, new NBTTagCompound()));
}
return new PacketExtremeRecipe(recipeInputs);
}
@SubscribeEvent
public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe) {
}
if (event.gui instanceof GuiRecipe && isGuiExtremeTerm((GuiRecipe<?>) event.gui)) {
for (int i = 0; i < event.buttonList.size(); i++) {
event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i)));
}
}
}
private boolean isGuiExtremeTerm(GuiRecipe<?> gui) {
return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
}
}
@@ -0,0 +1,134 @@
package com.github.vfyjxf.nee.nei;
import static codechicken.lib.gui.GuiDraw.drawRect;
import java.util.Map;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import com.github.vfyjxf.nee.config.NEEConfig;
import com.github.vfyjxf.nee.utils.Ingredient;
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.GuiOverlayButton.ItemOverlayFormat;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.IRecipeHandler;
public class NEEGuiOverlayButton 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) {
boolean doCraftingHelp = Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.nopreview"))
|| Keyboard.isKeyDown(NEIClientConfig.getKeyBinding("nee.preview"));
if (this.ingredient.isCraftable()
&& (!this.isCraftingTerm || doCraftingHelp && this.ingredient.requiresToCraft())) {
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);
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 NEEGuiOverlayButton(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex, int xPosition,
int yPosition, int width, int height) {
super(firstGui, handler, recipeIndex, xPosition, yPosition, width, height);
if (NEEConfig.noShift) {
setRequireShiftForOverlayRecipe(false);
}
}
public NEEGuiOverlayButton(GuiOverlayButton button) {
this(
button.firstGui,
button.handler,
button.recipeIndex,
button.xPosition,
button.yPosition,
button.width,
button.height);
}
@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().anyMatch(
btn -> btn instanceof NEEItemOverlayState && showCraftingHotkeys((NEEItemOverlayState) btn))) {
final String previewKeyName = NEIClientConfig.getKeyName("nee.preview");
if (previewKeyName != null) {
hotkeys.put(previewKeyName + " + Click", I18n.format("neenergistics.gui.tooltip.crafting.preview"));
}
final String noPreviewKeyName = NEIClientConfig.getKeyName("nee.nopreview");
if (noPreviewKeyName != null) {
hotkeys.put(noPreviewKeyName + " + Click", I18n.format("neenergistics.gui.tooltip.crafting.nopreview"));
}
}
return hotkeys;
}
private static boolean showCraftingHotkeys(NEEItemOverlayState button) {
return button.isCraftingTerm() && button.getIngredient().isCraftable()
&& button.getIngredient().requiresToCraft();
}
}
@@ -0,0 +1,115 @@
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.network.NEENetworkHandler;
import com.github.vfyjxf.nee.network.packet.PacketArcaneRecipe;
import com.github.vfyjxf.nee.utils.ItemUtils;
import appeng.util.Platform;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.GuiOverlayButton;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
/**
* @author vfyjxf
*/
public class NEEKnowledgeInscriberHandler implements IOverlayHandler {
public static final NEEKnowledgeInscriberHandler instance = new NEEKnowledgeInscriberHandler();
private Class<?> knowledgeInscriberClz;
private Class<?> itemAspectClz;
private NEEKnowledgeInscriberHandler() {
try {
knowledgeInscriberClz = Class.forName("thaumicenergistics.client.gui.GuiKnowledgeInscriber");// "Knowledge
// Inscriber"
} 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();
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 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 onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe && isGuiPatternTerm((GuiRecipe<?>) event.gui)) {
for (int i = 0; i < event.buttonList.size(); i++) {
event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i)));
}
}
}
private boolean isGuiPatternTerm(GuiRecipe<?> gui) {
return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
}
}
@@ -0,0 +1,280 @@
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.NEEGuiOverlayButton.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.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.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.GuiOverlayButton;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.GuiRecipe;
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";
public static Map<String, PositionedStack> ingredients = new HashMap<>();// Add the function of mouse wheel to
// switch materials
public static final NEEPatternTerminalHandler instance = new NEEPatternTerminalHandler();
private NEEPatternTerminalHandler() {}
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
NEENetworkHandler.getInstance().sendToServer(packRecipe(recipe, recipeIndex));
if (Loader.isModLoaded(ModIDs.FC)) {
fluidCraftOverlayRecipe(firstGui, recipe, recipeIndex, shift);
}
}
@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, boolean shift) {
FluidPatternTerminalRecipeTransferHandler.INSTANCE.overlayRecipe(firstGui, recipe, recipeIndex, shift);
}
private PacketNEIPatternRecipe packRecipe(IRecipeHandler recipe, int recipeIndex) {
if (isCraftingTableRecipe(recipe)) {
return packCraftingTableRecipe(recipe, recipeIndex);
} else {
return packProcessRecipe(recipe, recipeIndex);
}
}
private 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;
}
}
private PacketNEIPatternRecipe packProcessRecipe(IRecipeHandler recipe, int recipeIndex) {
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.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(
INPUT_KEY + inputIndex,
ItemUtils.writeItemStackToNBT(currentStack, new NBTTagCompound()));
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, new NBTTagCompound()));
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.item;
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.items[0];
boolean areItemStackEqual = firstStack.isItemEqual(currentStack)
&& ItemStack.areItemStackTagsEqual(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 NBTTagCompound recipeInputs = new NBTTagCompound();
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
NEEPatternTerminalHandler.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.item;
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(INPUT_KEY + slotIndex, ItemUtils.writeItemStackToNBT(stack, new NBTTagCompound()));
NEEPatternTerminalHandler.ingredients.put(INPUT_KEY + slotIndex, positionedStack);
}
}
return new PacketNEIPatternRecipe(recipeInputs, null);
}
@SubscribeEvent
public void onActionPerformedEventPre(GuiOverlayButton.UpdateOverlayButtonsEvent.Post event) {
if (event.gui instanceof GuiRecipe && isGuiPatternTerm((GuiRecipe<?>) event.gui)) {
for (int i = 0; i < event.buttonList.size(); i++) {
event.buttonList.set(i, new NEEGuiOverlayButton(event.buttonList.get(i)));
}
}
}
private boolean isGuiPatternTerm(GuiRecipe<?> gui) {
return this.getClass().isInstance(gui.getHandler().getOverlayHandler(gui.firstGui, 0));
}
}
@@ -0,0 +1,35 @@
package com.github.vfyjxf.nee.nei;
import java.util.ArrayList;
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 codechicken.nei.api.IBookmarkContainerHandler;
public class NEETerminalBookmarkContainerHandler implements IBookmarkContainerHandler {
public static final NEETerminalBookmarkContainerHandler instance = new NEETerminalBookmarkContainerHandler();
private NEETerminalBookmarkContainerHandler() {}
@Override
public void pullBookmarkItemsFromContainer(GuiContainer guiContainer, ArrayList<ItemStack> bookmarkItems) {
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());
}
}
@@ -1,227 +0,0 @@
package com.github.vfyjxf.nee.network;
import static com.github.vfyjxf.nee.NotEnoughEnergistics.instance;
import javax.annotation.Nullable;
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;
@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);
}
}
}
}
} 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;
}
@Nullable
@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;
}
}
} else {
if (tile != null) {
if (guiId == PATTERN_INTERFACE_ID) {
if (tile instanceof TilePatternInterface) {
return new GuiPatternInterface(player.inventory, (TilePatternInterface) tile);
}
}
}
}
} 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;
int z = tile.zCoord;
player.openGui(instance, ID << 4 | (side.ordinal()), tile.getWorldObj(), x, y, z);
}
public static void openGui(EntityPlayer player, int ID, World world) {
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
player.openGui(instance, (ID << 4), world, 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,14 +4,10 @@ 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;
import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
@@ -25,6 +21,10 @@ public class NEENetworkHandler {
return packId++;
}
private NEENetworkHandler() {
throw new IllegalStateException("Utility class");
}
public static SimpleNetworkWrapper getInstance() {
return INSTANCE;
}
@@ -52,22 +52,6 @@ public class NEENetworkHandler {
PacketCraftingRequest.class,
nextId(),
Side.SERVER);
INSTANCE.registerMessage(
PacketOpenCraftAmount.Handler.class,
PacketOpenCraftAmount.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,
nextId(),
Side.SERVER);
INSTANCE.registerMessage(
PacketValueConfigClient.Handler.class,
PacketValueConfigClient.class,
nextId(),
Side.CLIENT);
INSTANCE.registerMessage(PacketNEIBookmark.Handler.class, PacketNEIBookmark.class, nextId(), Side.SERVER);
}
}
@@ -1,39 +1,12 @@
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.concurrent.Future;
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 appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
@@ -41,20 +14,15 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.security.ISecurityGrid;
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.helpers.IContainerCraftingPacket;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -126,61 +94,55 @@ public class PacketCraftingRequest implements IMessage {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (GuiUtils.isWirelessCraftingTermContainer(container)) {
message.handlerWirelessCraftingRequest((ContainerWirelessCraftingTerminal) container, message, player);
} else if (container instanceof AEBaseContainer) {
if (container instanceof AEBaseContainer && message.getRequireToCraftStack() != null) {
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();
final IGridNode gridNode = ((IGridHost) target).getGridNode(ForgeDirection.UNKNOWN);
if (gridNode != null) {
final IGrid grid = gridNode.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 (container instanceof ContainerCraftingAmount) {
message.handlerCraftingAmountRequest(
(ContainerCraftingAmount) container,
message,
grid,
player);
}
if (security != null && security.hasPermission(player, SecurityPermissions.CRAFT)) {
handlerCraftingTermRequest(
(IContainerCraftingPacket) container,
baseContainer.getOpenContext(),
grid,
message,
player);
}
}
}
}
}
return null;
}
}
private void handlerCraftingTermRequest(ContainerCraftingTerm container, PacketCraftingRequest message, IGrid grid,
EntityPlayerMP player) {
if (message.getRequireToCraftStack() != null) {
private void handlerCraftingTermRequest(IContainerCraftingPacket craftingPacket, ContainerOpenContext context,
IGrid grid, PacketCraftingRequest message, EntityPlayerMP player) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(
player.worldObj,
grid,
container.getActionSource(),
craftingPacket.getActionSource(),
message.getRequireToCraftStack(),
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);
Platform.openGUI(player, context.getTile(), context.getSide(), GuiBridge.GUI_CRAFTING_CONFIRM);
if (player.openContainer instanceof ContainerCraftConfirm) {
final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
ccc.setItemToCraft(message.getRequireToCraftStack());
@@ -188,195 +150,15 @@ public class PacketCraftingRequest implements IMessage {
ccc.setAutoStart(message.isAutoStart());
}
}
} 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) {
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;
}
}
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);
int x = (int) player.posX;
int y = (int) player.posY;
int z = (int) player.posZ;
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) {
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
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);
}
}
}
}
}
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;
}
}
@@ -0,0 +1,69 @@
package com.github.vfyjxf.nee.network.packet;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import com.github.vfyjxf.nee.utils.ItemUtils;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
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 PacketNEIBookmark implements IMessage {
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) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if (container instanceof AEBaseContainer && message.bookmarkItems != null) {
AEBaseContainer baseContainer = (AEBaseContainer) container;
for (Object key : message.bookmarkItems.func_150296_c()) {
final IAEItemStack request = AEItemStack
.create(ItemUtils.loadItemStackFromNBT(message.bookmarkItems.getCompoundTag((String) key)));
final IAEItemStack extracted = Platform.poweredExtraction(
baseContainer.getPowerSource(),
baseContainer.getCellInventory(),
request,
baseContainer.getActionSource());
if (extracted != null) {
InventoryAdaptor.getAdaptor(player, ForgeDirection.UNKNOWN).addItems(extracted.getItemStack());
}
}
}
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) {
((ContainerPatternTerm) container).getPatternTerminal().setCraftingRecipe(craftingMode);
} else if (Loader.isModLoaded(ModIDs.FC) && container instanceof ContainerFluidPatternTerminal) {
((ContainerFluidPatternTerminal) container).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,52 +0,0 @@
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;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
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 PacketOpenGui implements IMessage {
private int guiId;
public PacketOpenGui() {}
public PacketOpenGui(int guiId) {
this.guiId = guiId;
}
@Override
public void fromBytes(ByteBuf buf) {
this.guiId = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.guiId);
}
public static final class Handler implements IMessageHandler<PacketOpenGui, 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();
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;
}
}
@@ -1,75 +0,0 @@
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 codechicken.nei.recipe.GuiRecipe;
import cpw.mods.fml.common.FMLCommonHandler;
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.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
/**
* @author vfyjxf
*/
public class PacketValueConfigClient implements IMessage {
private String name;
private String value;
public PacketValueConfigClient() {}
public PacketValueConfigClient(String name, String value) {
this.name = name;
this.value = value;
}
public PacketValueConfigClient(String name) {
this.name = name;
this.value = "";
}
@Override
public void fromBytes(ByteBuf buf) {
this.name = ByteBufUtils.readUTF8String(buf);
this.value = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, this.name);
ByteBufUtils.writeUTF8String(buf, this.value);
}
public static final class Handler implements IMessageHandler<PacketValueConfigClient, IMessage> {
@Override
public IMessage onMessage(PacketValueConfigClient message, MessageContext ctx) {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
handMessage(message, ctx);
}
return null;
}
@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);
}
}
}
}
}
}
@@ -1,118 +0,0 @@
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 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;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
public class PacketValueConfigServer implements IMessage {
private String name;
private String value;
public PacketValueConfigServer() {}
public PacketValueConfigServer(String name, String value) {
this.name = name;
this.value = value;
}
public PacketValueConfigServer(String name) {
this.name = name;
this.value = "";
}
@Override
public void fromBytes(ByteBuf buf) {
this.name = ByteBufUtils.readUTF8String(buf);
this.value = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, this.name);
ByteBufUtils.writeUTF8String(buf, this.value);
}
public static final class Handler implements IMessageHandler<PacketValueConfigServer, IMessage> {
@Override
public IMessage onMessage(PacketValueConfigServer message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
Container container = player.openContainer;
if ("Container.selectedSlot".equals(message.name)) {
if (container instanceof ContainerPatternInterface) {
ContainerPatternInterface cpc = (ContainerPatternInterface) container;
int slotIndex = Integer.parseInt(message.value);
Slot slot = container.getSlot(slotIndex);
if (slot instanceof SlotRestrictedInput) {
cpc.setSelectedSlotIndex(slot.slotNumber);
}
}
} else if ("Gui.PatternInterface".equals(message.name)) {
if (container instanceof ContainerPatternInterface) {
ContainerPatternInterface cpc = (ContainerPatternInterface) container;
TilePatternInterface tile = (TilePatternInterface) cpc.getTileEntity();
tile.cancelWork(cpc.getSelectedSlotIndex());
cpc.removeCurrentRecipe();
tile.updateCraftingList();
}
} else if ("PatternInterface.check".equals(message.name)) {
if (container instanceof AEBaseContainer) {
IGrid grid = message.getNetwork((AEBaseContainer) container);
if (grid != null) {
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
if (gridNode.getMachine() instanceof TilePatternInterface) {
NEENetworkHandler.getInstance()
.sendTo(new PacketValueConfigClient("PatternInterface.check", "true"), player);
return null;
}
}
NEENetworkHandler.getInstance()
.sendTo(new PacketValueConfigClient("PatternInterface.check", "false"), player);
}
}
}
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,10 @@ 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.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 +21,9 @@ 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);
}
}
@@ -1,95 +1,12 @@
package com.github.vfyjxf.nee.proxy;
import static com.github.vfyjxf.nee.block.BlockPatternInterface.BLOCK_INSTANCE;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.ShapedOreRecipe;
import com.github.vfyjxf.nee.NotEnoughEnergistics;
import com.github.vfyjxf.nee.block.BlockPatternInterface;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import appeng.api.AEApi;
import appeng.api.definitions.IBlocks;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IMaterials;
import appeng.api.definitions.IParts;
import appeng.api.util.AEColor;
import appeng.core.features.ActivityState;
import appeng.core.features.BlockStackSrc;
import appeng.tile.AEBaseTile;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
public class CommonProxy {
public void init(FMLInitializationEvent event) {
AEBaseTile.registerTileItem(
TilePatternInterface.class,
new BlockStackSrc(BLOCK_INSTANCE, 0, ActivityState.Enabled));
registerRecipe();
}
public void init(FMLInitializationEvent event) {}
public void preInit(FMLPreInitializationEvent event) {
registerBlocks();
registerItems();
registerTileEntities();
}
public void preInit(FMLPreInitializationEvent event) {}
public void registerItems() {
GameRegistry.registerItem(BlockPatternInterface.ITEM_INSTANCE, "tile.pattern_interface");
}
public void registerBlocks() {
GameRegistry.registerBlock(BLOCK_INSTANCE, null, "tile.pattern_interface");
}
public void registerTileEntities() {
GameRegistry.registerTileEntity(
TilePatternInterface.class,
NotEnoughEnergistics.MODID + "." + "tile.pattern_interface");
}
public void registerRecipe() {
final IDefinitions definitions = AEApi.instance().definitions();
final IMaterials materials = definitions.materials();
final IParts parts = definitions.parts();
final IBlocks blocks = definitions.blocks();
ItemStack blankPattern = null;
ItemStack patternTerm = null;
ItemStack meInterface = null;
ItemStack monitor = null;
ItemStack cableSmart = parts.cableSmart().stack(AEColor.Transparent, 1);
if (materials.blankPattern().maybeStack(1).isPresent()) {
blankPattern = materials.blankPattern().maybeStack(1).get();
}
if (parts.patternTerminal().maybeStack(1).isPresent()) {
patternTerm = parts.patternTerminal().maybeStack(1).get();
}
if (blocks.iface().maybeStack(1).isPresent()) {
meInterface = blocks.iface().maybeStack(1).get();
}
if (blocks.craftingMonitor().maybeStack(1).isPresent()) {
monitor = blocks.craftingMonitor().maybeStack(1).get();
}
GameRegistry.addRecipe(
new ShapedOreRecipe(
BLOCK_INSTANCE,
"aba",
"cdc",
"eee",
'a',
blankPattern,
'b',
patternTerm,
'c',
meInterface,
'd',
monitor,
'e',
cableSmart));
}
}
@@ -6,14 +6,11 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
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.client.gui.implementations.GuiPatternTerm;
import appeng.client.gui.implementations.GuiPatternTermEx;
import appeng.container.implementations.ContainerPatternTerm;
@@ -34,30 +31,6 @@ public class GuiUtils {
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;
@@ -81,19 +54,10 @@ public class GuiUtils {
}
}
public static boolean isGuiCraftingTerm(GuiScreen guiScreen) {
return guiScreen instanceof GuiCraftingTerm || isGuiWirelessCrafting(guiScreen);
}
public static boolean isFluidCraftPatternTermEx(GuiScreen guiScreen) {
return isFluidCraftModloaded && guiScreen instanceof GuiFluidPatternTerminalEx;
}
public static boolean isFluidCraftPatternTerm(GuiScreen guiScreen) {
return isFluidCraftModloaded
&& (guiScreen instanceof GuiFluidPatternTerminal || guiScreen instanceof GuiFluidPatternTerminalEx);
}
public static boolean isPatternTerm(GuiScreen guiScreen) {
if (isFluidCraftModloaded) {
return guiScreen instanceof GuiPatternTerm || guiScreen instanceof GuiPatternTermEx
@@ -104,7 +68,4 @@ public class GuiUtils {
}
}
public static boolean isGuiCraftConfirm(GuiScreen gui) {
return gui instanceof GuiCraftConfirm || isWirelessGuiCraftConfirm(gui);
}
}
@@ -1,31 +1,26 @@
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;
import java.util.function.Predicate;
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;
import cpw.mods.fml.relauncher.ReflectionHelper.UnableToFindFieldException;
public class IngredientTracker {
@@ -35,20 +30,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 : getStorageStacks(IAEItemStack::isCraftable)) {
if (ingredient.getIngredient().contains(stack.getItemStack())) {
ingredient.setCraftableIngredient(stack.getItemStack());
}
@@ -58,90 +49,46 @@ 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();
private List<IAEItemStack> getStorageStacks(Predicate<IAEItemStack> predicate) {
List<IAEItemStack> storageStacks = new ArrayList<>();
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());
ItemRepo repo = getItemRepo(termGui);
if (repo != null) {
try {
@SuppressWarnings("unchecked")
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 (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return craftableStacks;
return storageStacks;
}
@SuppressWarnings("unchecked")
private List<IAEItemStack> getStorageStacks() {
List<IAEItemStack> list = new ArrayList<>();
if (termGui != null) {
private ItemRepo getItemRepo(GuiContainer termGui) {
Class<?> clazz = termGui.getClass();
ItemRepo repo = null;
while (repo == null && clazz != 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();
repo = (ItemRepo) ReflectionHelper.findField(clazz, "repo").get(termGui);
} catch (UnableToFindFieldException | IllegalAccessException e) {
clazz = clazz.getSuperclass();
}
}
return list;
return repo;
}
public List<Ingredient> getIngredients() {
@@ -180,7 +127,7 @@ public class IngredientTracker {
return currentIndex < getRequireStacks().size();
}
public void requestNextIngredient() {
public void requestNextIngredient(boolean noPreview) {
IAEItemStack stack = AEItemStack.create(this.getRequiredStack(currentIndex));
if (stack != null) {
NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview));
@@ -231,18 +178,16 @@ public class IngredientTracker {
@SuppressWarnings("unchecked")
public void calculateIngredients() {
List<IAEItemStack> stacks = getStorageStacks(stack -> NEEConfig.matchOtherItems || stack.isCraftable());
List<IAEItemStack> stacks = NEEConfig.matchOtherItems ? getStorageStacks() : getCraftableStacks();
for (Ingredient ingredient : this.ingredients) {
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 (ingredient.getIngredient().contains(stack.getItemStack()) && stack.getStackSize() > 0) {
ingredient.addCount(stack.getStackSize());
if (ingredient.requiresToCraft()) {
stack.setStackSize(0);
} else {
stack.setStackSize(stack.getStackSize() - ingredient.getRequireCount());
}
}
}
@@ -1,7 +1,5 @@
neenergistics.gui.tooltip.helper.crafting.text1=click to request missing items
neenergistics.gui.tooltip.helper.crafting.text2=click to request the recipe result.
neenergistics.gui.tooltip.missing=Missing Items
neenergistics.gui.tooltip.helper.pattern=Autocrafting available
neenergistics.gui.tooltip.crafting.preview=Request missing items
neenergistics.gui.tooltip.crafting.nopreview=Request missing items (No Preview)
nei.options.keys.nee=NotEnoughEnergistics
nei.options.keys.nee.count=Change Item Count
@@ -17,4 +15,3 @@ gui.neenergistics.button.name.whitelist=Whitelist
gui.neenergistics.button.title.remove=Remove
gui.neenergistics.button.tooltip.remove=Remove and cancel the current recipe
tile.neenergistics.pattern_interface.name=Pattern Interface
@@ -1,6 +1,6 @@
neenergistics.gui.tooltip.helper.crafting.text1=Нажмите, чтобы запоросить отсутсвующие предметы
neenergistics.gui.tooltip.missing=Отсутствуют требуемые предметы
neenergistics.gui.tooltip.helper.pattern=Автокрафт доступен
neenergistics.gui.tooltip.crafting.preview=Запоросить отсутсвующие предметы
neenergistics.gui.tooltip.crafting.nopreview=Запоросить отсутсвующие предметы (без превью)
nei.options.keys.nee=NotEnoughEnergistics
nei.options.keys.nee.count=Изменить кол-во
nei.options.keys.nee.ingredient=Выбрать ингредиент
@@ -1,8 +1,3 @@
neenergistics.gui.tooltip.helper.crafting.text1=点击以请求缺失物品
neenergistics.gui.tooltip.helper.crafting.text2=点击以请求配方成品
neenergistics.gui.tooltip.missing=缺失物品
neenergistics.gui.tooltip.helper.pattern=自动合成已启用
nei.options.keys.nee=NotEnoughEnergistics
nei.options.keys.nee.count=修改物品数量
nei.options.keys.nee.ingredient=选择材料
@@ -16,6 +11,3 @@ gui.neenergistics.button.name.disabled=关闭
gui.neenergistics.button.name.whitelist=白名单
gui.neenergistics.button.title.remove=删除
gui.neenergistics.button.tooltip.remove=删除并取消当前配方
tile.neenergistics.pattern_interface.name=样板接口
Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB