Compare commits

..
Author SHA1 Message Date
asdfljandRaven Szewczyk b9724d9369 fc terminal add type filter (#98)
* fc terminal add type filter

* Update dependencies.gradle

---------

Co-authored-by: Raven Szewczyk <[email protected]>
2023-03-12 20:25:42 +01:00
Yang Xizhi c92f8bdd7c Merge pull request #103 from asdflj/recipe
fix fc pattern terminal shift click will use not support item to fill slot
2023-03-07 12:41:05 +08:00
asdflj ab7769a45d add default method 2023-03-06 18:35:54 +08:00
asdflj d2c03bc903 fix fc pattern terminal shift click will use not support item to fill slot 2023-03-06 15:54:33 +08:00
Yang Xizhi e8664328ed Merge pull request #102 from asdflj/terminal
fix cant Take/Put items in Universal Terminal
2023-03-04 13:10:41 +08:00
asdflj 84e395e470 fix cant Take/Put items in Universal Terminal 2023-03-04 08:36:21 +08:00
GlodBlock 0a01bb008b fix gl crash 2023-03-03 20:27:02 +08:00
Yang Xizhi f73f79da7b Merge pull request #100 from asdflj/terminal
terminal does not update view
2023-03-03 13:03:22 +08:00
asdflj 16f207ce80 terminal does not update view 2023-03-03 13:00:01 +08:00
GlodBlock 18f31ac3ef fix export bus exporting too much fluid 2023-03-02 16:46:35 +08:00
Yang Xizhi b205d3f53f Merge pull request #97 from asdflj/master
fluid packet decode add support to use conduit to export fluid
2023-02-28 12:24:33 +08:00
asdflj 6505967826 add fluid packet check 2023-02-28 09:06:06 +08:00
asdflj 78e9291fc6 Certus Quartz Tank add waila support
fluid packet decode add support to use conduit to export fluid
2023-02-27 16:50:29 +08:00
25 changed files with 311 additions and 106 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
dependencies {
compile('com.github.GTNewHorizons:NotEnoughItems:2.3.32-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-160-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-176-GTNH:dev')
compile('curse.maven:cofh-core-69162:2388751')
compile('com.github.GTNewHorizons:waila:1.5.22:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.32:dev') { transitive = false }
@@ -13,6 +13,7 @@ import com.glodblock.github.loader.CalculatorV2PluginLoader;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.loader.RecipeLoader;
import com.glodblock.github.loader.filter.FluidFilter;
import com.glodblock.github.proxy.CommonProxy;
import com.glodblock.github.util.ModAndClassUtil;
@@ -77,6 +78,9 @@ public class FluidCraft {
if (ModAndClassUtil.isV2) {
CalculatorV2PluginLoader.installCalculatorV2Plugins();
}
if (ModAndClassUtil.isTypeFilter) {
FluidFilter.installFilter();
}
proxy.postInit(event);
}
@@ -84,6 +84,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
protected GuiImgButton searchBoxSettings;
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
protected GuiImgButton typeFilter;
@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
@@ -228,6 +229,15 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
this.configSrc.getSetting(Settings.VIEW_MODE)));
this.offsetY += 20;
}
if (ModAndClassUtil.isTypeFilter && this instanceof GuiItemMonitor) {
this.buttonList.add(
this.typeFilter = new GuiImgButton(
this.guiLeft - 18,
this.offsetY,
Settings.TYPE_FILTER,
this.configSrc.getSetting(Settings.TYPE_FILTER)));
this.offsetY += 20;
}
this.buttonList.add(
this.SortDirBox = new GuiImgButton(
@@ -658,6 +668,11 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
return this.configSrc.getSetting(Settings.VIEW_MODE);
}
@Override
public Enum getTypeFilter() {
return this.configSrc.getSetting(Settings.TYPE_FILTER);
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (this.SortByBox != null) {
@@ -671,6 +686,9 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
if (this.ViewBox != null) {
this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE));
}
if (this.typeFilter != null) {
this.typeFilter.set(this.configSrc.getSetting(Settings.TYPE_FILTER));
}
this.repo.updateView();
}
@@ -18,8 +18,6 @@ import org.apache.commons.lang3.tuple.MutablePair;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
@@ -28,6 +26,7 @@ import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
@@ -42,7 +41,6 @@ import appeng.util.item.AEItemStack;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.inventory.item.IFluidPortableCell;
import com.glodblock.github.network.CPacketFluidUpdate;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
@@ -61,27 +59,28 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
super(ip, monitorable, bindInventory);
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getFluidInventory();
if (this.monitor != null) {
this.monitor.addListener(this, null);
if (monitorable instanceof IFluidPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
IStorageGrid storageGrid = g.getCache(IStorageGrid.class);
this.monitor = storageGrid.getFluidInventory();
if (this.monitor == null) {
this.setValidContainer(false);
} else {
this.monitor.addListener(this, null);
}
}
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
this.monitor = monitorable.getFluidInventory();
this.monitor.addListener(this, null);
this.setPowerSource((IEnergySource) monitorable);
}
} else {
this.monitor = null;
@@ -151,11 +150,6 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
}
}
@Override
protected boolean isInvalid() {
return this.monitor != this.host.getFluidInventory();
}
@Override
protected void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
@@ -9,8 +9,6 @@ import net.minecraft.inventory.ICrafting;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.implementations.guiobjects.IPortableCell;
import appeng.api.implementations.tiles.IMEChest;
import appeng.api.implementations.tiles.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
@@ -19,6 +17,7 @@ import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@@ -43,26 +42,30 @@ public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
super(ip, monitorable, bindInventory);
if (Platform.isServer()) {
this.serverCM = monitorable.getConfigManager();
this.monitor = monitorable.getItemInventory();
if (this.monitor != null) {
this.monitor.addListener(this, null);
this.setCellInventory(this.monitor);
if (monitorable instanceof IPortableCell) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IMEChest) {
this.setPowerSource((IEnergySource) monitorable);
} else if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
if (monitorable instanceof IGridHost) {
final IGridNode node = ((IGridHost) monitorable).getGridNode(ForgeDirection.UNKNOWN);
if (node != null) {
this.networkNode = node;
final IGrid g = node.getGrid();
if (g != null) {
this.setPowerSource(new ChannelPowerSrc(this.networkNode, g.getCache(IEnergyGrid.class)));
IStorageGrid storageGrid = g.getCache(IStorageGrid.class);
this.monitor = storageGrid.getItemInventory();
if (this.monitor == null) {
this.setValidContainer(false);
} else {
this.monitor.addListener(this, null);
this.setCellInventory(this.monitor);
}
}
} else {
this.setValidContainer(false);
}
} else {
this.setValidContainer(false);
this.monitor = monitorable.getItemInventory();
this.monitor.addListener(this, null);
this.setCellInventory(this.monitor);
this.setPowerSource((IEnergySource) monitorable);
}
} else {
this.monitor = null;
@@ -61,6 +61,11 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.clientCM.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
}
public IMEMonitor<T> getMonitor() {
return this.monitor;
}
public IGridNode getNetworkNode() {
@@ -112,7 +117,7 @@ public abstract class FCContainerMonitor<T extends IAEStack<T>> extends FCBaseCo
protected abstract void processItemList();
protected boolean isInvalid() {
return this.monitor != this.host.getItemInventory();
return this.monitor == null;
}
protected void updatePowerStatus() {
@@ -137,8 +137,9 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
this.source);
}
int space = fh.fill(this.getSide().getOpposite(), toExtract.getFluidStack(), false);
toExtract.setStackSize(space);
final IAEFluidStack real = inv.extractItems(toExtract, Actionable.MODULATE, this.source);
if (real != null && isAllowed) {
int realInserted = fh.fill(this.getSide().getOpposite(), real.getFluidStack(), true);
if (realInserted < real.getStackSize()) {
@@ -82,6 +82,7 @@ public abstract class FCPart extends AEBasePart
this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.cm.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
}
@MENetworkEventSubscribe
@@ -35,6 +35,7 @@ import appeng.client.texture.CableBusTextures;
import appeng.core.AELog;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.Reflected;
import appeng.hooks.TickHandler;
import appeng.me.GridAccessException;
import appeng.parts.reporting.AbstractPartDisplay;
import appeng.parts.reporting.PartPanel;
@@ -199,7 +200,7 @@ public abstract class FCPartMonitor extends AbstractPartDisplay implements IPart
super.finalize();
if (this.dspList != null) {
GLAllocation.deleteDisplayLists(this.dspList);
TickHandler.INSTANCE.scheduleCallListDelete(this.dspList);
}
}
@@ -1,14 +1,17 @@
package com.glodblock.github.common.tile;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.util.BlockPos;
public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
@@ -26,6 +29,7 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return this;
}
};
private boolean hasUpdate;
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
@@ -191,6 +195,40 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
return (float) this.tank.getFluidAmount() / this.tank.getCapacity();
}
private void onComparatorUpdate(World world, int x, int y, int z, Block block) {
world.func_147453_f(x, y, z, block);
}
@Override
public void updateEntity() {
super.updateEntity();
if (this.tank.getFluid() != null) {
TileCertusQuartzTank below = getTankBelow(this);
if (below != null) {
FluidStack filled = this.tank.getFluid().copy();
filled.amount = below.fill(this.tank.getFluid(), true, true);
if (filled.amount >= 0) {
this.drain(filled, true, true);
this.hasUpdate = true;
below.hasUpdate = true;
}
}
}
if (this.hasUpdate) {
onComparatorUpdate(this.worldObj, this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
this.hasUpdate = false;
}
}
private TileCertusQuartzTank getTankBelow(TileEntity tile) {
TileEntity tank = new BlockPos(tile).getOffSet(0, -1, 0).getTileEntity();
if (tank != null && tank instanceof TileCertusQuartzTank) {
return (TileCertusQuartzTank) tank;
}
return null;
}
public FluidTankInfo[] getTankInfo(boolean goToMainTank) {
if (!goToMainTank) return new FluidTankInfo[] { this.tank.getInfo() };
@@ -212,12 +250,12 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
break;
}
yOff = 0;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
yOff -= 1;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord - yOff, this.zCoord);
while (true) {
if (offTE instanceof TileCertusQuartzTank) {
mainTank = (TileCertusQuartzTank) offTE;
if (mainTank.getFluid() == null || mainTank.getFluid() == getFluid()) {
if (mainTank.getFluid() == null || getFluid() == null || mainTank.getFluid() == getFluid()) {
FluidTankInfo info = mainTank.getTankInfo(false)[0];
if (info != null) {
capacity += info.capacity;
@@ -226,8 +264,7 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
if (info.fluid.getFluid() != null) fluid = info.fluid.getFluid();
}
}
yOff++;
offTE = this.worldObj.getTileEntity(this.xCoord, this.yCoord + yOff, this.zCoord);
offTE = new BlockPos(offTE).getOffSet(0, 1, 0).getTileEntity();
continue;
}
}
@@ -274,4 +311,8 @@ public class TileCertusQuartzTank extends TileEntity implements IFluidHandler {
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
this.tank.writeToNBT(tag);
}
public FluidTankInfo[] getInternalFluid() {
return this.getTankInfo(true);
}
}
@@ -182,6 +182,7 @@ public class TileFluidPacketDecoder extends AENetworkTile
ItemStack fluidPacket = this.inventory.getStackInSlot(0);
if (fluidPacket != null) {
FluidStack fs = ItemFluidPacket.getFluidStack(fluidPacket);
if (fs == null) return null;
if (fs.isFluidEqual(requestFluid)) {
if (fs.amount > requestFluid.amount) {
fs.amount -= requestFluid.amount;
@@ -201,6 +202,7 @@ public class TileFluidPacketDecoder extends AENetworkTile
ItemStack fluidPacket = this.inventory.getStackInSlot(0);
if (fluidPacket != null) {
FluidStack requestFluid = ItemFluidPacket.getFluidStack(fluidPacket);
if (requestFluid == null) return null;
requestFluid.amount = maxDrain;
return this.drain(requestFluid, doDrain);
}
@@ -224,6 +226,7 @@ public class TileFluidPacketDecoder extends AENetworkTile
return new FluidTankInfo[0];
} else {
FluidStack fs = ItemFluidPacket.getFluidStack(fluidPacket);
if (fs == null) return new FluidTankInfo[0];
return new FluidTankInfo[] { new FluidTankInfo(fs, fs.amount) };
}
}
@@ -15,6 +15,14 @@ public class Tooltip {
return String.format("%s: %s mB", name, NumberFormat.getInstance().format(amount));
}
public static String fluidFormat(String name, long amount, long capacity) {
return String.format(
"%s: %s mB / %s mB",
name,
NumberFormat.getInstance().format(amount),
NumberFormat.getInstance().format(capacity));
}
public static String partFluidBusFormat(int amount) {
return String
.format("%s: %s mB/t", I18n.format(NameConst.WAILA_SPEED), NumberFormat.getInstance().format(amount));
@@ -10,14 +10,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import com.glodblock.github.common.tile.TileCertusQuartzTank;
import com.glodblock.github.crossmod.waila.Tooltip;
import com.glodblock.github.util.Util;
public class FluidInvWailaDataProvider extends BaseWailaDataProvider {
@@ -26,9 +25,13 @@ public class FluidInvWailaDataProvider extends BaseWailaDataProvider {
final IWailaDataAccessor accessor, final IWailaConfigHandler config) {
final TileEntity te = accessor.getTileEntity();
if (te instanceof TileCertusQuartzTank) {
for (FluidTankInfo info : ((IFluidHandler) te).getTankInfo(ForgeDirection.UNKNOWN)) {
if (info.fluid == null) continue;
currentToolTip.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount));
if (accessor.getNBTData().hasKey("fluidInv")) {
NBTTagCompound data = (NBTTagCompound) accessor.getNBTData().getTag("fluidInv");
for (FluidTankInfo info : Util.FluidUtil.fluidTankInfoReadFromNBT(data)) {
if (info.fluid == null) continue;
currentToolTip
.add(Tooltip.fluidFormat(info.fluid.getLocalizedName(), info.fluid.amount, info.capacity));
}
}
}
return currentToolTip;
@@ -38,6 +41,9 @@ public class FluidInvWailaDataProvider extends BaseWailaDataProvider {
public NBTTagCompound getNBTData(final EntityPlayerMP player, final TileEntity te, final NBTTagCompound tag,
final World world, final int x, final int y, final int z) {
if (te instanceof TileCertusQuartzTank) {
NBTTagCompound data = new NBTTagCompound();
Util.FluidUtil.fluidTankInfoWriteToNBT(((TileCertusQuartzTank) te).getInternalFluid(), data);
tag.setTag("fluidInv", data);
te.writeToNBT(tag);
}
return tag;
@@ -95,6 +95,7 @@ public class WirelessCraftingTerminalInventory extends MEMonitorHandler<IAEItemS
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
return out;
}
@@ -135,6 +135,7 @@ public class WirelessPatternTerminalExInventory extends MEMonitorHandler<IAEItem
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
this.readFromNBT();
return out;
@@ -133,6 +133,7 @@ public class WirelessPatternTerminalInventory extends MEMonitorHandler<IAEItemSt
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
this.readFromNBT();
return out;
@@ -0,0 +1,34 @@
package com.glodblock.github.loader.filter;
import static appeng.api.config.TypeFilter.*;
import net.minecraft.item.Item;
import appeng.api.config.TypeFilter;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.client.me.ItemRepo;
import com.glodblock.github.common.item.ItemFluidDrop;
public class FluidFilter {
public static void installFilter() {
ItemRepo.registerTypeHandler(FluidFilter::filter, FLUIDS);
}
private static boolean filter(IAEStack<?> stack, TypeFilter typeFilter) {
if (stack instanceof IAEItemStack) {
Item item = ((IAEItemStack) stack).getItem();
if (item != null) {
switch (typeFilter) {
case ITEMS:
return !(item instanceof ItemFluidDrop);
case FLUIDS:
return item instanceof ItemFluidDrop;
}
}
}
return true;
}
}
@@ -1,9 +1,7 @@
package com.glodblock.github.nei;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import net.minecraft.item.ItemStack;
@@ -43,24 +41,11 @@ public class NEIUtils {
}
public static List<OrderStack<?>> clearNull(List<OrderStack<?>> list) {
List<OrderStack<?>> cleared = new LinkedList<>();
HashMap<Integer, Object> map = new HashMap<>();
int upper = 0;
for (OrderStack<?> orderStack : list) {
if (orderStack != null && orderStack.getStack() != null) {
if (orderStack.getStack() instanceof ItemStack && ((ItemStack) orderStack.getStack()).stackSize == 0)
continue;
map.put(orderStack.getIndex(), orderStack.getStack());
upper = Math.max(upper, orderStack.getIndex());
}
}
int id = 0;
for (int i = 0; i <= upper; i++) {
if (map.containsKey(i)) {
cleared.add(new OrderStack<>(map.get(i), id));
id++;
}
}
return cleared;
AtomicInteger i = new AtomicInteger(0);
return list.stream().filter(Objects::nonNull)
.filter(
orderStack -> !(orderStack.getStack() != null && orderStack.getStack() instanceof ItemStack
&& ((ItemStack) orderStack.getStack()).stackSize == 0))
.peek(orderStack -> orderStack.setIndex(i.getAndIncrement())).collect(Collectors.toList());
}
}
@@ -1,10 +1,14 @@
package com.glodblock.github.nei.object;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -15,7 +19,8 @@ import com.glodblock.github.util.Util;
public class OrderStack<T> {
private T RealStack;
private final int index;
private int index;
private ItemStack[] items;
public static final int ITEM = 1;
public static final int FLUID = 2;
@@ -28,10 +33,29 @@ public class OrderStack<T> {
this.index = order;
}
public OrderStack(T stack, int order, ItemStack[] items) {
this(stack, order);
if (items.length > 1) {
this.items = items;
}
}
public void putStack(T stack) {
this.RealStack = stack;
}
public void putItems(ItemStack[] items) {
this.items = items;
}
public ItemStack[] getItems() {
return this.items;
}
public final void setIndex(int i) {
this.index = i;
}
public T getStack() {
return RealStack;
}
@@ -71,6 +95,16 @@ public class OrderStack<T> {
NBTTagCompound tmp = new NBTTagCompound();
tmp.setByte("t", (byte) ITEM);
((ItemStack) RealStack).writeToNBT(tmp);
// replacement items
if (items != null) {
NBTTagList list = new NBTTagList();
for (ItemStack is : this.items) {
NBTTagCompound t = new NBTTagCompound();
is.writeToNBT(t);
list.appendTag(t);
}
tmp.setTag(index + ":", list);
}
buf.setTag(index + ":", tmp);
} else if (RealStack instanceof FluidStack) {
NBTTagCompound tmp = new NBTTagCompound();
@@ -91,7 +125,15 @@ public class OrderStack<T> {
byte id = info.getByte("t");
switch (id) {
case ITEM:
return new OrderStack<>(ItemStack.loadItemStackFromNBT(info), index);
List<ItemStack> list = new ArrayList<>();
if (info.hasKey(index + ":")) {
NBTTagList items = info.getTagList(index + ":", 10);
for (int x = 0; x < items.tagCount(); x++) {
final NBTTagCompound item = items.getCompoundTagAt(x);
list.add(ItemStack.loadItemStackFromNBT(item));
}
}
return new OrderStack<>(ItemStack.loadItemStackFromNBT(info), index, list.toArray(new ItemStack[0]));
case FLUID:
return new OrderStack<>(FluidStack.loadFluidStackFromNBT(info), index);
case CUSTOM:
@@ -1,9 +1,7 @@
package com.glodblock.github.nei.recipes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
@@ -30,7 +28,8 @@ public final class FluidRecipe {
public static List<OrderStack<?>> getPackageInputs(IRecipeHandler recipe, int index, boolean priority) {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
if (tRecipe == null || !IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return new ArrayList<>();
if (tRecipe == null) return new ArrayList<>();
if (!IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return getDefaultPackageInputs(tRecipe, index);
if (tRecipe.getOverlayIdentifier() == null) return getPackageInputsLegacy(recipe, index);
IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier());
if (extractor == null) return new ArrayList<>();
@@ -54,9 +53,26 @@ public final class FluidRecipe {
return out;
}
private static List<OrderStack<?>> getDefaultPackageInputs(TemplateRecipeHandler tRecipe, int index) {
List<OrderStack<?>> tmp = new LinkedList<>();
AtomicInteger i = new AtomicInteger(0);
tRecipe.getIngredientStacks(index)
.forEach(ps -> tmp.add(new OrderStack<>(ps.item, i.getAndIncrement(), ps.items)));
return tmp;
}
private static List<OrderStack<?>> getDefaultPackageOutputs(TemplateRecipeHandler tRecipe, int index) {
List<OrderStack<?>> tmp = new LinkedList<>();
AtomicInteger i = new AtomicInteger(0);
tmp.add(new OrderStack<>(tRecipe.getResultStack(index).item, i.getAndIncrement()));
tRecipe.getOtherStacks(index).forEach(ps -> tmp.add(new OrderStack<>(ps.item, i.getAndIncrement())));
return tmp;
}
public static List<OrderStack<?>> getPackageOutputs(IRecipeHandler recipe, int index, boolean useOther) {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
if (tRecipe == null || !IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return new ArrayList<>();
if (tRecipe == null) return new ArrayList<>();
if (!IdentifierMap.containsKey(tRecipe.getOverlayIdentifier())) return getDefaultPackageOutputs(tRecipe, index);
if (tRecipe.getOverlayIdentifier() == null) return getPackageOutputsLegacy(recipe, index, useOther);
IRecipeExtractor extractor = IdentifierMap.get(tRecipe.getOverlayIdentifier());
if (extractor == null) return new ArrayList<>();
@@ -26,7 +26,7 @@ public final class ExtractorUtil {
return items.stream().map(item -> {
index.getAndIncrement();
Object o = transformer.apply(item);
return o != null ? new OrderStack<>(o, index.get()) : null;
return o != null ? new OrderStack<>(o, index.get(), item.items) : null;
}).filter(Objects::nonNull).collect(Collectors.toList());
}
}
@@ -12,8 +12,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@@ -97,12 +96,10 @@ public class CPacketTransferRecipe implements IMessage {
public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) {
Container c = ctx.getServerHandler().playerEntity.openContainer;
if (c instanceof ContainerItemMonitor) {
ITerminalHost host = ((ContainerItemMonitor) c).getHost();
IItemList<IAEItemStack> storageList;
if (host != null) {
storageList = host.getItemInventory().getStorageList();
} else {
storageList = AEApi.instance().storage().createItemList();
IMEMonitor<IAEItemStack> monitor = ((ContainerItemMonitor) c).getMonitor();
IItemList<IAEItemStack> storageList = AEApi.instance().storage().createItemList();
if (monitor != null) {
storageList = monitor.getStorageList();
}
if (c instanceof FCContainerEncodeTerminal) {
// pattern terminal only
@@ -130,16 +127,15 @@ public class CPacketTransferRecipe implements IMessage {
// using exists item to fill slot
if (message.shift && !storageList.isEmpty()) {
for (OrderStack stack : message.inputs) {
if (stack.getStack() instanceof FluidStack) continue;
ItemStack is = (ItemStack) stack.getStack();
IAEItemStack iaeItemStack = AEApi.instance().storage().createItemStack(is);
if (stack.getStack() instanceof FluidStack || stack.getItems() == null) continue;
IAEItemStack iaeItemStack = AEApi.instance().storage()
.createItemStack((ItemStack) stack.getStack());
if (storageList.findPrecise(iaeItemStack) == null) {
for (IAEItemStack tmp : storageList.findFuzzy(iaeItemStack, FuzzyMode.IGNORE_ALL)) {
if (iaeItemStack.sameOre(tmp)) {
ItemStack substitute = tmp.getItemStack().copy();
substitute.stackSize = is.stackSize;
stack.putStack(substitute);
break;
// try to replace item
for (ItemStack replaceItemStack : stack.getItems()) {
if (storageList.findPrecise(
AEApi.instance().storage().createItemStack(replaceItemStack)) != null) {
stack.putStack(replaceItemStack);
}
}
}
@@ -40,6 +40,10 @@ public class BlockPos {
return new BlockPos(this.x + face.offsetX, this.y + face.offsetY, this.z + face.offsetZ, this.w);
}
public BlockPos getOffSet(int x, int y, int z) {
return new BlockPos(this.x + x, this.y + y, this.z + z, this.w);
}
public TileEntity getTileEntity() {
if (w != null) {
return w.getTileEntity(x, y, z);
@@ -27,6 +27,7 @@ public final class ModAndClassUtil {
public static boolean WAILA = false;
public static boolean AVARITIA = false;
public static boolean isV2;
public static boolean isTypeFilter;
public static boolean isDoubleButton;
public static boolean isSaveText;
public static boolean isSearchStringTooltip;
@@ -111,6 +112,13 @@ public final class ModAndClassUtil {
} catch (ClassNotFoundException e) {
isV2 = false;
}
try {
Field filters = Class.forName("appeng.client.me.ItemRepo").getDeclaredField("filters");
if (filters == null) isTypeFilter = false;
isTypeFilter = true;
} catch (ClassNotFoundException | NoSuchFieldException e) {
isTypeFilter = false;
}
try {
essentiaGas = Class.forName("thaumicenergistics.common.fluids.GaseousEssentia");
@@ -3,6 +3,8 @@ package com.glodblock.github.util;
import static com.glodblock.github.common.item.ItemBaseWirelessTerminal.infinityBoosterCard;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
@@ -415,6 +417,36 @@ public final class Util {
public static class FluidUtil {
public static void fluidTankInfoWriteToNBT(FluidTankInfo[] infos, NBTTagCompound data) {
int i = 0;
for (FluidTankInfo info : infos) {
if (info.fluid != null && info.fluid.amount > 0) {
NBTTagCompound fs = new NBTTagCompound();
info.fluid.writeToNBT(fs);
fs.setInteger("capacity", info.capacity);
data.setTag("#" + i, fs);
}
i++;
}
data.setInteger("fluidInvSize", i);
}
public static FluidTankInfo[] fluidTankInfoReadFromNBT(NBTTagCompound data) {
int i = 0;
List<FluidTankInfo> infos = new ArrayList<>();
while (data.hasKey("fluidInvSize") && i < data.getInteger("fluidInvSize")) {
if (data.hasKey("#" + i)) {
NBTTagCompound tag = (NBTTagCompound) data.getTag("#" + i);
FluidStack fs = FluidStack.loadFluidStackFromNBT(tag);
infos.add(new FluidTankInfo(fs, tag.getInteger("capacity")));
} else {
infos.add(new FluidTankInfo(null, 0));
}
i++;
}
return infos.toArray(new FluidTankInfo[0]);
}
public static IAEFluidStack createAEFluidStack(Fluid fluid) {
return createAEFluidStack(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME));
}