超级装配矩阵合成核心
This commit is contained in:
parent
a8bdefba31
commit
6580173e71
|
|
@ -9,6 +9,7 @@ import appeng.items.parts.PartModelsHelper;
|
|||
import com.extendedae_plus.api.ids.EAPComponents;
|
||||
import com.extendedae_plus.api.storage.InfinityBigIntegerCellHandler;
|
||||
import com.extendedae_plus.config.ModConfigs;
|
||||
import com.extendedae_plus.content.matrix.CrafterCorePlusBlockEntity;
|
||||
import com.extendedae_plus.content.matrix.SpeedCorePlusBlockEntity;
|
||||
import com.extendedae_plus.init.*;
|
||||
import com.extendedae_plus.util.storage.InfinityStorageManager;
|
||||
|
|
@ -159,6 +160,13 @@ public class ExtendedAEPlus {
|
|||
null
|
||||
);
|
||||
|
||||
ModBlocks.ASSEMBLER_MATRIX_CRAFTER_PLUS.get().setBlockEntity(
|
||||
CrafterCorePlusBlockEntity.class,
|
||||
ModBlockEntities.ASSEMBLER_MATRIX_CRAFTER_PLUS_BE.get(),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
LOGGER.info("Bound UploadCoreBlockEntity to assembler matrix upload core block.");
|
||||
} catch (Throwable t) {
|
||||
LOGGER.warn("Failed to bind block entities: {}", t.toString());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.extendedae_plus.content.matrix;
|
||||
|
||||
import com.extendedae_plus.init.ModItems;
|
||||
import com.glodblock.github.extendedae.common.blocks.matrix.BlockAssemblerMatrixBase;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public class CrafterCorePlusBlock extends BlockAssemblerMatrixBase<CrafterCorePlusBlockEntity> {
|
||||
|
||||
public CrafterCorePlusBlock(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPresentItem() {
|
||||
return ModItems.ASSEMBLER_MATRIX_CRAFTER_PLUS.get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
package com.extendedae_plus.content.matrix;
|
||||
|
||||
import appeng.api.crafting.IPatternDetails;
|
||||
import appeng.api.inventories.InternalInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.stacks.GenericStack;
|
||||
import appeng.api.stacks.KeyCounter;
|
||||
import appeng.util.inv.AppEngInternalInventory;
|
||||
import appeng.util.inv.CombinedInternalInventory;
|
||||
import com.extendedae_plus.init.ModBlockEntities;
|
||||
import com.glodblock.github.extendedae.common.me.CraftingMatrixThread;
|
||||
import com.glodblock.github.extendedae.common.me.CraftingThread;
|
||||
import com.glodblock.github.extendedae.common.me.matrix.ClusterAssemblerMatrix;
|
||||
import com.glodblock.github.extendedae.common.tileentities.matrix.TileAssemblerMatrixCrafter;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CrafterCorePlusBlockEntity extends TileAssemblerMatrixCrafter {
|
||||
|
||||
public static final int MAX_THREAD = 32;
|
||||
|
||||
// 自己的 32 线程与合并库存,不影响父类原来的 8 线程逻辑
|
||||
private final CraftingThread[] plusThreads = new CraftingThread[MAX_THREAD];
|
||||
private final InternalInventory plusInternalInv;
|
||||
private int plusStates = 0;
|
||||
|
||||
public CrafterCorePlusBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
super(pos, blockState);
|
||||
// 替换为自己的 32 线程实现
|
||||
var inventories = new InternalInventory[MAX_THREAD];
|
||||
for (int x = 0; x < MAX_THREAD; x++) {
|
||||
final int index = x;
|
||||
this.plusThreads[index] = new CraftingMatrixThread(this, this::getSrc, signal -> this.changeState(index, signal));
|
||||
inventories[index] = this.plusThreads[index].getInternalInventory();
|
||||
}
|
||||
this.plusInternalInv = new CombinedInternalInventory(inventories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockEntityType<?> getType() {
|
||||
return ModBlockEntities.ASSEMBLER_MATRIX_CRAFTER_PLUS_BE.get();
|
||||
}
|
||||
|
||||
private IActionSource getSrc() {
|
||||
return this.cluster == null ? null : this.cluster.getSrc();
|
||||
}
|
||||
|
||||
private void changeState(int index, boolean state) {
|
||||
boolean oldState = this.plusStates > 0;
|
||||
if (state) {
|
||||
this.plusStates |= (1 << index);
|
||||
} else {
|
||||
this.plusStates &= ~(1 << index);
|
||||
}
|
||||
if (state) {
|
||||
if (!oldState) {
|
||||
this.getMainNode().ifPresent((grid, node) -> grid.getTickManager().wakeDevice(node));
|
||||
}
|
||||
} else if (oldState && this.plusStates <= 0) {
|
||||
this.getMainNode().ifPresent((grid, node) -> grid.getTickManager().sleepDevice(node));
|
||||
}
|
||||
}
|
||||
|
||||
public int usedThread() {
|
||||
int cnt = 0;
|
||||
for (var t : this.plusThreads) {
|
||||
if (t.getCurrentPattern() != null) {
|
||||
cnt++;
|
||||
} else if (!t.getInternalInventory().isEmpty()) {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
// 向集群汇报时仍然受原版 8 线程上限限制,避免破坏 Cluster 逻辑
|
||||
double scale = (double) TileAssemblerMatrixCrafter.MAX_THREAD / MAX_THREAD;
|
||||
int reported = (int) Math.ceil(cnt * scale);
|
||||
return Math.min(TileAssemblerMatrixCrafter.MAX_THREAD, reported);
|
||||
}
|
||||
|
||||
public boolean pushJob(IPatternDetails patternDetails, KeyCounter[] inputHolder) {
|
||||
for (var thread : this.plusThreads) {
|
||||
if (thread.acceptJob(patternDetails, inputHolder, Direction.DOWN)) {
|
||||
if (this.cluster != null) {
|
||||
this.cluster.updateCrafter(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
for (var thread : this.plusThreads) {
|
||||
thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAdditional(CompoundTag data, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(data, registries);
|
||||
for (int x = 0; x < MAX_THREAD; x++) {
|
||||
var tag = this.plusThreads[x].writeNBT(registries);
|
||||
data.put("#ct" + x, tag);
|
||||
}
|
||||
final CompoundTag opt = new CompoundTag();
|
||||
for (int x = 0; x < this.plusInternalInv.size(); x++) {
|
||||
var is = this.plusInternalInv.getStackInSlot(x);
|
||||
opt.put("item" + x, is.saveOptional(registries));
|
||||
}
|
||||
data.put("inv", opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadTag(CompoundTag data, HolderLookup.Provider registries) {
|
||||
super.loadTag(data, registries);
|
||||
for (int x = 0; x < MAX_THREAD; x++) {
|
||||
if (data.contains("#ct" + x)) {
|
||||
this.plusThreads[x].readNBT(data.getCompound("#ct" + x), registries);
|
||||
}
|
||||
}
|
||||
var opt = data.getCompound("inv");
|
||||
for (int x = 0; x < this.plusInternalInv.size(); x++) {
|
||||
var item = opt.getCompound("item" + x);
|
||||
this.plusInternalInv.setItemDirect(x, ItemStack.parseOptional(registries, item));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ClusterAssemblerMatrix cluster) {
|
||||
// 保持父类期望的类型:集群内部还是按 TileAssemblerMatrixCrafter 来管理
|
||||
cluster.addCrafter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
var isAwake = false;
|
||||
for (var t : this.plusThreads) {
|
||||
t.recalculatePlan();
|
||||
t.updateSleepiness();
|
||||
isAwake |= t.isAwake();
|
||||
}
|
||||
return new TickingRequest(1, 1, !isAwake);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
if (this.cluster == null) {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
var rate = TickRateModulation.SLEEP;
|
||||
for (var t : this.plusThreads) {
|
||||
if (t.isAwake()) {
|
||||
var tr = t.tick(this.cluster.getSpeedCore(), ticksSinceLastCall);
|
||||
if (tr.ordinal() > rate.ordinal()) {
|
||||
rate = tr;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cluster.updateCrafter(this);
|
||||
return rate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChangedInventory(AppEngInternalInventory inv) {
|
||||
for (var t : this.plusThreads) {
|
||||
if (inv == t.getInternalInventory()) {
|
||||
t.recalculatePlan();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.saveChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(AppEngInternalInventory inv, int slot) {
|
||||
this.saveChangedInventory(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdditionalDrops(Level level, BlockPos pos, List<ItemStack> drops) {
|
||||
super.addAdditionalDrops(level, pos, drops);
|
||||
for (var stack : this.plusInternalInv) {
|
||||
var genericStack = GenericStack.unwrapItemStack(stack);
|
||||
if (genericStack != null) {
|
||||
genericStack.what().addDrops(genericStack.amount(), drops, level, pos);
|
||||
} else {
|
||||
drops.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
super.clearContent();
|
||||
this.plusInternalInv.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
package com.extendedae_plus.init;
|
||||
|
||||
import com.extendedae_plus.ExtendedAEPlus;
|
||||
import com.extendedae_plus.content.matrix.CrafterCorePlusBlockEntity;
|
||||
import com.extendedae_plus.content.matrix.SpeedCorePlusBlockEntity;
|
||||
import com.extendedae_plus.content.wireless.WirelessTransceiverBlockEntity;
|
||||
import com.extendedae_plus.content.controller.NetworkPatternControllerBlockEntity;
|
||||
import com.extendedae_plus.content.matrix.UploadCoreBlockEntity;
|
||||
import appeng.blockentity.crafting.CraftingBlockEntity;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
|
|
@ -56,4 +58,10 @@ public final class ModBlockEntities {
|
|||
BLOCK_ENTITY_TYPES.register("assembler_matrix_speed_plus",
|
||||
()->BlockEntityType.Builder.of(SpeedCorePlusBlockEntity::new,
|
||||
ModBlocks.ASSEMBLER_MATRIX_SPEED_PLUS.get()).build(null));
|
||||
|
||||
//超级装配矩阵合成核心
|
||||
public static final DeferredHolder<BlockEntityType<?>,BlockEntityType<CrafterCorePlusBlockEntity>> ASSEMBLER_MATRIX_CRAFTER_PLUS_BE=
|
||||
BLOCK_ENTITY_TYPES.register("assembler_matrix_crafter_plus",
|
||||
()-> BlockEntityType.Builder.of(CrafterCorePlusBlockEntity::new,
|
||||
ModBlocks.ASSEMBLER_MATRIX_CRAFTER_PLUS.get()).build(null));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.extendedae_plus.init;
|
|||
|
||||
import com.extendedae_plus.ExtendedAEPlus;
|
||||
import com.extendedae_plus.content.controller.NetworkPatternControllerBlock;
|
||||
import com.extendedae_plus.content.matrix.CrafterCorePlusBlock;
|
||||
import com.extendedae_plus.content.matrix.SpeedCorePlusBlock;
|
||||
import com.extendedae_plus.content.wireless.WirelessTransceiverBlock;
|
||||
import com.extendedae_plus.content.crafting.EPlusCraftingUnitType;
|
||||
|
|
@ -95,4 +96,12 @@ public final class ModBlocks {
|
|||
.requiresCorrectToolForDrops()
|
||||
)
|
||||
);
|
||||
public static final DeferredBlock<CrafterCorePlusBlock> ASSEMBLER_MATRIX_CRAFTER_PLUS = BLOCKS.register(
|
||||
"assembler_matrix_crafter_plus",
|
||||
() -> new CrafterCorePlusBlock(
|
||||
BlockBehaviour.Properties.of()
|
||||
.strength(1.5F,6.0F)
|
||||
.requiresCorrectToolForDrops()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ public final class ModCreativeTabs {
|
|||
ModItems.VIRTUAL_CRAFTING_CARD.get().getDefaultInstance(),
|
||||
ModItems.ENTITY_TICKER_PART_ITEM.get().getDefaultInstance(),
|
||||
ModItems.INFINITY_BIGINTEGER_CELL_ITEM.get().getDefaultInstance(),
|
||||
ModItems.ASSEMBLER_MATRIX_SPEED_PLUS.get().getDefaultInstance()
|
||||
ModItems.ASSEMBLER_MATRIX_SPEED_PLUS.get().getDefaultInstance(),
|
||||
ModItems.ASSEMBLER_MATRIX_CRAFTER_PLUS.get().getDefaultInstance()
|
||||
).forEach(output::accept);
|
||||
|
||||
// 放入四个预设的 stacks(x2,x4,x8,x16),使用 ModItems 工厂创建
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ public final class ModItems {
|
|||
"assembler_matrix_speed_plus",
|
||||
()->new BlockItem(ModBlocks.ASSEMBLER_MATRIX_SPEED_PLUS.get(), new Item.Properties())
|
||||
);
|
||||
public static final DeferredItem<Item> ASSEMBLER_MATRIX_CRAFTER_PLUS = ITEMS.register(
|
||||
"assembler_matrix_crafter_plus",
|
||||
()->new BlockItem(ModBlocks.ASSEMBLER_MATRIX_CRAFTER_PLUS.get(), new Item.Properties())
|
||||
);
|
||||
static final DeferredItem<Item> NETWORK_PATTERN_CONTROLLER = ITEMS.register(
|
||||
"network_pattern_controller",
|
||||
() -> new BlockItem(ModBlocks.NETWORK_PATTERN_CONTROLLER.get(), new Item.Properties())
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"extendedae_plus:64x_crafting_accelerator",
|
||||
"extendedae_plus:256x_crafting_accelerator",
|
||||
"extendedae_plus:1024x_crafting_accelerator",
|
||||
"extendedae_plus:assembler_matrix_speed_plus"
|
||||
"extendedae_plus:assembler_matrix_speed_plus",
|
||||
"extendedae_plus:assembler_matrix_crafter_plus"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"extendedae_plus:64x_crafting_accelerator",
|
||||
"extendedae_plus:256x_crafting_accelerator",
|
||||
"extendedae_plus:1024x_crafting_accelerator",
|
||||
"extendedae_plus:assembler_matrix_speed_plus"
|
||||
"extendedae_plus:assembler_matrix_speed_plus",
|
||||
"extendedae_plus:assembler_matrix_crafter_plus"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user