Skip to content

Commit cde374b

Browse files
committed
- public methods...
- Internal changes.
1 parent 946b217 commit cde374b

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

src/main/java/github/kasuminova/mmce/common/helper/MachineController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MachineController {
2222
* @return 如果无控制器则返回 null,否则返回 IMachineController 实例。
2323
*/
2424
@ZenMethod
25-
static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) {
25+
public static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) {
2626
World world = CraftTweakerMC.getWorld(worldCT);
2727
BlockPos pos = CraftTweakerMC.getBlockPos(posCT);
2828
if (world == null || pos == null || !world.isBlockLoaded(pos)) {
@@ -40,7 +40,7 @@ static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) {
4040
* @return 如果无控制器则返回 null,否则返回 IMachineController 实例。
4141
*/
4242
@ZenMethod
43-
static IMachineController getControllerAt(IWorld worldCT, int x, int y, int z) {
43+
public static IMachineController getControllerAt(IWorld worldCT, int x, int y, int z) {
4444
World world = CraftTweakerMC.getWorld(worldCT);
4545
BlockPos pos = new BlockPos(x, y, z);
4646

src/main/java/github/kasuminova/mmce/common/world/MachineComponentManager.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import github.kasuminova.mmce.common.util.concurrent.ExecuteGroup;
55
import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
66
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
7+
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
78
import net.minecraft.tileentity.TileEntity;
89
import net.minecraft.util.math.BlockPos;
910
import net.minecraft.world.World;
@@ -43,10 +44,10 @@ public void checkComponentShared(TileEntity component, TileMultiblockMachineCont
4344
Map<BlockPos, ComponentInfo> posComponentMap = componentMap.computeIfAbsent(world, v -> new ConcurrentHashMap<>());
4445

4546
ComponentInfo info = posComponentMap.computeIfAbsent(pos, v -> new ComponentInfo(
46-
component, pos, new ObjectArraySet<>(Collections.singleton(ctrl))));
47+
component, pos, new ReferenceOpenHashSet<>(Collections.singleton(ctrl))));
4748

4849
if (!info.areTileEntityEquals(component)) {
49-
ComponentInfo newInfo = new ComponentInfo(component, pos, new ObjectArraySet<>(Collections.singleton(ctrl)));
50+
ComponentInfo newInfo = new ComponentInfo(component, pos, new ReferenceOpenHashSet<>(Collections.singleton(ctrl)));
5051
posComponentMap.put(pos, newInfo);
5152
return;
5253
}
@@ -62,20 +63,13 @@ public void checkComponentShared(TileEntity component, TileMultiblockMachineCont
6263
return;
6364
}
6465

65-
long groupId = -1;
66-
for (final TileMultiblockMachineController owner : owners) {
67-
if (owner.getExecuteGroupId() != -1) {
68-
groupId = owner.getExecuteGroupId();
69-
}
70-
}
71-
72-
if (groupId == -1) {
73-
groupId = ExecuteGroup.newGroupId();
74-
}
66+
long groupId = owners.stream()
67+
.filter(owner -> owner.getExecuteGroupId() != -1)
68+
.findFirst()
69+
.map(TileMultiblockMachineController::getExecuteGroupId)
70+
.orElse(ExecuteGroup.newGroupId());
7571

76-
for (final TileMultiblockMachineController owner : owners) {
77-
owner.setExecuteGroupId(groupId);
78-
}
72+
owners.forEach(owner -> owner.setExecuteGroupId(groupId));
7973
}
8074
}
8175

src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ TextFormatting.AQUA, formatCPUUsage(machine.getTimeRecorder().usedTimeAvg()),
109109
TextFormatting.AQUA, formatRecipeSearchUsage(machine.getTimeRecorder().recipeSearchUsedTimeAvg())));
110110
TileMultiblockMachineController.WorkMode workMode = machine.getWorkMode();
111111
long groupId = machine.getExecuteGroupId();
112-
if (workMode == TileMultiblockMachineController.WorkMode.ASYNC && groupId != 0) {
112+
if (workMode == TileMultiblockMachineController.WorkMode.ASYNC && groupId != -1) {
113113
perfBox.text(String.format("%sWorkMode: %s (GroupID: %s)", TextFormatting.AQUA, workMode.getDisplayName(), groupId));
114114
} else {
115115
perfBox.text(String.format("%sWorkMode: %s", TextFormatting.AQUA, workMode.getDisplayName()));

src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ protected void checkAllPatterns() {
671671

672672
protected void updateComponents() {
673673
if (this.foundMachine == null || this.foundPattern == null || this.controllerRotation == null || this.foundReplacements == null) {
674+
this.foundComponents.forEach((te, component) -> MachineComponentManager.INSTANCE.removeOwner(te, this));
674675
this.foundComponents.clear();
675676
this.foundModifiers.clear();
676677
this.foundSmartInterfaces.clear();
@@ -684,6 +685,7 @@ protected void updateComponents() {
684685

685686
this.foundUpgrades.clear();
686687
this.foundUpgradeBuses.clear();
688+
this.foundComponents.forEach((te, component) -> MachineComponentManager.INSTANCE.removeOwner(te, this));
687689
this.foundComponents.clear();
688690
this.foundSmartInterfaces.clear();
689691
this.foundParallelControllers.clear();

0 commit comments

Comments
 (0)