diff --git a/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java b/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java index fc796c37..a9cb5a50 100644 --- a/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java +++ b/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java @@ -22,7 +22,7 @@ public class MachineController { * @return 如果无控制器则返回 null,否则返回 IMachineController 实例。 */ @ZenMethod - static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) { + public static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) { World world = CraftTweakerMC.getWorld(worldCT); BlockPos pos = CraftTweakerMC.getBlockPos(posCT); if (world == null || pos == null || !world.isBlockLoaded(pos)) { @@ -40,7 +40,7 @@ static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) { * @return 如果无控制器则返回 null,否则返回 IMachineController 实例。 */ @ZenMethod - static IMachineController getControllerAt(IWorld worldCT, int x, int y, int z) { + public static IMachineController getControllerAt(IWorld worldCT, int x, int y, int z) { World world = CraftTweakerMC.getWorld(worldCT); BlockPos pos = new BlockPos(x, y, z); diff --git a/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java b/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java index 04aca76a..6faec172 100644 --- a/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java +++ b/src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java @@ -4,6 +4,7 @@ import github.kasuminova.mmce.common.util.concurrent.ExecuteGroup; import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController; import it.unimi.dsi.fastutil.objects.ObjectArraySet; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -43,10 +44,10 @@ public void checkComponentShared(TileEntity component, TileMultiblockMachineCont Map posComponentMap = componentMap.computeIfAbsent(world, v -> new ConcurrentHashMap<>()); ComponentInfo info = posComponentMap.computeIfAbsent(pos, v -> new ComponentInfo( - component, pos, new ObjectArraySet<>(Collections.singleton(ctrl)))); + component, pos, new ReferenceOpenHashSet<>(Collections.singleton(ctrl)))); if (!info.areTileEntityEquals(component)) { - ComponentInfo newInfo = new ComponentInfo(component, pos, new ObjectArraySet<>(Collections.singleton(ctrl))); + ComponentInfo newInfo = new ComponentInfo(component, pos, new ReferenceOpenHashSet<>(Collections.singleton(ctrl))); posComponentMap.put(pos, newInfo); return; } @@ -62,20 +63,13 @@ public void checkComponentShared(TileEntity component, TileMultiblockMachineCont return; } - long groupId = -1; - for (final TileMultiblockMachineController owner : owners) { - if (owner.getExecuteGroupId() != -1) { - groupId = owner.getExecuteGroupId(); - } - } - - if (groupId == -1) { - groupId = ExecuteGroup.newGroupId(); - } + long groupId = owners.stream() + .filter(owner -> owner.getExecuteGroupId() != -1) + .findFirst() + .map(TileMultiblockMachineController::getExecuteGroupId) + .orElse(ExecuteGroup.newGroupId()); - for (final TileMultiblockMachineController owner : owners) { - owner.setExecuteGroupId(groupId); - } + owners.forEach(owner -> owner.setExecuteGroupId(groupId)); } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java index ba7b6a23..7f82a774 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java @@ -109,7 +109,7 @@ TextFormatting.AQUA, formatCPUUsage(machine.getTimeRecorder().usedTimeAvg()), TextFormatting.AQUA, formatRecipeSearchUsage(machine.getTimeRecorder().recipeSearchUsedTimeAvg()))); TileMultiblockMachineController.WorkMode workMode = machine.getWorkMode(); long groupId = machine.getExecuteGroupId(); - if (workMode == TileMultiblockMachineController.WorkMode.ASYNC && groupId != 0) { + if (workMode == TileMultiblockMachineController.WorkMode.ASYNC && groupId != -1) { perfBox.text(String.format("%sWorkMode: %s (GroupID: %s)", TextFormatting.AQUA, workMode.getDisplayName(), groupId)); } else { perfBox.text(String.format("%sWorkMode: %s", TextFormatting.AQUA, workMode.getDisplayName())); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java index 6226184f..c69d28fa 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java @@ -671,6 +671,7 @@ protected void checkAllPatterns() { protected void updateComponents() { if (this.foundMachine == null || this.foundPattern == null || this.controllerRotation == null || this.foundReplacements == null) { + this.foundComponents.forEach((te, component) -> MachineComponentManager.INSTANCE.removeOwner(te, this)); this.foundComponents.clear(); this.foundModifiers.clear(); this.foundSmartInterfaces.clear(); @@ -684,6 +685,7 @@ protected void updateComponents() { this.foundUpgrades.clear(); this.foundUpgradeBuses.clear(); + this.foundComponents.forEach((te, component) -> MachineComponentManager.INSTANCE.removeOwner(te, this)); this.foundComponents.clear(); this.foundSmartInterfaces.clear(); this.foundParallelControllers.clear();