吞噬盘实现分区功能

This commit is contained in:
GaLi 2026-04-17 16:11:32 +08:00
parent c8ae498808
commit b7a3f60979
3 changed files with 66 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package com.extendedae_plus.api.storage;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.AEKey;
@ -8,7 +10,11 @@ import appeng.api.stacks.KeyCounter;
import appeng.api.storage.cells.CellState;
import appeng.api.storage.cells.ISaveProvider;
import appeng.api.storage.cells.StorageCell;
import appeng.api.upgrades.IUpgradeInventory;
import appeng.core.AELog;
import appeng.core.definitions.AEItems;
import appeng.util.ConfigInventory;
import appeng.util.prioritylist.IPartitionList;
import com.extendedae_plus.ExtendedAEPlus;
import com.extendedae_plus.items.InfinityBigIntegerCellItem;
import com.extendedae_plus.util.storage.InfinityConstants;
@ -37,6 +43,8 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
private final ItemStack self;
// AE2 提供的保存提供者用于在容器中批量保存时触发回调
private final ISaveProvider container;
private final IPartitionList partitionList;
private final IncludeExclude partitionListMode;
// 存储物品键和数量的映射
private Object2ObjectMap<AEKey, BigInteger> AEKey2AmountsMap;
// 存储的物品种类数量
@ -59,6 +67,17 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
this.container = saveProvider;
// 初始化 storedAmounts null延迟加载物品数据
this.AEKey2AmountsMap = null;
var builder = IPartitionList.builder();
var upgrades = this.getUpgradesInventory();
var config = this.getConfigInventory();
boolean hasInverter = upgrades.isInstalled(AEItems.INVERTER_CARD);
boolean isFuzzy = upgrades.isInstalled(AEItems.FUZZY_CARD);
if (isFuzzy) {
builder.fuzzyMode(this.getFuzzyMode());
}
builder.addAll(config.keySet());
this.partitionListMode = hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
this.partitionList = builder.build();
// 初始化磁盘数据
initData();
}
@ -146,6 +165,7 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
// backward compat: also remove internal cell item count key if present
tag.remove(InfinityConstants.INFINITY_CELL_ITEM_COUNT);
}
this.isPersisted = true;
initData();
}
return;
@ -195,7 +215,7 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
// 获取存储单元的描述此处返回null可自定义
@Override
public Component getDescription() {
return null;
return self.getHoverName();
}
// 静态方法创建存储单元库存
@ -311,6 +331,18 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
return ExtendedAEPlus.STORAGE_INSTANCE;
}
private ConfigInventory getConfigInventory() {
return this.cell.getConfigInventory(this.self);
}
private IUpgradeInventory getUpgradesInventory() {
return this.cell.getUpgrades(this.self);
}
private FuzzyMode getFuzzyMode() {
return this.cell.getFuzzyMode(this.self);
}
// 标记数据需要保存并通知容器或直接持久化
private void saveChanges() {
// 更新存储的物品种类数量
@ -339,6 +371,9 @@ public class InfinityBigIntegerCellInventory implements StorageCell {
if (amount == 0){
return 0;
}
if (!this.partitionList.matchesFilter(what, this.partitionListMode)) {
return 0;
}
// 不允许存储有物品的无限单元
if (what instanceof AEItemKey itemKey &&
itemKey.getItem() instanceof InfinityBigIntegerCellItem &&

View File

@ -52,9 +52,13 @@ public final class UpgradeCards {
Upgrades.add(ModItems.CHANNEL_CARD.get(), AEParts.EXPORT_BUS, 1, ioBusGroup);
Upgrades.add(ModItems.CHANNEL_CARD.get(), AEParts.STORAGE_BUS, 1, storageGroup);
String storageCellGroup = GuiText.StorageCells.getTranslationKey();
Upgrades.add(AEItems.FUZZY_CARD, ModItems.INFINITY_BIGINTEGER_CELL.get(), 1, storageCellGroup);
Upgrades.add(AEItems.INVERTER_CARD, ModItems.INFINITY_BIGINTEGER_CELL.get(), 1, storageCellGroup);
//EAE 的扩展输入/输出总线支持频道卡部件
Upgrades.add(ModItems.CHANNEL_CARD.get(), EX_IMPORT_BUS, 1, ioBusGroup);
Upgrades.add(ModItems.CHANNEL_CARD.get(), EX_EXPORT_BUS, 1, ioBusGroup);
});
}
}
}

View File

@ -2,6 +2,10 @@ package com.extendedae_plus.items;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.cells.ICellWorkbenchItem;
import appeng.api.upgrades.IUpgradeInventory;
import appeng.api.upgrades.UpgradeInventories;
import appeng.items.contents.CellConfig;
import appeng.util.ConfigInventory;
import com.extendedae_plus.api.storage.InfinityBigIntegerCellInventory;
import com.extendedae_plus.util.storage.InfinityConstants;
import com.google.common.base.Preconditions;
@ -94,12 +98,31 @@ public class InfinityBigIntegerCellItem extends Item implements ICellWorkbenchIt
return stack;
}
@Override
public IUpgradeInventory getUpgrades(ItemStack itemStack) {
return UpgradeInventories.forItem(itemStack, 4);
}
@Override
public ConfigInventory getConfigInventory(ItemStack itemStack) {
return CellConfig.create(itemStack);
}
@Override
public FuzzyMode getFuzzyMode(ItemStack itemStack) {
return null;
final String fz = itemStack.getOrCreateTag().getString("FuzzyMode");
if (fz.isEmpty()) {
return FuzzyMode.IGNORE_ALL;
}
try {
return FuzzyMode.valueOf(fz);
} catch (Throwable t) {
return FuzzyMode.IGNORE_ALL;
}
}
@Override
public void setFuzzyMode(ItemStack itemStack, FuzzyMode fuzzyMode) {
itemStack.getOrCreateTag().putString("FuzzyMode", fuzzyMode.name());
}
}
}