装配矩阵上传核心

This commit is contained in:
GaLicn 2025-09-19 20:17:32 +08:00
parent ba22d3ae2e
commit 0090d302f1
7 changed files with 106 additions and 2 deletions

View File

@ -74,6 +74,14 @@ public class ExtendedAEPlus {
ModNetwork.register();
// 注册自定义 Curios 宿主定位器便于将菜单宿主信息在服务端与客户端间同步
MenuLocators.register(CuriosItemLocator.class, CuriosItemLocator::writeToPacket, CuriosItemLocator::readFromPacket);
// 绑定装配矩阵上传核心的方块实体类型延迟到注册完成后
com.extendedae_plus.init.ModBlocks.ASSEMBLER_MATRIX_UPLOAD_CORE.get().setBlockEntity(
com.extendedae_plus.content.matrix.UploadCoreBlockEntity.class,
com.extendedae_plus.init.ModBlockEntities.UPLOAD_CORE_BE.get(),
null,
null
);
});
}

View File

@ -0,0 +1,26 @@
package com.extendedae_plus.content.matrix;
import com.glodblock.github.extendedae.common.blocks.matrix.BlockAssemblerMatrixBase;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.state.BlockBehaviour;
/**
* ExtendedAE_Plus: 装配矩阵上传核心方块内部功能块
* 仅用于作为多方块内部的功能块存在是否允许自动上传由工具类检查集群中是否存在该核心决定
*/
public class UploadCoreBlock extends BlockAssemblerMatrixBase<UploadCoreBlockEntity> {
public UploadCoreBlock() {
super();
}
public UploadCoreBlock(BlockBehaviour.Properties props) {
super(props);
}
@Override
public Item getPresentItem() {
// 由对应的 BlockItem 注册返回上传核心不需要特殊的 PresentItem可返回自身的 BlockItem
return com.extendedae_plus.init.ModItems.ASSEMBLER_MATRIX_UPLOAD_CORE.get();
}
}

View File

@ -0,0 +1,24 @@
package com.extendedae_plus.content.matrix;
import com.glodblock.github.extendedae.common.me.matrix.ClusterAssemblerMatrix;
import com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixFunction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
/**
* ExtendedAE_Plus: 装配矩阵上传核心方块实体
* 作为矩阵内部功能块仅用于标记该矩阵允许被自动上传工具类会在集群中查找此实体
*/
public class UploadCoreBlockEntity extends TileAssemblerMatrixFunction {
public UploadCoreBlockEntity(BlockPos pos, BlockState state) {
super((BlockEntityType<?>) com.extendedae_plus.init.ModBlockEntities.UPLOAD_CORE_BE.get(), pos, state);
}
@Override
public void add(ClusterAssemblerMatrix c) {
// 无需修改集群仅作为存在性标记
// 若后续需要限制为最多一个可在 ExtendedAE_Plus 工具类或事件中做校验与提示
}
}

View File

@ -2,6 +2,7 @@ package com.extendedae_plus.init;
import com.extendedae_plus.ExtendedAEPlus;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity;
import com.extendedae_plus.content.matrix.UploadCoreBlockEntity;
import com.extendedae_plus.content.controller.NetworkPatternControllerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.registries.DeferredRegister;
@ -23,4 +24,10 @@ public final class ModBlockEntities {
BLOCK_ENTITY_TYPES.register("network_pattern_controller",
() -> BlockEntityType.Builder.of(NetworkPatternControllerBlockEntity::new,
ModBlocks.NETWORK_PATTERN_CONTROLLER.get()).build(null));
// 装配矩阵上传核心
public static final RegistryObject<BlockEntityType<UploadCoreBlockEntity>> UPLOAD_CORE_BE =
BLOCK_ENTITY_TYPES.register("assembler_matrix_upload_core",
() -> BlockEntityType.Builder.of(UploadCoreBlockEntity::new,
ModBlocks.ASSEMBLER_MATRIX_UPLOAD_CORE.get()).build(null));
}

View File

@ -2,6 +2,7 @@ package com.extendedae_plus.init;
import com.extendedae_plus.ExtendedAEPlus;
import com.extendedae_plus.content.wireless.WirelessTransceiverBlock;
import com.extendedae_plus.content.matrix.UploadCoreBlock;
import com.extendedae_plus.content.crafting.EPlusCraftingUnitType;
import appeng.block.crafting.CraftingUnitBlock;
import appeng.blockentity.crafting.CraftingBlockEntity;
@ -39,6 +40,16 @@ public final class ModBlocks {
)
);
// 装配矩阵上传核心内部功能块
public static final RegistryObject<UploadCoreBlock> ASSEMBLER_MATRIX_UPLOAD_CORE = BLOCKS.register(
"assembler_matrix_upload_core",
() -> {
var b = new UploadCoreBlock();
// 注意方块实体绑定延后到 commonSetup enqueueWork 中执行避免注册阶段循环依赖
return b;
}
);
// Crafting Accelerators (reuse MAE2 textures/models)
public static final RegistryObject<CraftingUnitBlock> ACCELERATOR_4x = BLOCKS.register(
"4x_crafting_accelerator",

View File

@ -28,6 +28,12 @@ public final class ModItems {
() -> new BlockItem(ModBlocks.NETWORK_PATTERN_CONTROLLER.get(), new Item.Properties())
);
// 装配矩阵上传核心方块物品
public static final RegistryObject<Item> ASSEMBLER_MATRIX_UPLOAD_CORE = ITEMS.register(
"assembler_matrix_upload_core",
() -> new BlockItem(ModBlocks.ASSEMBLER_MATRIX_UPLOAD_CORE.get(), new Item.Properties())
);
// Crafting Accelerators
public static final RegistryObject<Item> ACCELERATOR_4x = ITEMS.register(
"4x_crafting_accelerator",

View File

@ -543,7 +543,7 @@ public class ExtendedAEPatternUploadUtil {
var tiles = grid.getMachines(com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixPattern.class);
int idx = 0;
for (com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixPattern tile : tiles) {
if (tile != null && tile.isFormed() && tile.getMainNode().isActive()) {
if (tile != null && tile.isFormed() && tile.getMainNode().isActive() && clusterHasSingleUploadCore(tile)) {
var inv = tile.getExposedInventory();
if (inv != null) {
result.add(inv);
@ -565,7 +565,7 @@ public class ExtendedAEPatternUploadUtil {
Set<TileAssemblerMatrixBase> matrices = grid.getMachines(TileAssemblerMatrixBase.class);
int idx = 0;
for (TileAssemblerMatrixBase tile : matrices) {
if (tile != null && tile.isFormed()) {
if (tile != null && tile.isFormed() && clusterHasSingleUploadCore(tile)) {
var capOpt = tile.getCapability(ForgeCapabilities.ITEM_HANDLER, null);
if (capOpt != null) {
var handler = capOpt.orElse(null);
@ -631,6 +631,28 @@ public class ExtendedAEPatternUploadUtil {
return false;
}
/**
* 判断给定矩阵集群中是否存在且仅存在一个装配矩阵上传核心
* 传入任意属于该集群的 Tile Pattern/Crafter/Frame
*/
private static boolean clusterHasSingleUploadCore(TileAssemblerMatrixBase any) {
try {
if (any == null || any.getCluster() == null) return false;
int cores = 0;
var it = any.getCluster().getBlockEntities();
while (it.hasNext()) {
var te = it.next();
if (te instanceof com.extendedae_plus.content.matrix.UploadCoreBlockEntity) {
cores++;
if (cores > 1) return false; // 至多一个
}
}
return cores == 1; // 恰好一个
} catch (Throwable t) {
return false;
}
}
/**
* 检查当前菜单是否为ExtendedAE的扩展样板管理终端
*