Skip to content

一个简单的IO平衡思路#2

Open
yansunsky wants to merge 2 commits into
link-fgfgui:masterfrom
yansunsky:master
Open

一个简单的IO平衡思路#2
yansunsky wants to merge 2 commits into
link-fgfgui:masterfrom
yansunsky:master

Conversation

@yansunsky

Copy link
Copy Markdown

通过评估前后统计容器内物品的变化来规避容器欺骗。

2.启动棒可以用于还原工厂
3.添加黑名单机制,黑名单方块无法评估
- 新增配置项 EnableFactoryRevert (默认 false,禁止启动棒将工厂还原为空间方块)
- 防止物品复制Bug的同时不破坏评估系统的正常工作
- 后续根据快照修复进度重新开启

@link-fgfgui link-fgfgui left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

核心问题在于扫库存是没有通用办法的
不过检测到禁止的方块选择不进行评估而不是破坏方块后继续评估的逻辑是OK的

此PR包含内容过多,比如解包工厂方块,黑名单模组id,扫描库存并修正等,建议每个内容单独提PR,具体怎么分开可以问ai

public InventorySnapshot inventoryEnd;

// 原机器的 neoforge:attachments(含 machine_color),由 createMachine 从 EvaluatorBlockEntity 读取
public CompoundTag originalAttachments;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果要存,不应该存储在这里,放这里不会持久化,一旦重开存档就丢失


// 扫 IItemHandler
for (Direction dir : Direction.values()) {
IItemHandler itemHandler = compactWorld.getCapability(Capabilities.ItemHandler.BLOCK, pos, dir);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在模拟这种等级的要求下,NeoForge的Capability系统不能保证提供真实的信息

Comment on lines +320 to +322
Set<IItemHandler> seenItemHandlers = Collections.newSetFromMap(new IdentityHashMap<>());
Set<IFluidHandler> seenFluidHandlers = Collections.newSetFromMap(new IdentityHashMap<>());
Set<IEnergyStorage> seenEnergyHandlers = Collections.newSetFromMap(new IdentityHashMap<>());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一整块试图对IItemHandler去重的逻辑都不可靠

public class EvaluatorBlockEntity extends RoomCodeBlockEntity {
// 原机器方块信息,用于评估失败时还原
private ResourceLocation originalMachineBlock;
private CompoundTag savedOriginalNbt; // 原 BE 的完整 NBT(含 data components)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前没有存完整nbt的意义,原BE里只有颜色和RoomCode两个数据,只要RoomCode对应存在,还原的方块就能正常使用,只是颜色会丢失。如果要存颜色,直接写存颜色的代码


public class EvaluatorBlockEntity extends RoomCodeBlockEntity {
// 原机器方块信息,用于评估失败时还原
private ResourceLocation originalMachineBlock;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何意味?

Comment on lines +332 to +334
for (int x = startX; x <= endX; x++) {
for (int y = startY; y <= endY; y++) {
for (int z = startZ; z <= endZ; z++) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

又抄一次扫描

outputData.put(energyKey, outputData.get(energyKey) * ratio);
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

然后流体呢?

}
}

// ========== 工厂方块 → 还原为紧凑空间机器 ==========

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重复功能

Comment on lines +443 to +446
long s0Count = s0.items().getOrDefault(id, 0L);
long s1Count = s1.items().getOrDefault(id, 0L);
long totalO = machine.totalOutput.getOrDefault(id, 0L);
long totalI = machine.totalInput.getOrDefault(id, 0L);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServerLevel compactWorld = overworldLevel.getServer().getLevel(CompactDimension.LEVEL_KEY);
if (compactWorld == null) return CreateResult.ABORTED_SUSPICIOUS_BLOCKS;

// 必须先生成 UUID,再 loadRoom(forceRoom 需要 UUID 来强制加载区块)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这也要打注释,感觉有点吃饱了没事干

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants