diff --git a/dependencies.gradle b/dependencies.gradle index bf4a753..0723160 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -4,9 +4,6 @@ dependencies { compile("com.github.GTNewHorizons:CodeChickenCore:1.1.3:dev") compile("com.github.GTNewHorizons:NotEnoughItems:2.1.22-GTNH:dev") - runtime(files("libs/BetterCrashes-1.0.0-dev.jar")) - runtime(files("libs/Grimoire-mc1.7.10-dev-3.2.7.jar")) - compileOnly("com.github.GTNewHorizons:Avaritiaddons:1.5.2-GTNH:dev") {transitive = false} compileOnly("com.github.GTNewHorizons:BuildCraftCompat:7.1.9:dev") {transitive = false} compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.27:dev") {transitive = false} diff --git a/gradle.properties b/gradle.properties index e58f6ca..6ec09e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ modName = NotEnoughEnergistics # This is a case-sensitive string to identify your mod. Convention is to use lower case. modId = neenergistics -modVersion=1.3.9 +modVersion=1.4.0 modGroup = com.github.vfyjxf.nee diff --git a/libs/BetterCrashes-1.0.0-dev.jar b/libs/BetterCrashes-1.0.0-dev.jar deleted file mode 100644 index e575138..0000000 Binary files a/libs/BetterCrashes-1.0.0-dev.jar and /dev/null differ diff --git a/libs/Grimoire-mc1.7.10-dev-3.2.7.jar b/libs/Grimoire-mc1.7.10-dev-3.2.7.jar deleted file mode 100644 index 943ab93..0000000 Binary files a/libs/Grimoire-mc1.7.10-dev-3.2.7.jar and /dev/null differ diff --git a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java index 40e9097..5fb73d6 100644 --- a/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java +++ b/src/main/java/com/github/vfyjxf/nee/NotEnoughEnergistics.java @@ -1,7 +1,7 @@ package com.github.vfyjxf.nee; import com.github.vfyjxf.nee.config.NEEConfig; -import com.github.vfyjxf.nee.gui.NEEGuiHandler; +import com.github.vfyjxf.nee.network.NEEGuiHandler; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.proxy.CommonProxy; import cpw.mods.fml.common.FMLCommonHandler; @@ -40,20 +40,21 @@ public class NotEnoughEnergistics { public static NotEnoughEnergistics instance; @EventHandler - public void preInit(FMLPreInitializationEvent e) { + public void preInit(FMLPreInitializationEvent event) { + proxy.preInit(event); NEENetworkHandler.init(); NEEConfig.loadConfig(new File(Launch.minecraftHome, "config/NotEnoughEnergistics.cfg")); FMLCommonHandler.instance().bus().register(new NEEConfig()); } - @EventHandler - public void postInit(FMLPostInitializationEvent event) { - NetworkRegistry.INSTANCE.registerGuiHandler(this, new NEEGuiHandler()); - } - @EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); } + @EventHandler + public void postInit(FMLPostInitializationEvent event) { + NetworkRegistry.INSTANCE.registerGuiHandler(this, new NEEGuiHandler()); + } + } diff --git a/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java b/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java index 3ccb0c7..0143801 100644 --- a/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java +++ b/src/main/java/com/github/vfyjxf/nee/asm/AppengHelper.java @@ -22,6 +22,8 @@ import org.lwjgl.input.Mouse; import java.util.ArrayList; import java.util.List; +import static com.github.vfyjxf.nee.nei.NEECraftingHandler.INPUT_KEY; + public class AppengHelper { /** @@ -57,7 +59,7 @@ public class AppengHelper { private static void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) { List craftingSlots = new ArrayList<>(); int currentSlotIndex = currentSlot.getSlotIndex(); - PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlotIndex); + PositionedStack currentIngredients = NEECraftingHandler.ingredients.get(INPUT_KEY + currentSlotIndex); if (currentIngredients != null && currentIngredients.items.length > 1) { int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients); if (currentStackIndex >= 0) { @@ -76,7 +78,7 @@ public class AppengHelper { if (NEEConfig.allowSynchronousSwitchIngredient) { for (Slot slot : getCraftingSlots(gui)) { - PositionedStack slotIngredients = NEECraftingHandler.ingredients.get("input" + slot.getSlotIndex()); + PositionedStack slotIngredients = NEECraftingHandler.ingredients.get(INPUT_KEY + slot.getSlotIndex()); boolean areItemStackEqual = currentSlot.getHasStack() && slot.getHasStack() && diff --git a/src/main/java/com/github/vfyjxf/nee/block/BlockPatternInterface.java b/src/main/java/com/github/vfyjxf/nee/block/BlockPatternInterface.java new file mode 100644 index 0000000..211888b --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/block/BlockPatternInterface.java @@ -0,0 +1,51 @@ +package com.github.vfyjxf.nee.block; + +import appeng.block.AEBaseItemBlock; +import appeng.block.AEBaseTileBlock; +import appeng.core.features.AEFeature; +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; +import com.github.vfyjxf.nee.network.NEEGuiHandler; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.EnumSet; + +/** + * @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; + } + + if (!world.isRemote) { + TilePatternInterface tile = this.getTileEntity(world,x, y, z); + if (tile != null) { + NEEGuiHandler.openGui(player, NEEGuiHandler.PATTERN_INTERFACE_ID, tile, ForgeDirection.UNKNOWN); + return true; + } + } + + return false; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/block/tile/TilePatternInterface.java b/src/main/java/com/github/vfyjxf/nee/block/tile/TilePatternInterface.java new file mode 100644 index 0000000..9be7edc --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/block/tile/TilePatternInterface.java @@ -0,0 +1,707 @@ +package com.github.vfyjxf.nee.block.tile; + +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.*; +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 com.google.common.collect.ImmutableSet; +import cpw.mods.fml.relauncher.ReflectionHelper; +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 javax.annotation.Nonnull; +import java.util.*; +import java.util.stream.IntStream; + + +/** + * 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 craftingList; + private List 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, 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 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 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 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 cpuSet = cg.getCpus(); + + for (ICraftingCPU cpu : cpuSet) { + if (cpu instanceof CraftingCPUCluster) { + CraftingCPUCluster cluster = (CraftingCPUCluster) cpu; + final IItemList 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 possibleDirections) { + if (!this.hasItemsToPush()) { + return; + } + + + final Iterator 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 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 cpuSet = cg.getCpus(); + + final IItemList 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"); + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java index 30ec991..69a666d 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java @@ -4,18 +4,15 @@ import appeng.client.gui.AEBaseGui; import appeng.client.gui.implementations.GuiPatternTerm; import appeng.container.implementations.ContainerPatternTerm; import appeng.container.slot.SlotFake; -import codechicken.nei.PositionedStack; import codechicken.nei.VisiblityData; import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.api.TaggedInventoryArea; import com.github.vfyjxf.nee.config.ItemCombination; import com.github.vfyjxf.nee.config.NEEConfig; -import com.github.vfyjxf.nee.gui.widgets.GuiImgButtonEnableCombination; -import com.github.vfyjxf.nee.nei.NEECraftingHandler; +import com.github.vfyjxf.nee.client.gui.widgets.GuiImgButtonEnableCombination; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketSlotStackChange; import com.github.vfyjxf.nee.utils.GuiUtils; -import com.github.vfyjxf.nee.utils.ItemUtils; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.client.gui.inventory.GuiContainer; @@ -89,52 +86,6 @@ public class GuiEventHandler implements INEIGuiHandler { } } - private void handleRecipeIngredientChange(GuiContainer gui, Slot currentSlot, int dWheel) { - List craftingSlots = new ArrayList<>(); - int currentSlotIndex = currentSlot.getSlotIndex(); - PositionedStack currentIngredients = NEECraftingHandler.ingredients.get("input" + currentSlotIndex); - if (currentIngredients != null && currentIngredients.items.length > 1) { - int currentStackIndex = ItemUtils.getIngredientIndex(currentSlot.getStack(), currentIngredients); - if (currentStackIndex >= 0) { - int nextStackIndex = dWheel / 120; - for (int j = 0; j < Math.abs(nextStackIndex); j++) { - currentStackIndex = nextStackIndex > 0 ? currentStackIndex + 1 : currentStackIndex - 1; - if (currentStackIndex >= currentIngredients.items.length) { - currentStackIndex = 0; - } else if (currentStackIndex < 0) { - currentStackIndex = currentIngredients.items.length - 1; - } - - ItemStack currentStack = currentIngredients.items[currentStackIndex].copy(); - currentStack.stackSize = currentSlot.getStack().stackSize; - - if (NEEConfig.allowSynchronousSwitchIngredient) { - for (Slot slot : getCraftingSlots(gui)) { - - PositionedStack slotIngredients = NEECraftingHandler.ingredients.get("input" + slot.getSlotIndex()); - - boolean areItemStackEqual = currentSlot.getHasStack() && - slot.getHasStack() && - currentSlot.getStack().isItemEqual(slot.getStack()) && - ItemStack.areItemStackTagsEqual(currentSlot.getStack(), slot.getStack()); - - boolean areIngredientEqual = slotIngredients != null && currentIngredients.contains(slotIngredients.items[0]); - - if (areItemStackEqual && areIngredientEqual) { - craftingSlots.add(slot.slotNumber); - } - - } - } else { - craftingSlots.add(currentSlot.slotNumber); - } - NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(currentStack, craftingSlots)); - } - } - } - - } - @SuppressWarnings("unchecked") private List getCraftingSlots(GuiContainer gui) { List craftingSlots = new ArrayList<>(); diff --git a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java index 60155c8..a4014bb 100644 --- a/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/client/NEEContainerDrawHandler.java @@ -93,37 +93,22 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { Point point = guiRecipe.getRecipePosition(tracker.getRecipeIndex()); Slot currentSlot = guiRecipe.slotcontainer.getSlotWithStack(ingredient.getIngredient(), point.x, point.y); if (slot.equals(currentSlot)) { - if (!NEEConfig.enableCraftAmountSettingGui) { - GuiContainer firstGui = guiRecipe.firstGui; - boolean renderAutoAbleItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft(); - boolean renderCraftableItems = (firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui)) && ingredient.isCraftable(); - boolean renderMissingItems = (firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft(); - if (renderAutoAbleItems || renderCraftableItems) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); - this.drawCraftableTooltip = renderCraftableItems; - this.drawRequestTooltip = renderAutoAbleItems; - } - if (renderMissingItems) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); - this.drawMissingTooltip = true; - } - } else { - - if (ingredient.isCraftable()) { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); - this.drawRequestTooltip = true; - } else { - Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, - slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, - new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); - this.drawMissingTooltip = true; - } + GuiContainer firstGui = guiRecipe.firstGui; + boolean renderAutoAbleItems = (GuiUtils.isCraftingTerm(firstGui)) && ingredient.isCraftable() && ingredient.requiresToCraft(); + boolean renderCraftableItems = (GuiUtils.isPatternTerm(firstGui)) && ingredient.isCraftable(); + boolean renderMissingItems = (GuiUtils.isCraftingTerm(firstGui)) && !ingredient.isCraftable() && ingredient.requiresToCraft(); + if (renderAutoAbleItems || renderCraftableItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(0.0f, 0.0f, 1.0f, 0.4f).getRGB()); + this.drawCraftableTooltip = renderCraftableItems; + this.drawRequestTooltip = renderAutoAbleItems; + } + if (renderMissingItems) { + Gui.drawRect(slot.xDisplayPosition, slot.yDisplayPosition, + slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, + new Color(1.0f, 0.0f, 0.0f, 0.4f).getRGB()); + this.drawMissingTooltip = true; } } } @@ -138,8 +123,8 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { if (event.gui instanceof GuiRecipe) { GuiRecipe guiRecipe = (GuiRecipe) event.gui; GuiContainer firstGui = guiRecipe.firstGui; - boolean isGuiPatternTerm = firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(firstGui); - boolean isCraftingTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui); + boolean isGuiPatternTerm = GuiUtils.isPatternTerm(firstGui); + boolean isCraftingTerm = GuiUtils.isCraftingTerm(firstGui); if (isCraftingTerm || isGuiPatternTerm) { if (overlayButtons.isEmpty()) { setOverlayButtons(guiRecipe); @@ -172,8 +157,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { private void drawCraftingHelperTooltip(GuiRecipe guiRecipe, int mouseX, int mouseY) { List tooltips = new ArrayList<>(); - boolean isCraftingTerm = guiRecipe.firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(guiRecipe.firstGui); - if (isCraftingTerm) { + if (GuiUtils.isCraftingTerm(guiRecipe.firstGui)) { if (this.drawRequestTooltip) { tooltips.add(String.format("%s" + EnumChatFormatting.GRAY + " + " + EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.crafting"), @@ -183,8 +167,7 @@ public class NEEContainerDrawHandler implements IContainerDrawHandler { tooltips.add(EnumChatFormatting.RED + I18n.format("neenergistics.gui.tooltip.missing")); } } - boolean isPatternTerm = guiRecipe.firstGui instanceof GuiPatternTerm || GuiUtils.isPatternTermExGui(guiRecipe.firstGui); - if (this.drawCraftableTooltip && isPatternTerm) { + if (this.drawCraftableTooltip && GuiUtils.isPatternTerm(guiRecipe.firstGui)) { tooltips.add(EnumChatFormatting.BLUE + I18n.format("neenergistics.gui.tooltip.helper.pattern")); } //drawHoveringText diff --git a/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingAmount.java b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingAmount.java similarity index 84% rename from src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingAmount.java rename to src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingAmount.java index 1deb0e9..f3761ad 100644 --- a/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingAmount.java +++ b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingAmount.java @@ -1,10 +1,9 @@ -package com.github.vfyjxf.nee.gui; +package com.github.vfyjxf.nee.client.gui; import appeng.api.AEApi; import appeng.api.definitions.IDefinitions; import appeng.api.definitions.IParts; import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.AEBaseGui; import appeng.client.gui.widgets.GuiNumberBox; import appeng.client.gui.widgets.GuiTabButton; @@ -16,7 +15,6 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketSwitchGuis; import appeng.helpers.Reflected; import appeng.parts.reporting.PartCraftingTerminal; -import appeng.util.item.AEItemStack; import com.github.vfyjxf.nee.container.ContainerCraftingAmount; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest; @@ -25,22 +23,17 @@ import com.github.vfyjxf.nee.utils.ModIDs; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Optional; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.p455w0rd.wirelesscraftingterminal.items.ItemEnum; import net.p455w0rd.wirelesscraftingterminal.reference.Reference; -import java.util.Collections; - -import static com.github.vfyjxf.nee.nei.NEECraftingHelper.*; - public class GuiCraftingAmount extends AEBaseGui { private GuiNumberBox amountToCraft; private GuiTabButton originalGuiBtn; - private GuiButton start; + private GuiButton next; private GuiButton plus1; private GuiButton plus10; @@ -80,7 +73,7 @@ public class GuiCraftingAmount extends AEBaseGui { 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.start = new GuiButton(0, this.guiLeft + 128, this.guiTop + 51, 38, 20, GuiText.Next.getLocal())); + 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(); @@ -121,19 +114,16 @@ public class GuiCraftingAmount extends AEBaseGui { @Override public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { - this.start.displayString = isShiftKeyDown() ? GuiText.Start.getLocal() : GuiText.Next.getLocal(); + 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.start.enabled = this.amountToCraft.getText().length() > 0; + this.next.enabled = this.amountToCraft.getText().length() > 0; } catch (final NumberFormatException e) { - this.start.enabled = false; - } - if (tracker.getRequireStacks().isEmpty()) { - this.start.enabled = false; + this.next.enabled = false; } this.amountToCraft.drawTextBox(); @@ -142,17 +132,13 @@ public class GuiCraftingAmount extends AEBaseGui { @Override public void drawScreen(int mouseX, int mouseY, float btn) { super.drawScreen(mouseX, mouseY, btn); - if (start.func_146115_a() && !start.enabled && start.visible && tracker.getRequireStacks().isEmpty()) { - //drawHoveringText - this.func_146283_a(Collections.singletonList(I18n.format("gui.neenergistics.button.without")), mouseX, mouseY); - } } @Override protected void keyTyped(final char character, final int key) { if (!this.checkHotbarKeys(key)) { if (key == 28) { - this.actionPerformed(this.start); + this.actionPerformed(this.next); } if ((key == 211 || key == 205 || key == 203 || key == 14 || character == '-' || Character.isDigit(character)) && this.amountToCraft.textboxKeyTyped(character, key)) { try { @@ -199,16 +185,8 @@ public class GuiCraftingAmount extends AEBaseGui { } } - if (btn == this.start) { - int craftingAmount = Integer.parseInt(amountToCraft.getText()); - tracker.setCraftingAmount(craftingAmount); - tracker.calculateIngredients(); - if (!tracker.getRequireStacks().isEmpty()) { - IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(0)); - noPreview = isShiftKeyDown(); - NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview)); - stackIndex = 1; - } + if (btn == this.next) { + NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(Integer.parseInt(this.amountToCraft.getText()), isShiftKeyDown())); } } catch (final NumberFormatException e) { // nope.. diff --git a/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingConfirm.java similarity index 96% rename from src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java rename to src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingConfirm.java index 0db4f73..5f4ed20 100644 --- a/src/main/java/com/github/vfyjxf/nee/gui/GuiCraftingConfirm.java +++ b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiCraftingConfirm.java @@ -1,4 +1,4 @@ -package com.github.vfyjxf.nee.gui; +package com.github.vfyjxf.nee.client.gui; import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEItemStack; diff --git a/src/main/java/com/github/vfyjxf/nee/client/gui/GuiPatternInterface.java b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiPatternInterface.java new file mode 100644 index 0000000..baeb3ab --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/client/gui/GuiPatternInterface.java @@ -0,0 +1,70 @@ +package com.github.vfyjxf.nee.client.gui; + +import appeng.client.gui.AEBaseGui; +import appeng.container.slot.SlotRestrictedInput; +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 net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + + +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) { + 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"); + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java b/src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonEnableCombination.java similarity index 92% rename from src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java rename to src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonEnableCombination.java index 2c8ab59..04ef79a 100644 --- a/src/main/java/com/github/vfyjxf/nee/gui/widgets/GuiImgButtonEnableCombination.java +++ b/src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonEnableCombination.java @@ -1,4 +1,4 @@ -package com.github.vfyjxf.nee.gui.widgets; +package com.github.vfyjxf.nee.client.gui.widgets; import appeng.client.gui.widgets.ITooltip; import com.github.vfyjxf.nee.config.ItemCombination; @@ -27,7 +27,11 @@ public class GuiImgButtonEnableCombination extends GuiButton implements ITooltip GL11.glPushMatrix(); GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F); GL11.glScalef(0.5f, 0.5f, 0.5f); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + if (this.enabled) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } else { + GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f); + } minecraft.renderEngine.bindTexture(new ResourceLocation("neenergistics", "textures/gui/states.png")); this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; this.drawTexturedModalRect(0, 0, 0, 0, 16, 16); diff --git a/src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonRemove.java b/src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonRemove.java new file mode 100644 index 0000000..5310fd1 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/client/gui/widgets/GuiImgButtonRemove.java @@ -0,0 +1,71 @@ +package com.github.vfyjxf.nee.client.gui.widgets; + +import appeng.client.gui.widgets.ITooltip; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.resources.I18n; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +public class GuiImgButtonRemove extends GuiButton implements ITooltip { + + public GuiImgButtonRemove(int x, int y) { + super(0, x, y, ""); + this.width = 8; + this.height = 8; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (this.visible) { + + GL11.glPushMatrix(); + GL11.glTranslatef(this.xPosition, this.yPosition, 0.0F); + GL11.glScalef(0.5f, 0.5f, 0.5f); + if (this.enabled) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } else { + GL11.glColor4f(0.5f, 0.5f, 0.5f, 1.0f); + } + mc.renderEngine.bindTexture(new ResourceLocation("neenergistics", "textures/gui/states.png")); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + this.drawTexturedModalRect(0, 0, 0, 0, 16, 16); + this.drawTexturedModalRect(0, 0, 0, 32, 16, 16); + this.mouseDragged(mc, mouseX, mouseY); + GL11.glPopMatrix(); + } + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + } + + @Override + public String getMessage() { + return I18n.format("gui.neenergistics.button.title.remove") + + "\n" + + I18n.format("gui.neenergistics.button.tooltip.remove"); + } + + @Override + public int xPos() { + return this.xPosition; + } + + @Override + public int yPos() { + return this.yPosition; + } + + @Override + public int getWidth() { + return this.width; + } + + @Override + public int getHeight() { + return this.height; + } + + @Override + public boolean isVisible() { + return this.visible; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java index ee784e9..242cb35 100644 --- a/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java +++ b/src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java @@ -32,7 +32,6 @@ public class NEEConfig { public static boolean enableNEIDragNDrop = true; public static boolean useStackSizeFromNEI = true; public static boolean keepGhostitems = true; - public static boolean enableCraftAmountSettingGui = false; public static int draggedStackDefaultSize = 1; @@ -68,9 +67,6 @@ public class NEEConfig { drawHighlight = config.get(CATEGORY_CRAFTING_HELPER, "drawHighlight", true, "if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean(); - - enableCraftAmountSettingGui = config.get(CATEGORY_CRAFTING_HELPER, "enableCraftAmountSettingGui", false, - "If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean(); } { @@ -90,7 +86,9 @@ public class NEEConfig { "The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt(); } - if (config.hasChanged()) config.save(); + if (config.hasChanged()) { + config.save(); + } } public static void reload() { @@ -124,9 +122,6 @@ public class NEEConfig { drawHighlight = config.get(CATEGORY_CRAFTING_HELPER, "drawHighlight", true, "if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean(); - - enableCraftAmountSettingGui = config.get(CATEGORY_CRAFTING_HELPER, "enableCraftAmountSettingGui", false, - "If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean(); } { diff --git a/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingAmount.java b/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingAmount.java index 7caf648..22cb6ea 100644 --- a/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingAmount.java +++ b/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingAmount.java @@ -11,12 +11,14 @@ import appeng.tile.inventory.AppEngInternalInventory; 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; public class ContainerCraftingAmount extends AEBaseContainer { private final Slot resultSlot; private ItemStack resultStack; + private NBTTagCompound recipe; public ContainerCraftingAmount(InventoryPlayer ip, Object anchor) { super(ip, anchor); @@ -44,6 +46,10 @@ public class ContainerCraftingAmount extends AEBaseContainer { return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget()); } + public NBTTagCompound getRecipe() { + return recipe; + } + public Slot getResultSlot() { return resultSlot; } @@ -55,4 +61,8 @@ public class ContainerCraftingAmount extends AEBaseContainer { public void setResultStack(ItemStack resultStack) { this.resultStack = resultStack; } + + public void setRecipe(NBTTagCompound recipe) { + this.recipe = recipe; + } } diff --git a/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingConfirm.java b/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingConfirm.java new file mode 100644 index 0000000..05311bc --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/container/ContainerCraftingConfirm.java @@ -0,0 +1,47 @@ +package com.github.vfyjxf.nee.container; + +import appeng.api.storage.ITerminalHost; +import appeng.container.implementations.ContainerCraftConfirm; +import appeng.util.Platform; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +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()) { + if (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; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/container/ContainerPatternInterface.java b/src/main/java/com/github/vfyjxf/nee/container/ContainerPatternInterface.java new file mode 100644 index 0000000..8ebb1f7 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/container/ContainerPatternInterface.java @@ -0,0 +1,157 @@ +package com.github.vfyjxf.nee.container; + +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; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; +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 static appeng.container.slot.SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN; + +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) { + + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/container/WCTContainerCraftingConfirm.java b/src/main/java/com/github/vfyjxf/nee/container/WCTContainerCraftingConfirm.java new file mode 100644 index 0000000..1761fd7 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/container/WCTContainerCraftingConfirm.java @@ -0,0 +1,42 @@ +package com.github.vfyjxf.nee.container; + +import appeng.api.storage.ITerminalHost; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm; + +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() { + super.startJob(); + hasWorkCommitted = true; + } + + @Override + public void onContainerClosed(EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + if (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; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java index cb01e49..846a941 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHandler.java @@ -27,7 +27,7 @@ import java.util.*; */ public class NEECraftingHandler implements IOverlayHandler { - public static final String INPUT_KEY = "input"; + public static final String INPUT_KEY = "#"; public static final String OUTPUT_KEY = "Outputs"; public static Map ingredients = new HashMap<>(); diff --git a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java index c2319f0..482de77 100644 --- a/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java +++ b/src/main/java/com/github/vfyjxf/nee/nei/NEECraftingHelper.java @@ -22,8 +22,11 @@ import com.github.vfyjxf.nee.config.NEEConfig; import com.github.vfyjxf.nee.network.NEENetworkHandler; import com.github.vfyjxf.nee.network.packet.PacketCraftingRequest; import com.github.vfyjxf.nee.network.packet.PacketOpenCraftAmount; +import com.github.vfyjxf.nee.network.packet.PacketSetRecipe; +import com.github.vfyjxf.nee.network.packet.PacketValueConfigServer; import com.github.vfyjxf.nee.utils.GuiUtils; import com.github.vfyjxf.nee.utils.IngredientTracker; +import com.github.vfyjxf.nee.utils.ItemUtils; import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.ReflectionHelper; @@ -49,6 +52,9 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import static com.github.vfyjxf.nee.nei.NEECraftingHandler.INPUT_KEY; +import static com.github.vfyjxf.nee.nei.NEECraftingHandler.OUTPUT_KEY; + public class NEECraftingHelper implements IOverlayHandler { public static final NEECraftingHelper INSTANCE = new NEECraftingHelper(); @@ -56,35 +62,82 @@ public class NEECraftingHelper implements IOverlayHandler { public static int stackIndex = 1; 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) { - boolean isCraftingGuiTerm = firstGui instanceof GuiCraftingTerm || GuiUtils.isGuiWirelessCrafting(firstGui); - if (isCraftingGuiTerm && NEECraftingHandler.isCraftingTableRecipe(recipe)) { - tracker = new IngredientTracker(firstGui, recipe, recipeIndex); + if (GuiUtils.isCraftingTerm(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 (noPreview) { + + if (isPatternInterfaceExists) { +// NEENetworkHandler.getInstance().sendToServer(new PacketSetRecipe(packCraftingRecipe(recipe, recipeIndex))); + NEENetworkHandler.getInstance().sendToServer(new PacketOpenCraftAmount(packCraftingRecipe(recipe,recipeIndex))); + isPatternInterfaceExists = false; + + } else { + tracker = new IngredientTracker(firstGui, recipe, recipeIndex); if (!tracker.getRequireStacks().isEmpty()) { IAEItemStack stack = AEItemStack.create(tracker.getRequiredStack(0)); NEENetworkHandler.getInstance().sendToServer(new PacketCraftingRequest(stack, noPreview)); + stackIndex = 1; } else { - moveItem(firstGui, recipe, recipeIndex); + moveItems(firstGui, recipe, recipeIndex); } - } else if (NEEConfig.enableCraftAmountSettingGui) { - NEENetworkHandler.getInstance().sendToServer(new PacketOpenCraftAmount(recipe.getResultStack(recipeIndex).item)); + } - stackIndex = 1; + } else { - moveItem(firstGui, recipe, recipeIndex); + moveItems(firstGui, recipe, recipeIndex); } } } + private NBTTagCompound packCraftingRecipe(IRecipeHandler recipeHandler, int recipeIndex) { + final NBTTagCompound recipe = new NBTTagCompound(); + final List 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(); + } + } + + //Fix ItemStack with wrong meta + if (stack.getItemDamage() == 32767) { + 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 moveItem(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { + private void moveItems(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { try { final List ingredients = recipe.getIngredientStacks(recipeIndex); if (firstGui instanceof GuiCraftingTerm) { @@ -241,4 +294,18 @@ public class NEECraftingHelper implements IOverlayHandler { } } + @SubscribeEvent + public void onInitGui(GuiScreenEvent.InitGuiEvent.Post event) { + if (event.gui instanceof GuiRecipe) { + GuiRecipe guiRecipe = (GuiRecipe) event.gui; + GuiContainer firstGui = guiRecipe.firstGui; + if (GuiUtils.isCraftingTerm(firstGui)) { + NEENetworkHandler.getInstance().sendToServer(new PacketValueConfigServer("PatternInterface.check")); + } + } + } + + public static void setIsPatternInterfaceExists(boolean isPatternInterfaceExists) { + NEECraftingHelper.isPatternInterfaceExists = isPatternInterfaceExists; + } } diff --git a/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEEGuiHandler.java similarity index 69% rename from src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java rename to src/main/java/com/github/vfyjxf/nee/network/NEEGuiHandler.java index 394364f..32a936c 100644 --- a/src/main/java/com/github/vfyjxf/nee/gui/NEEGuiHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/network/NEEGuiHandler.java @@ -1,4 +1,4 @@ -package com.github.vfyjxf.nee.gui; +package com.github.vfyjxf.nee.network; import appeng.api.AEApi; import appeng.api.implementations.guiobjects.IPortableCell; @@ -7,9 +7,15 @@ import appeng.api.parts.IPartHost; import appeng.api.storage.ITerminalHost; import appeng.container.AEBaseContainer; import appeng.container.ContainerOpenContext; -import appeng.container.implementations.ContainerCraftConfirm; import appeng.parts.reporting.PartCraftingTerminal; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; +import com.github.vfyjxf.nee.client.gui.GuiCraftingAmount; +import com.github.vfyjxf.nee.client.gui.GuiCraftingConfirm; +import com.github.vfyjxf.nee.client.gui.GuiPatternInterface; import com.github.vfyjxf.nee.container.ContainerCraftingAmount; +import com.github.vfyjxf.nee.container.ContainerCraftingConfirm; +import com.github.vfyjxf.nee.container.ContainerPatternInterface; +import com.github.vfyjxf.nee.container.WCTContainerCraftingConfirm; import com.github.vfyjxf.nee.utils.ModIDs; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Optional; @@ -19,6 +25,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.p455w0rd.wirelesscraftingterminal.api.IWirelessCraftingTermHandler; +import net.p455w0rd.wirelesscraftingterminal.client.gui.GuiCraftConfirm; +import net.p455w0rd.wirelesscraftingterminal.common.container.ContainerCraftConfirm; import net.p455w0rd.wirelesscraftingterminal.common.utils.RandomUtils; import net.p455w0rd.wirelesscraftingterminal.helpers.WirelessTerminalGuiObject; @@ -30,16 +38,18 @@ 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 CRAFTING_AMOUNT_WIRELESS_ID = 2; + 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) { + 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) { - TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof IPartHost) { IPartHost partHost = (IPartHost) tile; IPart part = partHost.getPart(side); @@ -51,7 +61,7 @@ public class NEEGuiHandler implements IGuiHandler { return null; case CRAFTING_CONFIRM_ID: if (part instanceof PartCraftingTerminal) { - return updateGui(new ContainerCraftConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); + return updateGui(new ContainerCraftingConfirm(player.inventory, (ITerminalHost) part), world, x, y, z, side, part); } return null; @@ -59,12 +69,29 @@ public class NEEGuiHandler implements IGuiHandler { 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) { - return new ContainerCraftingAmount(player.inventory, wirelessTerminal); + if (guiId == CRAFTING_AMOUNT_WIRELESS_ID) { + return new ContainerCraftingAmount(player.inventory, wirelessTerminal); + } else { + return new WCTContainerCraftingConfirm(player.inventory, wirelessTerminal); + } + + } else { + return null; } + } return null; } @@ -73,10 +100,10 @@ public class NEEGuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ordinal, EntityPlayer player, World world, int x, int y, int z) { final int guiId = ordinal >> 4; - if (guiId != CRAFTING_AMOUNT_WIRELESS_ID) { + 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) { - TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof IPartHost) { IPartHost partHost = (IPartHost) tile; IPart part = partHost.getPart(side); @@ -97,11 +124,28 @@ public class NEEGuiHandler implements IGuiHandler { } } + } 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) { - return new GuiCraftingAmount(player.inventory, wirelessTerminal); + if (guiId == CRAFTING_AMOUNT_WIRELESS_ID) { + return new GuiCraftingAmount(player.inventory, wirelessTerminal); + } else { + return new GuiCraftConfirm(player.inventory, wirelessTerminal); + } + + } else { + return null; } } return null; diff --git a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java index a835207..8eee463 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java +++ b/src/main/java/com/github/vfyjxf/nee/network/NEENetworkHandler.java @@ -27,6 +27,9 @@ public class NEENetworkHandler { INSTANCE.registerMessage(PacketCraftingRequest.class, PacketCraftingRequest.class, nextId(), Side.SERVER); INSTANCE.registerMessage(PacketOpenCraftAmount.class, PacketOpenCraftAmount.class, nextId(), Side.SERVER); INSTANCE.registerMessage(PacketOpenGui.class, PacketOpenGui.class, nextId(), Side.SERVER); + INSTANCE.registerMessage(PacketSetRecipe.class, PacketSetRecipe.class, nextId(), Side.SERVER); + INSTANCE.registerMessage(PacketValueConfigServer.class, PacketValueConfigServer.class, nextId(), Side.SERVER); + INSTANCE.registerMessage(PacketValueConfigClient.class, PacketValueConfigClient.class, nextId(), Side.CLIENT); } } \ No newline at end of file diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingRequest.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingRequest.java index bda9058..3794222 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingRequest.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketCraftingRequest.java @@ -1,13 +1,19 @@ package com.github.vfyjxf.nee.network.packet; +import appeng.api.AEApi; +import appeng.api.config.SecurityPermissions; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; import appeng.api.networking.IGridNode; import appeng.api.networking.crafting.ICraftingGrid; import appeng.api.networking.crafting.ICraftingJob; -import appeng.api.networking.security.IActionHost; +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; @@ -15,54 +21,69 @@ import appeng.core.AELog; import appeng.core.sync.GuiBridge; import appeng.util.Platform; import appeng.util.item.AEItemStack; +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 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; import io.netty.buffer.ByteBuf; +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 java.io.IOException; import java.util.concurrent.Future; +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; + public class PacketCraftingRequest implements IMessage, IMessageHandler { private IAEItemStack requireToCraftStack; - private boolean noPreview; + private boolean isAutoStart; private int craftAmount; public PacketCraftingRequest() { } - public PacketCraftingRequest(IAEItemStack requireToCraftStack, boolean noPreview) { + public PacketCraftingRequest(IAEItemStack requireToCraftStack, boolean isAutoStart) { this.requireToCraftStack = requireToCraftStack; - this.noPreview = noPreview; + this.isAutoStart = isAutoStart; } - public PacketCraftingRequest(int craftAmount, boolean noPreview) { + public PacketCraftingRequest(int craftAmount, boolean isAutoStart) { this.craftAmount = craftAmount; - this.noPreview = noPreview; + this.isAutoStart = isAutoStart; } public IAEItemStack getRequireToCraftStack() { return requireToCraftStack; } - public boolean isNoPreview() { - return noPreview; + public boolean isAutoStart() { + return isAutoStart; } @@ -79,7 +100,7 @@ public class PacketCraftingRequest implements IMessage, IMessageHandler futureJob = null; + try { + final ICraftingGrid cg = grid.getCache(ICraftingGrid.class); + futureJob = cg.beginCraftingJob(player.worldObj, grid, container.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); + if (player.openContainer instanceof ContainerCraftConfirm) { + final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer; + ccc.setJob(futureJob); + 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 pair = setRecipe(grid, container.getRecipe(), player); + if (pair != null) { + final IStorageGrid inv = grid.getCache(IStorageGrid.class); + final IMEMonitor storage = inv.getItemInventory(); + final IItemList 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 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.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.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 futureJob = null; try { final ICraftingGrid cg = grid.getCache(ICraftingGrid.class); futureJob = cg.beginCraftingJob(player.worldObj, grid, container.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); - if (player.openContainer instanceof ContainerCraftConfirm) { - final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer; - ccc.setJob(futureJob); - ccc.setAutoStart(message.isNoPreview()); - } + 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.setJob(futureJob); + ccc.setAutoStart(message.isAutoStart()); } } catch (final Throwable e) { if (futureJob != null) { @@ -154,81 +279,81 @@ public class PacketCraftingRequest implements IMessage, IMessageHandler 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(); - Platform.openGUI(player, te, context.getSide(), GuiBridge.GUI_CRAFTING_CONFIRM); - if (player.openContainer instanceof ContainerCraftConfirm) { - final ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer; - ccc.setAutoStart(message.isNoPreview()); - ccc.setJob(futureJob); - ccc.detectAndSendChanges(); + private Pair 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); } - } else if (Loader.isModLoaded(ModIDs.WCT)) { - 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.setJob(futureJob); - ccc.setAutoStart(message.isNoPreview()); - } - } - } catch (final Throwable e) { - if (futureJob != null) { - futureJob.cancel(true); - } - AELog.debug(e); } + } } + return null; } - 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 && message.getRequireToCraftStack() != null) { - Future futureJob = null; - try { - final ICraftingGrid cg = grid.getCache(ICraftingGrid.class); - futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), message.getRequireToCraftStack(), 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]); + } - 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.setJob(futureJob); - ccc.setAutoStart(message.isNoPreview()); - } - } catch (final Throwable e) { - if (futureJob != null) { - futureJob.cancel(true); - } - AELog.debug(e); + ItemStack result = CraftingManager.getInstance().findMatchingRecipe(ic, player.worldObj); + if (result != null) { + ItemStack patternStack = null; + Optional 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; } } diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketOpenCraftAmount.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketOpenCraftAmount.java index bfd1a6c..c161d89 100644 --- a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketOpenCraftAmount.java +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketOpenCraftAmount.java @@ -3,7 +3,7 @@ package com.github.vfyjxf.nee.network.packet; import appeng.container.ContainerOpenContext; import appeng.container.implementations.ContainerCraftingTerm; import com.github.vfyjxf.nee.container.ContainerCraftingAmount; -import com.github.vfyjxf.nee.gui.NEEGuiHandler; +import com.github.vfyjxf.nee.network.NEEGuiHandler; import com.github.vfyjxf.nee.utils.GuiUtils; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; @@ -13,31 +13,33 @@ import io.netty.buffer.ByteBuf; 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 static com.github.vfyjxf.nee.gui.NEEGuiHandler.CRAFTING_AMOUNT_ID; -import static com.github.vfyjxf.nee.gui.NEEGuiHandler.CRAFTING_AMOUNT_WIRELESS_ID; +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; public class PacketOpenCraftAmount implements IMessage, IMessageHandler { - private ItemStack resultStack; + private NBTTagCompound recipe; public PacketOpenCraftAmount() { } - public PacketOpenCraftAmount(ItemStack resultStack) { - this.resultStack = resultStack; + public PacketOpenCraftAmount(NBTTagCompound recipe) { + this.recipe = recipe; } @Override public void fromBytes(ByteBuf buf) { - this.resultStack = ByteBufUtils.readItemStack(buf); + this.recipe = ByteBufUtils.readTag(buf); } @Override public void toBytes(ByteBuf buf) { - ByteBufUtils.writeItemStack(buf, this.resultStack); + ByteBufUtils.writeTag(buf, this.recipe); } @Override @@ -53,9 +55,14 @@ public class PacketOpenCraftAmount implements IMessage, IMessageHandler { + + 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); + } + + @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 = 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 = 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 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; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigClient.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigClient.java new file mode 100644 index 0000000..1fb4bd1 --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigClient.java @@ -0,0 +1,60 @@ +package com.github.vfyjxf.nee.network.packet; + +import codechicken.nei.recipe.GuiRecipe; +import com.github.vfyjxf.nee.nei.NEECraftingHelper; +import com.github.vfyjxf.nee.utils.GuiUtils; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiScreen; + +public class PacketValueConfigClient implements IMessage, IMessageHandler { + + + 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); + } + + @Override + public IMessage onMessage(PacketValueConfigClient message, MessageContext ctx) { + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if ("PatternInterface.check".equals(message.name) && Boolean.parseBoolean(message.value)) { + if (gui instanceof GuiRecipe) { + GuiRecipe guiRecipe = (GuiRecipe) gui; + if (GuiUtils.isCraftingTerm(guiRecipe.firstGui)) { + NEECraftingHelper.setIsPatternInterfaceExists(true); + } + } + } + return null; + } +} diff --git a/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigServer.java b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigServer.java new file mode 100644 index 0000000..87e304d --- /dev/null +++ b/src/main/java/com/github/vfyjxf/nee/network/packet/PacketValueConfigServer.java @@ -0,0 +1,103 @@ +package com.github.vfyjxf.nee.network.packet; + +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 com.github.vfyjxf.nee.block.tile.TilePatternInterface; +import com.github.vfyjxf.nee.container.ContainerPatternInterface; +import com.github.vfyjxf.nee.network.NEENetworkHandler; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; + +public class PacketValueConfigServer implements IMessage, IMessageHandler { + + 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); + } + + @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) { + AEBaseContainer abc = (AEBaseContainer) container; + IGrid grid = getNetwork(abc); + 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; + } + + } + + } + } + } + + 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; + } + +} diff --git a/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java b/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java index 2d205e8..dc63a33 100644 --- a/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java +++ b/src/main/java/com/github/vfyjxf/nee/proxy/CommonProxy.java @@ -1,9 +1,38 @@ package com.github.vfyjxf.nee.proxy; +import appeng.core.features.ActivityState; +import appeng.core.features.BlockStackSrc; +import appeng.tile.AEBaseTile; +import com.github.vfyjxf.nee.NotEnoughEnergistics; +import com.github.vfyjxf.nee.block.BlockPatternInterface; +import com.github.vfyjxf.nee.block.tile.TilePatternInterface; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; -public abstract class CommonProxy { +public class CommonProxy { - public abstract void init(FMLInitializationEvent event); + public void init(FMLInitializationEvent event) { + AEBaseTile.registerTileItem(TilePatternInterface.class, + new BlockStackSrc(BlockPatternInterface.BLOCK_INSTANCE, 0, ActivityState.Enabled)); + } + + public void preInit(FMLPreInitializationEvent event){ + registerBlocks(); + registerItems(); + registerTileEntities(); + } + + public void registerItems() { + GameRegistry.registerItem(BlockPatternInterface.ITEM_INSTANCE, "tile.pattern_interface"); + } + + public void registerBlocks() { + GameRegistry.registerBlock(BlockPatternInterface.BLOCK_INSTANCE, null,"tile.pattern_interface"); + } + + public void registerTileEntities() { + GameRegistry.registerTileEntity(TilePatternInterface.class, NotEnoughEnergistics.MODID + "." + "tile.pattern_interface"); + } } diff --git a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java index b1366c8..6c4e0ee 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/GuiUtils.java @@ -1,5 +1,7 @@ package com.github.vfyjxf.nee.utils; +import appeng.client.gui.implementations.GuiCraftingTerm; +import appeng.client.gui.implementations.GuiPatternTerm; import appeng.container.implementations.ContainerPatternTerm; import appeng.helpers.IContainerCraftingPacket; import net.minecraft.client.Minecraft; @@ -101,4 +103,12 @@ public class GuiUtils { } } + public static boolean isCraftingTerm(GuiScreen guiScreen) { + return guiScreen instanceof GuiCraftingTerm || isGuiWirelessCrafting(guiScreen); + } + + public static boolean isPatternTerm(GuiScreen guiScreen) { + return guiScreen instanceof GuiPatternTerm || isPatternTermExGui(guiScreen); + } + } diff --git a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java index 3d70e62..ae064dc 100644 --- a/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java +++ b/src/main/java/com/github/vfyjxf/nee/utils/IngredientTracker.java @@ -130,45 +130,22 @@ public class IngredientTracker { public List getRequireToCraftStacks() { List requireToCraftStacks = new ArrayList<>(); - if (NEEConfig.enableCraftAmountSettingGui) { - for (Ingredient ingredient : this.getIngredients()) { - boolean find = false; - if (ingredient.isCraftable()) { - for (ItemStack stack : requireToCraftStacks) { - boolean areStackEqual = stack.isItemEqual(ingredient.getCraftableIngredient()) && ItemStack.areItemStackTagsEqual(stack, ingredient.getCraftableIngredient()); - if (areStackEqual) { - stack.stackSize += ingredient.getRequireCount(); - find = true; - break; - } - + for (Ingredient ingredient : this.getIngredients()) { + boolean find = false; + if (ingredient.isCraftable() && ingredient.requiresToCraft()) { + for (ItemStack stack : requireToCraftStacks) { + boolean areStackEqual = stack.isItemEqual(ingredient.getCraftableIngredient()) && ItemStack.areItemStackTagsEqual(stack, ingredient.getCraftableIngredient()); + if (areStackEqual) { + stack.stackSize = (int) (stack.stackSize + ingredient.getMissingCount()); + find = true; } - if (!find) { - ItemStack requireStack = ingredient.getCraftableIngredient().copy(); - requireStack.stackSize = ((int) ingredient.getRequireCount()); - requireToCraftStacks.add(requireStack); - } } - } - } else { - for (Ingredient ingredient : this.getIngredients()) { - boolean find = false; - if (ingredient.isCraftable() && ingredient.requiresToCraft()) { - for (ItemStack stack : requireToCraftStacks) { - boolean areStackEqual = stack.isItemEqual(ingredient.getCraftableIngredient()) && ItemStack.areItemStackTagsEqual(stack, ingredient.getCraftableIngredient()); - if (areStackEqual) { - stack.stackSize = (int) (stack.stackSize + ingredient.getMissingCount()); - find = true; - } - } - - if (!find) { - ItemStack requireStack = ingredient.getCraftableIngredient().copy(); - requireStack.stackSize = ((int) ingredient.getMissingCount()); - requireToCraftStacks.add(requireStack); - } + if (!find) { + ItemStack requireStack = ingredient.getCraftableIngredient().copy(); + requireStack.stackSize = ((int) ingredient.getMissingCount()); + requireToCraftStacks.add(requireStack); } } } diff --git a/src/main/resources/META-INF/neenergistics_at.cfg b/src/main/resources/META-INF/neenergistics_at.cfg index 01fb0e2..258fbb8 100644 --- a/src/main/resources/META-INF/neenergistics_at.cfg +++ b/src/main/resources/META-INF/neenergistics_at.cfg @@ -2,4 +2,5 @@ public net.minecraft.client.gui.inventory.GuiContainer field_147003_i #guiLeft public net.minecraft.client.gui.inventory.GuiContainer field_147009_r #guiTop public net.minecraft.client.gui.inventory.GuiContainer field_147000_g #ySize public net.minecraft.client.gui.inventory.GuiContainer func_146975_c(II)Lnet/minecraft/inventory/Slot; #getSlotAtPositionv -public net.minecraft.client.gui.GuiScreen func_146283_a(Ljava/util/List;II)V #drawHoveringText \ No newline at end of file +public net.minecraft.client.gui.GuiScreen func_146283_a(Ljava/util/List;II)V #drawHoveringText +public net.minecraft.client.gui.inventory.GuiContainer field_147006_u # theSlot \ No newline at end of file diff --git a/src/main/resources/assets/neenergistics/lang/en_US.lang b/src/main/resources/assets/neenergistics/lang/en_US.lang index 75bfdb1..655418d 100644 --- a/src/main/resources/assets/neenergistics/lang/en_US.lang +++ b/src/main/resources/assets/neenergistics/lang/en_US.lang @@ -13,3 +13,7 @@ gui.neenergistics.button.tooltip.combination=Current Mode: %s gui.neenergistics.button.name.enabled=Enabled gui.neenergistics.button.name.disabled=Disabled 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 diff --git a/src/main/resources/assets/neenergistics/lang/zh_CN.lang b/src/main/resources/assets/neenergistics/lang/zh_CN.lang index 210dbed..6d758d0 100644 --- a/src/main/resources/assets/neenergistics/lang/zh_CN.lang +++ b/src/main/resources/assets/neenergistics/lang/zh_CN.lang @@ -13,3 +13,7 @@ gui.neenergistics.button.tooltip.combination=当前模式: %s gui.neenergistics.button.name.enabled=开启 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=样板接口 diff --git a/src/main/resources/assets/neenergistics/models/item/patterncrafter.json b/src/main/resources/assets/neenergistics/models/item/patterncrafter.json new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/assets/neenergistics/textures/blocks/pattern_interface.png b/src/main/resources/assets/neenergistics/textures/blocks/pattern_interface.png new file mode 100644 index 0000000..c0b37c0 Binary files /dev/null and b/src/main/resources/assets/neenergistics/textures/blocks/pattern_interface.png differ diff --git a/src/main/resources/assets/neenergistics/textures/gui/pattern_interface.png b/src/main/resources/assets/neenergistics/textures/gui/pattern_interface.png new file mode 100644 index 0000000..c6d10db Binary files /dev/null and b/src/main/resources/assets/neenergistics/textures/gui/pattern_interface.png differ diff --git a/src/main/resources/assets/neenergistics/textures/gui/states.png b/src/main/resources/assets/neenergistics/textures/gui/states.png index 9cc7e14..355481a 100644 Binary files a/src/main/resources/assets/neenergistics/textures/gui/states.png and b/src/main/resources/assets/neenergistics/textures/gui/states.png differ