Add a ME interface for storing temporary patterns.

This commit is contained in:
vfyjxf committed 2022-02-05 22:49:24 +08:00
1 parent a983a36e2f
commit a71ef8c51a
40 files changed
+1956 -309

No files matched your search

-3
View File
@@ -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}
+1 -1
View File
@@ -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
Binary file not shown.
Binary file not shown.
@@ -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());
}
}
@@ -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<Integer> 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() &&
@@ -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;
}
}
@@ -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<ICraftingPatternDetails> craftingList;
private List<ItemStack> waitingToSend;
private final MachineSource source;
private final WrapperInvSlot slotInv;
private final boolean[] workStarted = new boolean[9];
public TilePatternInterface() {
this.gridInv = new AppEngInternalInventory(this, 9 + 1, 1);
this.patterns = new AppEngInternalInventory(this, 9);
this.ejectInv = new AppEngInternalInventory(this, 9);
this.craftingList = new ArrayList<>();
this.source = new MachineSource(this);
this.slotInv = new WrapperInvSlot(this.ejectInv);
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
this.getProxy().setIdlePowerUsage(30D);
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkChannelsChanged c) {
this.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange c) {
this.notifyNeighbors();
}
private void notifyNeighbors() {
if (this.getProxy().isActive()) {
try {
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (GridAccessException e) {
// :P
}
Platform.notifyBlocksOfNeighbors(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord);
}
}
@Nonnull
@Override
public TickingRequest getTickingRequest(@Nonnull IGridNode node) {
return new TickingRequest(TickRates.Interface.getMin(), TickRates.Interface.getMax(), !hasItemToSend(), true);
}
@Nonnull
@Override
public TickRateModulation tickingRequest(@Nonnull IGridNode node, int ticksSinceLastCall) {
if (!this.getProxy().isActive()) {
return TickRateModulation.SLEEP;
}
if (hasItemToSend()) {
ejectItems();
}
if (this.hasItemsToPush()) {
this.pushItemsOut(EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN)));
}
if (hasWorkFinished()) {
updateWorks();
}
if (hasWorks()) {
return TickRateModulation.URGENT;
}
return TickRateModulation.SLEEP;
}
@Nonnull
@Override
public IInventory getInternalInventory() {
return this.ejectInv;
}
@Override
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added) {
if (inv == this.ejectInv || inv == patterns) {
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException e) {
// :P
}
}
}
@Override
public void onReady() {
super.onReady();
this.updateCraftingList();
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide) {
return this.sides;
}
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker) {
if (this.getProxy().isActive()) {
if (this.craftingList.isEmpty()) {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails pattern = ((ICraftingPatternItem) stack.getItem()).getPatternForItem(stack, worldObj);
if (pattern != null && pattern.isCraftable()) {
craftingList.add(pattern);
}
}
}
}
for (ICraftingPatternDetails details : this.craftingList) {
craftingTracker.addCraftingOption(this, details);
}
}
}
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table) {
if (!isBusy() && this.getProxy().isActive() && craftingList.contains(patternDetails) && !this.hasItemsToPush()) {
final EnumSet<ForgeDirection> possibleDirections = EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN));
for (final ForgeDirection direction : possibleDirections) {
final TileEntity te = worldObj.getTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
if (te instanceof IInterfaceHost) {
try {
if (this.sameGrid(getGridFromInterface(((IInterfaceHost) te).getInterfaceDuality()))) {
continue;
}
} catch (final GridAccessException e) {
continue;
}
}
if (te instanceof ICraftingMachine) {
final ICraftingMachine cm = (ICraftingMachine) te;
if (cm.acceptsPlans()) {
if (cm.pushPattern(patternDetails, table, direction.getOpposite())) {
setWorkStart(patternDetails);
return true;
}
continue;
}
}
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor(te, direction.getOpposite());
if (ad != null) {
if (this.acceptsItems(ad, table)) {
for (int x = 0; x < table.getSizeInventory(); x++) {
final ItemStack is = table.getStackInSlot(x);
if (is != null) {
final ItemStack added = ad.addItems(is);
this.addToSendList(added);
}
}
this.pushItemsOut(possibleDirections);
setWorkStart(patternDetails);
return true;
}
}
}
}
return false;
}
@Override
public boolean isBusy() {
return hasItemsToPush();
}
@Override
public void getDrops(final World w, final int x, final int y, final int z, final List<ItemStack> drops) {
if (hasItemsToPush()) {
for (ItemStack stack : waitingToSend) {
if (stack != null) {
drops.add(stack);
}
}
}
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
ItemStack stack = ejectInv.getStackInSlot(i);
if (stack != null) {
drops.add(stack);
}
}
}
public AppEngInternalInventory getGirdInventory() {
return gridInv;
}
public AppEngInternalInventory getPatternInventory() {
return patterns;
}
@Override
public DimensionalCoord getLocation() {
return new DimensionalCoord(this);
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir) {
return AECableType.SMART;
}
@Override
public boolean canInsert(ItemStack stack) {
if (stack == null || stack.getItem() == null) {
return false;
}
try {
final IAEItemStack out = this.getProxy().getStorage().getItemInventory().injectItems(AEApi.instance().storage().createItemStack(stack), Actionable.SIMULATE, this.source);
if (out == null) {
return true;
}
return out.getStackSize() != stack.stackSize;
} catch (GridAccessException e) {
return false;
}
}
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public NBTTagCompound writeToNBT_TilePatternInterface(NBTTagCompound data) {
this.patterns.writeToNBT(data, "patterns");
this.ejectInv.writeToNBT(data, "ejectInv");
final NBTTagList waitingToSend = new NBTTagList();
if (this.waitingToSend != null) {
for (final ItemStack is : this.waitingToSend) {
final NBTTagCompound item = new NBTTagCompound();
is.writeToNBT(item);
waitingToSend.appendTag(item);
}
}
data.setTag("waitingToSend", waitingToSend);
return data;
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBT_TilePatternInterface(NBTTagCompound data) {
this.waitingToSend = null;
final NBTTagList waitingList = data.getTagList("waitingToSend", 10);
if (waitingList != null) {
for (int x = 0; x < waitingList.tagCount(); x++) {
final NBTTagCompound c = waitingList.getCompoundTagAt(x);
if (c != null) {
final ItemStack is = ItemStack.loadItemStackFromNBT(c);
this.addToSendList(is);
}
}
}
this.patterns.readFromNBT(data, "patterns");
this.ejectInv.readFromNBT(data, "ejectInv");
this.updateCraftingList();
}
private boolean hasItemsToPush() {
return this.waitingToSend != null && !this.waitingToSend.isEmpty();
}
public boolean canPutPattern(ItemStack result) {
if (result == null) {
return false;
}
for (int i = 0; i < this.patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails pattern = ((ICraftingPatternItem) stack.getItem()).getPatternForItem(stack, worldObj);
if (result.isItemEqual(pattern.getOutputs()[0].getItemStack())) {
return false;
}
}
}
return IntStream.range(0, this.patterns.getSizeInventory()).anyMatch(slot -> patterns.getStackInSlot(slot) == null);
}
public int putPattern(ItemStack pattern) {
for (int i = 0; i < this.patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack == null) {
patterns.setInventorySlotContents(i, pattern);
updateCraftingList();
return i;
}
}
return -1;
}
public void updateCraftingList() {
final Boolean[] accountedFor = {false, false, false, false, false, false, false, false, false};
assert (accountedFor.length == this.patterns.getSizeInventory());
if (!this.getProxy().isReady()) {
return;
}
if (this.craftingList != null) {
final Iterator<ICraftingPatternDetails> i = this.craftingList.iterator();
while (i.hasNext()) {
final ICraftingPatternDetails details = i.next();
boolean found = false;
for (int x = 0; x < accountedFor.length; x++) {
final ItemStack is = this.patterns.getStackInSlot(x);
if (details.getPattern() == is) {
accountedFor[x] = found = true;
}
}
if (!found) {
i.remove();
}
}
}
for (int x = 0; x < accountedFor.length; x++) {
if (!accountedFor[x]) {
this.addToCraftingList(this.patterns.getStackInSlot(x));
}
}
try {
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
} catch (final GridAccessException e) {
// :P
}
}
public void cancelWork(int recipeIndex) {
IAEItemStack result = getResultStack(recipeIndex);
if (result != null) {
workStarted[recipeIndex] = false;
try {
final ICraftingGrid cg = this.getProxy().getCrafting();
final ImmutableSet<ICraftingCPU> cpuSet = cg.getCpus();
for (ICraftingCPU cpu : cpuSet) {
if (cpu instanceof CraftingCPUCluster) {
CraftingCPUCluster cluster = (CraftingCPUCluster) cpu;
final IItemList<IAEItemStack> pendingList = AEApi.instance().storage().createItemList();
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
for (IAEItemStack pendingStack : pendingList) {
if (pendingStack.isSameType(result)) {
cluster.cancel();
break;
}
}
}
}
} catch (GridAccessException e) {
e.printStackTrace();
}
}
}
private void addToCraftingList(final ItemStack is) {
if (is == null) {
return;
}
if (is.getItem() instanceof ICraftingPatternItem) {
final ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem();
final ICraftingPatternDetails details = cpi.getPatternForItem(is, worldObj);
if (details != null) {
if (this.craftingList == null) {
this.craftingList = new LinkedList<>();
}
this.craftingList.add(details);
}
}
}
private void addToSendList(final ItemStack is) {
if (is == null) {
return;
}
if (this.waitingToSend == null) {
this.waitingToSend = new LinkedList<>();
}
this.waitingToSend.add(is);
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
private boolean acceptsItems(final InventoryAdaptor ad, final InventoryCrafting table) {
for (int x = 0; x < table.getSizeInventory(); x++) {
final ItemStack is = table.getStackInSlot(x);
if (is == null) {
continue;
}
if (ad.simulateAdd(is.copy()) != null) {
return false;
}
}
return true;
}
private void pushItemsOut(final EnumSet<ForgeDirection> possibleDirections) {
if (!this.hasItemsToPush()) {
return;
}
final Iterator<ItemStack> i = this.waitingToSend.iterator();
while (i.hasNext()) {
ItemStack whatToSend = i.next();
for (final ForgeDirection s : possibleDirections) {
final TileEntity te = worldObj.getTileEntity(this.xCoord + s.offsetX, this.yCoord + s.offsetY, this.zCoord + s.offsetZ);
if (te == null) {
continue;
}
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor(te, s.getOpposite());
if (ad != null) {
final ItemStack Result = ad.addItems(whatToSend);
if (Result == null) {
whatToSend = null;
} else {
whatToSend.stackSize -= whatToSend.stackSize - Result.stackSize;
}
if (whatToSend == null) {
break;
}
}
}
if (whatToSend == null) {
i.remove();
}
}
if (this.waitingToSend.isEmpty()) {
this.waitingToSend = null;
}
}
private boolean hasItemToSend() {
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
ItemStack stack = ejectInv.getStackInSlot(i);
if (stack != null) {
return true;
}
}
return false;
}
private void ejectItems() {
for (int i = 0; i < ejectInv.getSizeInventory(); i++) {
if (ejectInv.getStackInSlot(i) != null) {
ItemStack stack = ejectInv.getStackInSlot(i);
int itemCount = stack.stackSize;
final InventoryAdaptor adaptor = getAdaptor(i);
final ItemStack canExtract = adaptor.simulateRemove(itemCount, stack, null);
if (canExtract != null && canExtract.stackSize == itemCount) {
try {
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getItemInventory();
final IEnergyGrid energy = this.getProxy().getEnergy();
final IAEItemStack aeStack = AEApi.instance().storage().createItemStack(stack);
if (aeStack != null) {
final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source);
if (failed != null) {
itemCount -= failed.getStackSize();
}
if (itemCount != 0) {
final ItemStack removed = adaptor.removeItems(itemCount, null, null);
if (removed == null) {
throw new IllegalStateException("bad attempt at managing inventory. ( removeItems )");
} else if (removed.stackSize != itemCount) {
throw new IllegalStateException("bad attempt at managing inventory. ( removeItems )");
}
}
}
} catch (GridAccessException e) {
// :P
}
}
}
}
}
private InventoryAdaptor getAdaptor(final int slot) {
return new AdaptorIInventory(this.slotInv.getWrapper(slot));
}
private boolean hasWorks() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
if (patterns.getStackInSlot(i) != null) {
return true;
}
}
return false;
}
private void setWorkStart(ICraftingPatternDetails pattern) {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem()).getPatternForItem(stack, worldObj);
if (currentPattern != null && currentPattern.equals(pattern)) {
workStarted[i] = true;
}
}
}
}
private boolean hasWorkFinished() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
ItemStack stack = patterns.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem()).getPatternForItem(stack, worldObj);
if (currentPattern != null) {
IAEItemStack what = currentPattern.getOutputs().length > 0 ? currentPattern.getOutputs()[0] : null;
if (isNotRequesting(what) && workStarted[i]) {
return true;
}
}
}
}
return false;
}
private void updateWorks() {
for (int i = 0; i < patterns.getSizeInventory(); i++) {
IAEItemStack what = getResultStack(i);
if (isNotRequesting(what) && workStarted[i]) {
patterns.setInventorySlotContents(i, null);
workStarted[i] = false;
updateCraftingList();
}
}
}
private boolean isNotRequesting(IAEItemStack stack) {
if (stack == null) {
return true;
}
try {
final ICraftingGrid cg = this.getProxy().getCrafting();
final ImmutableSet<ICraftingCPU> cpuSet = cg.getCpus();
final IItemList<IAEItemStack> pendingList = AEApi.instance().storage().createItemList();
for (ICraftingCPU cpu : cpuSet) {
if (cpu instanceof CraftingCPUCluster) {
CraftingCPUCluster cluster = (CraftingCPUCluster) cpu;
cluster.getListOfItem(pendingList, CraftingItemList.PENDING);
}
}
for (IAEItemStack pendingStack : pendingList) {
if (pendingStack.isSameType(stack)) {
return false;
}
}
} catch (GridAccessException e) {
e.printStackTrace();
}
return true;
}
private IAEItemStack getResultStack(int pattern) {
ItemStack stack = patterns.getStackInSlot(pattern);
if (stack != null && stack.getItem() instanceof ICraftingPatternItem) {
ICraftingPatternDetails currentPattern = ((ICraftingPatternItem) stack.getItem()).getPatternForItem(stack, worldObj);
if (currentPattern != null) {
return currentPattern.getOutputs().length > 0 ? currentPattern.getOutputs()[0] : null;
}
}
return null;
}
@Override
public void gridChanged() {
this.notifyNeighbors();
}
private boolean sameGrid(final IGrid grid) throws GridAccessException {
return grid == this.getProxy().getGrid();
}
private IGrid getGridFromInterface(DualityInterface iface) {
return ReflectionHelper.getPrivateValue(DualityInterface.class, iface, "gridProxy");
}
}
@@ -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<Integer> 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<Slot> getCraftingSlots(GuiContainer gui) {
List<Slot> craftingSlots = new ArrayList<>();
@@ -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<String> 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
@@ -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..
@@ -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;
@@ -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");
}
}
@@ -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);
@@ -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;
}
}
@@ -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();
}
{
@@ -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;
}
}
@@ -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;
}
}
@@ -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) {
}
}
@@ -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;
}
}
@@ -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<String, PositionedStack> ingredients = new HashMap<>();
@@ -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<PositionedStack> ingredients = recipeHandler.getIngredientStacks(recipeIndex);
for (final PositionedStack positionedStack : ingredients) {
final int col = (positionedStack.relx - 25) / 18;
final int row = (positionedStack.rely - 6) / 18;
int slotIndex = col + row * 3;
if (positionedStack.items != null && positionedStack.items.length > 0) {
final ItemStack[] currentStackList = positionedStack.items;
ItemStack stack = positionedStack.items[0];
ItemStack preferModItem = ItemUtils.getPreferModItem(positionedStack.items);
if (preferModItem != null) {
stack = preferModItem;
}
for (ItemStack currentStack : currentStackList) {
if (Platform.isRecipePrioritized(currentStack) || ItemUtils.isPreferItems(currentStack)) {
stack = currentStack.copy();
}
}
//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<PositionedStack> 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;
}
}
@@ -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;
@@ -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);
}
}
@@ -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<PacketCraftingRequest, IMessage> {
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<PacketCr
e.printStackTrace();
}
}
this.noPreview = buf.readBoolean();
this.isAutoStart = buf.readBoolean();
this.craftAmount = buf.readInt();
}
@@ -95,7 +116,7 @@ public class PacketCraftingRequest implements IMessage, IMessageHandler<PacketCr
} else {
buf.writeBoolean(false);
}
buf.writeBoolean(this.noPreview);
buf.writeBoolean(this.isAutoStart);
buf.writeInt(this.craftAmount);
}
@@ -107,12 +128,24 @@ public class PacketCraftingRequest implements IMessage, IMessageHandler<PacketCr
if (container instanceof AEBaseContainer) {
AEBaseContainer baseContainer = (AEBaseContainer) container;
Object target = baseContainer.getTarget();
if (container instanceof ContainerCraftingTerm) {
handlerCraftingTermRequest((ContainerCraftingTerm) container, message, target, player);
}
if (target instanceof IGridHost) {
final IGridHost gh = (IGridHost) target;
final IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
if (gn != null) {
final IGrid grid = gn.getGrid();
if (grid != null) {
final ISecurityGrid security = grid.getCache(ISecurityGrid.class);
if (security != null && security.hasPermission(player, SecurityPermissions.CRAFT)) {
if (container instanceof ContainerCraftingTerm) {
handlerCraftingTermRequest((ContainerCraftingTerm) container, message, grid, player);
}
if (container instanceof ContainerCraftingAmount) {
handlerCraftingAmountRequest((ContainerCraftingAmount) container, message, target, player);
if (container instanceof ContainerCraftingAmount) {
handlerCraftingAmountRequest((ContainerCraftingAmount) container, message, grid, player);
}
}
}
}
}
} else if (GuiUtils.isWirelessCraftingTermContainer(container)) {
handlerWirelessCraftingRequest((ContainerWirelessCraftingTerminal) container, message, player);
@@ -121,27 +154,119 @@ public class PacketCraftingRequest implements IMessage, IMessageHandler<PacketCr
return null;
}
private void handlerCraftingTermRequest(ContainerCraftingTerm container, PacketCraftingRequest message, Object target, EntityPlayerMP player) {
if (target instanceof IGridHost) {
IGridHost gh = (IGridHost) target;
IGridNode gn = gh.getGridNode(ForgeDirection.UNKNOWN);
if (gn != null) {
IGrid grid = gn.getGrid();
if (grid != null && message.getRequireToCraftStack() != null) {
private void handlerCraftingTermRequest(ContainerCraftingTerm container, PacketCraftingRequest message, IGrid grid, EntityPlayerMP player) {
if (message.getRequireToCraftStack() != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), message.getRequireToCraftStack(), null);
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<TilePatternInterface, Integer> pair = setRecipe(grid, container.getRecipe(), player);
if (pair != null) {
final IStorageGrid inv = grid.getCache(IStorageGrid.class);
final IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
final IItemList<IAEItemStack> all = storage.getStorageList();
ItemStack resultStack = container.getResultStack().copy();
IAEItemStack result = null;
/*
*For some reason,the output from jei is different from the actual one,
*so apply ItemStack.isItemEqual to match.
*/
for (IAEItemStack aeStack : all) {
if (resultStack.isItemEqual(aeStack.getItemStack()) && aeStack.isCraftable()) {
result = aeStack.copy();
break;
}
}
if (result != null) {
result.setStackSize(message.getCraftAmount());
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), result, null);
final ContainerOpenContext context = container.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
NEEGuiHandler.openGui(player, NEEGuiHandler.CRAFTING_CONFIRM_ID, te, context.getSide());
if (player.openContainer instanceof ContainerCraftingConfirm) {
final ContainerCraftingConfirm ccc = (ContainerCraftingConfirm) player.openContainer;
ccc.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<ICraftingJob> 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<PacketCr
}
}
private void handlerCraftingAmountRequest(ContainerCraftingAmount container, PacketCraftingRequest message, Object target, EntityPlayerMP player) {
if (target instanceof IActionHost) {
IActionHost ah = (IActionHost) target;
IGridNode gn = ah.getActionableNode();
IGrid grid = gn.getGrid();
ItemStack resultStack = container.getResultStack();
IAEItemStack result = message.getRequireToCraftStack();
if (resultStack != null) {
Future<ICraftingJob> futureJob = null;
try {
final ICraftingGrid cg = grid.getCache(ICraftingGrid.class);
futureJob = cg.beginCraftingJob(player.worldObj, grid, container.getActionSource(), result, null);
final ContainerOpenContext context = container.getOpenContext();
if (context != null) {
final TileEntity te = context.getTile();
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<TilePatternInterface, Integer> setRecipe(IGrid grid, NBTTagCompound recipe, EntityPlayer player) {
for (IGridNode gridNode : grid.getMachines(TilePatternInterface.class)) {
if (gridNode.getMachine() instanceof TilePatternInterface) {
TilePatternInterface tpi = (TilePatternInterface) gridNode.getMachine();
NBTTagCompound currentTag = recipe.getCompoundTag(OUTPUT_KEY);
ItemStack result = currentTag == null ? null : ItemStack.loadItemStackFromNBT(currentTag);
if (tpi.getProxy().isActive() && tpi.canPutPattern(result)) {
ItemStack patternStack = getPatternStack(player, recipe);
if (patternStack != null) {
int patternIndex = tpi.putPattern(patternStack);
if (patternIndex >= 0) {
return Pair.of(tpi, patternIndex);
}
} 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<ICraftingJob> 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<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
patternStack = maybePattern.get();
}
if (patternStack != null) {
final NBTTagCompound patternValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
for (ItemStack stack : recipeInputs) {
tagIn.appendTag(crateItemTag(stack));
}
patternValue.setTag("in", tagIn);
patternValue.setTag("out", result.writeToNBT(new NBTTagCompound()));
patternValue.setBoolean("crafting", true);
patternValue.setBoolean("substitute", false);
patternStack.setTagCompound(patternValue);
return patternStack;
}
}
return null;
}
private NBTTagCompound crateItemTag(ItemStack itemStack) {
NBTTagCompound tag = new NBTTagCompound();
if (itemStack != null) {
itemStack.writeToNBT(tag);
}
return tag;
}
}
@@ -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<PacketOpenCraftAmount, IMessage> {
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<PacketOp
if (player.openContainer instanceof ContainerCraftingAmount) {
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
if (message.resultStack != null) {
cca.setResultStack(message.resultStack);
cca.getResultSlot().putStack(message.resultStack);
if (message.recipe != null) {
NBTTagCompound tag = message.recipe.getCompoundTag(OUTPUT_KEY);
ItemStack result = tag == null ? null : ItemStack.loadItemStackFromNBT(tag);
if (result != null) {
cca.setResultStack(result);
cca.getResultSlot().putStack(result);
cca.setRecipe(message.recipe);
}
}
cca.detectAndSendChanges();
}
@@ -66,9 +73,12 @@ public class PacketOpenCraftAmount implements IMessage, IMessageHandler<PacketOp
if (player.openContainer instanceof ContainerCraftingAmount) {
ContainerCraftingAmount cca = (ContainerCraftingAmount) player.openContainer;
if (message.resultStack != null) {
cca.setResultStack(message.resultStack);
cca.getResultSlot().putStack(message.resultStack);
if (message.recipe != null) {
NBTTagCompound tag = message.recipe.getCompoundTag(OUTPUT_KEY);
ItemStack result = tag == null ? null : ItemStack.loadItemStackFromNBT(tag);
cca.setResultStack(result);
cca.getResultSlot().putStack(result);
cca.setRecipe(message.recipe);
}
cca.detectAndSendChanges();
}
@@ -2,7 +2,7 @@ package com.github.vfyjxf.nee.network.packet;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import com.github.vfyjxf.nee.gui.NEEGuiHandler;
import com.github.vfyjxf.nee.network.NEEGuiHandler;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -0,0 +1,144 @@
package com.github.vfyjxf.nee.network.packet;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.IActionHost;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerNull;
import com.github.vfyjxf.nee.block.tile.TilePatternInterface;
import com.google.common.base.Optional;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import 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 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 PacketSetRecipe implements IMessage, IMessageHandler<PacketSetRecipe, IMessage> {
private NBTTagCompound recipe;
public PacketSetRecipe() {
}
public PacketSetRecipe(NBTTagCompound recipe) {
this.recipe = recipe;
}
@Override
public void fromBytes(ByteBuf buf) {
this.recipe = ByteBufUtils.readTag(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeTag(buf, this.recipe);
}
@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<ItemStack> maybePattern = AEApi.instance().definitions().items().encodedPattern().maybeStack(1);
if (maybePattern.isPresent()) {
patternStack = maybePattern.get();
}
if (patternStack != null) {
final NBTTagCompound patternValue = new NBTTagCompound();
final NBTTagList tagIn = new NBTTagList();
for (ItemStack stack : recipeInputs) {
tagIn.appendTag(crateItemTag(stack));
}
patternValue.setTag("in", tagIn);
patternValue.setTag("out", result.writeToNBT(new NBTTagCompound()));
patternValue.setBoolean("crafting", true);
patternValue.setBoolean("substitute", false);
patternStack.setTagCompound(patternValue);
return patternStack;
}
}
return null;
}
private NBTTagCompound crateItemTag(ItemStack itemStack) {
NBTTagCompound tag = new NBTTagCompound();
if (itemStack != null) {
itemStack.writeToNBT(tag);
}
return tag;
}
}
@@ -0,0 +1,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<PacketValueConfigClient, IMessage> {
private String name;
private String value;
public PacketValueConfigClient() {
}
public PacketValueConfigClient(String name, String value) {
this.name = name;
this.value = value;
}
public PacketValueConfigClient(String name) {
this.name = name;
this.value = "";
}
@Override
public void fromBytes(ByteBuf buf) {
this.name = ByteBufUtils.readUTF8String(buf);
this.value = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, this.name);
ByteBufUtils.writeUTF8String(buf, this.value);
}
@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;
}
}
@@ -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<PacketValueConfigServer, IMessage> {
private String name;
private String value;
public PacketValueConfigServer() {
}
public PacketValueConfigServer(String name, String value) {
this.name = name;
this.value = value;
}
public PacketValueConfigServer(String name) {
this.name = name;
this.value = "";
}
@Override
public void fromBytes(ByteBuf buf) {
this.name = ByteBufUtils.readUTF8String(buf);
this.value = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, this.name);
ByteBufUtils.writeUTF8String(buf, this.value);
}
@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;
}
}
@@ -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");
}
}
@@ -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);
}
}
@@ -130,45 +130,22 @@ public class IngredientTracker {
public List<ItemStack> getRequireToCraftStacks() {
List<ItemStack> 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);
}
}
}
@@ -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
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
@@ -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
@@ -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=样板接口
Whitespace-only changes.
Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB