无线收发器材质&自动上传适配超级样板核心
This commit is contained in:
parent
162b15a748
commit
bf5fe24f9e
|
|
@ -67,6 +67,11 @@ public class PatternCorePlusBlockEntity extends TileAssemblerMatrixPattern {
|
|||
return this.patternInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppEngInternalInventory getExposedInventory() {
|
||||
return this.patternInventory;
|
||||
}
|
||||
|
||||
public long getLocateID() {
|
||||
return this.worldPosition.asLong();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,16 +19,28 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class WirelessTransceiverBlock extends Block implements EntityBlock {
|
||||
|
||||
public static IntegerProperty STATE = IntegerProperty.create("state", 0, 5);
|
||||
|
||||
|
||||
public WirelessTransceiverBlock(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new WirelessTransceiverBlockEntity(pos, state);
|
||||
|
|
|
|||
|
|
@ -67,8 +67,40 @@ public class WirelessTransceiverBlockEntity extends AEBaseBlockEntity implements
|
|||
// 从端需要周期检查与维护连接
|
||||
be.slaveLink.updateStatus();
|
||||
}
|
||||
be.updateStates();
|
||||
}
|
||||
|
||||
public void updateStates() {
|
||||
if(this.level== null||this.level.isClientSide) return;
|
||||
IGridNode node = this.getGridNode();
|
||||
int states=5;
|
||||
|
||||
if (node != null&&node.isActive()) {
|
||||
int usedCount=0;
|
||||
for(var connection: node.getConnections()){
|
||||
usedCount=Math.max(usedCount,connection.getUsedChannels());
|
||||
}
|
||||
|
||||
if(usedCount>=32){
|
||||
states=4;
|
||||
}else if(usedCount>=24){
|
||||
states=3;
|
||||
}else if(usedCount>=16){
|
||||
states=2;
|
||||
}else if(usedCount>=8){
|
||||
states=1;
|
||||
}else if(usedCount>=0){
|
||||
states=0;
|
||||
}
|
||||
}
|
||||
|
||||
BlockState currentState=this.getBlockState();
|
||||
if(currentState.getValue(WirelessTransceiverBlock.STATE)!=states){
|
||||
this.level.setBlock(this.worldPosition,currentState.setValue(WirelessTransceiverBlock.STATE,states),3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===================== IInWorldGridNodeHost ===================== */
|
||||
@Override
|
||||
public @Nullable IGridNode getGridNode(Direction dir) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ import appeng.menu.implementations.PatternAccessTermMenu;
|
|||
import appeng.menu.me.items.PatternEncodingTermMenu;
|
||||
import appeng.util.inv.FilteredInternalInventory;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import com.extendedae_plus.content.matrix.PatternCorePlusBlockEntity;
|
||||
import com.extendedae_plus.mixin.ae2.accessor.PatternEncodingTermMenuAccessor;
|
||||
import com.glodblock.github.extendedae.common.me.matrix.ClusterAssemblerMatrix;
|
||||
import com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixPattern;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
|
|
@ -33,10 +36,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
|
|
@ -521,17 +521,46 @@ public class ExtendedAEPatternUploadUtil {
|
|||
*/
|
||||
private static List<InternalInventory> findAllMatrixPatternInventories(IGrid grid) {
|
||||
List<InternalInventory> result = new ArrayList<>();
|
||||
if(grid== null) return result;
|
||||
try {
|
||||
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() && clusterHasSingleUploadCore(tile)) {
|
||||
var inv = tile.getExposedInventory();
|
||||
Set<TileAssemblerMatrixPattern> allTiles = grid.getMachines(TileAssemblerMatrixPattern.class);
|
||||
Set<PatternCorePlusBlockEntity> myAllTiles = grid.getMachines(PatternCorePlusBlockEntity.class);
|
||||
|
||||
// 用 Set 记录已经扫描过的集群,避免重复调用 clusterHasSingleUploadCore
|
||||
Set<ClusterAssemblerMatrix> scannedClusters = new HashSet<>();
|
||||
|
||||
for (TileAssemblerMatrixPattern tile : allTiles) {
|
||||
if (tile == null || !tile.isFormed() || !tile.getMainNode().isActive()) continue;
|
||||
|
||||
ClusterAssemblerMatrix cluster = tile.getCluster();
|
||||
if (cluster == null) continue;
|
||||
|
||||
// 如果该集群已经扫描过,或者该集群含 UploadCore,则处理 tile
|
||||
if (scannedClusters.contains(cluster) || clusterHasSingleUploadCore(cluster)) {
|
||||
scannedClusters.add(cluster); // 标记为已扫描
|
||||
|
||||
InternalInventory inv = tile.getExposedInventory();
|
||||
if (inv != null) {
|
||||
result.add(inv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PatternCorePlusBlockEntity myTile : myAllTiles) {
|
||||
if (myTile == null || !myTile.isFormed() || !myTile.getMainNode().isActive()) continue;
|
||||
|
||||
ClusterAssemblerMatrix cluster = myTile.getCluster();
|
||||
if (cluster == null) continue;
|
||||
|
||||
// 如果该集群已经扫描过,或者该集群含 UploadCore,则处理 tile
|
||||
if (scannedClusters.contains(cluster) || clusterHasSingleUploadCore(cluster)) {
|
||||
scannedClusters.add(cluster); // 标记为已扫描
|
||||
|
||||
InternalInventory inv = myTile.getExposedInventory();
|
||||
if (inv != null) {
|
||||
result.add(inv);
|
||||
}
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
|
|
@ -1170,11 +1199,11 @@ public class ExtendedAEPatternUploadUtil {
|
|||
* 要求:至少存在 1 个即可,不限制数量。
|
||||
* 传入任意属于该集群的 Tile(如 Pattern/Crafter/Frame 等)。
|
||||
*/
|
||||
private static boolean clusterHasSingleUploadCore(com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixBase any) {
|
||||
private static boolean clusterHasSingleUploadCore(ClusterAssemblerMatrix any) {
|
||||
try {
|
||||
if (any == null || any.getCluster() == null) return false;
|
||||
if (any == null) return false;
|
||||
int cores = 0;
|
||||
var it = any.getCluster().getBlockEntities();
|
||||
var it = any.getBlockEntities();
|
||||
while (it.hasNext()) {
|
||||
var te = it.next();
|
||||
if (te instanceof com.extendedae_plus.content.matrix.UploadCoreBlockEntity) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
{
|
||||
"variants": {
|
||||
"state=0": { "model": "extendedae_plus:block/wirelesstransceiver/wireless_transceiver_0" },
|
||||
"state=1": { "model": "extendedae_plus:block/wirelesstransceiver/wireless_transceiver_1" },
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user