Skip to content

Commit 6091645

Browse files
committed
GUI Fix; Add ParallelController TOP support.
1 parent 89ab435 commit 6091645

File tree

9 files changed

+61
-26
lines changed

9 files changed

+61
-26
lines changed

src/main/java/hellfirepvp/modularmachinery/ModularMachinery.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737
@Mod(modid = ModularMachinery.MODID, name = ModularMachinery.NAME, version = ModularMachinery.VERSION,
3838
dependencies = "required-after:forge@[14.21.0.2371,);after:crafttweaker@[4.0.4,);after:jei@[4.13.1.222,)",
39-
certificateFingerprint = "a0f0b759d895c15ceb3e3bcb5f3c2db7c582edf0",
4039
acceptedMinecraftVersions = "[1.12, 1.13)"
4140
)
4241
public class ModularMachinery {

src/main/java/hellfirepvp/modularmachinery/client/gui/GuiMachineController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,13 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
152152
String progressStr = I18n.format("gui.controller.status.crafting.progress", progress + "%");
153153
fr.drawStringWithShadow(progressStr, offsetX, offsetY, 0xFFFFFF);
154154
}
155+
155156
int parallelism = activeRecipe.getParallelism();
157+
int maxParallelism = activeRecipe.getMaxParallelism();
156158
if (parallelism > 1) {
157-
offsetY += 10;
159+
offsetY += 15;
158160
String parallelismStr = I18n.format("gui.controller.parallelism", parallelism);
159161
fr.drawStringWithShadow(parallelismStr, offsetX, offsetY, 0xFFFFFF);
160-
}
161-
int maxParallelism = activeRecipe.getMaxParallelism();
162-
if (maxParallelism > 1) {
163162
offsetY += 10;
164163
String maxParallelismStr = I18n.format("gui.controller.max_parallelism", maxParallelism);
165164
fr.drawStringWithShadow(maxParallelismStr, offsetX, offsetY, 0xFFFFFF);

src/main/java/hellfirepvp/modularmachinery/common/data/Config.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232
public class Config {
3333
public static boolean mocCompatibleMode = false;
34+
public static boolean onlyOneMachineController = false;
3435
public static boolean disableMocDeprecatedTip = false;
3536
public static int machineColor;
3637
public static boolean selectiveUpdateTileEntity = false;
@@ -76,6 +77,8 @@ private static void load() {
7677
mocCompatibleMode = lastReadConfig.getBoolean(
7778
"modular-controller-compatible-mode", "general", false,
7879
"When enabled, the mod registers a controller block under the name modularcontroller to prevent incompatibility with older saves.");
80+
onlyOneMachineController = lastReadConfig.getBoolean("only-one-machine-controller", "general", false,
81+
"When enabled, Modules no longer register a separate controller for each machine, and the modular-controller-compatible-mode option is turned off.");
7982
disableMocDeprecatedTip = lastReadConfig.getBoolean(
8083
"disable-moc-deprecated-tip", "general", false,
8184
"Disable the ModularController is deprecated tooltip.");

src/main/java/hellfirepvp/modularmachinery/common/integration/ModIntegrationTOP.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package hellfirepvp.modularmachinery.common.integration;
22

3-
import hellfirepvp.modularmachinery.common.integration.theoneprobe.DynamicMachineInfoProvider;
3+
import hellfirepvp.modularmachinery.common.integration.theoneprobe.MMInfoProvider;
44
import mcjty.theoneprobe.TheOneProbe;
55
import mcjty.theoneprobe.apiimpl.TheOneProbeImp;
66
import net.minecraftforge.common.config.Configuration;
@@ -11,11 +11,12 @@ public class ModIntegrationTOP {
1111
public static int recipeProgressBarBorderColor = 0xCC43CD80;
1212
public static int recipeProgressBarBackgroundColor = 0xFF000000;
1313
public static boolean showRecipeProgressBarDecimalPoints = true;
14+
public static boolean showParallelControllerInfo = true;
1415

1516
public static void registerProvider() {
1617
TheOneProbeImp top = TheOneProbe.theOneProbeImp;
1718

18-
top.registerProvider(new DynamicMachineInfoProvider());
19+
top.registerProvider(new MMInfoProvider());
1920
}
2021

2122
public static void loadFromConfig(Configuration cfg) {
@@ -41,5 +42,7 @@ public static void loadFromConfig(Configuration cfg) {
4142
showRecipeProgressBarDecimalPoints = cfg.getBoolean("SHOW_RECIPE_PROGRESSBAR_DECIMAL_POINTS",
4243
"display.theoneprobe", true,
4344
"Show recipe progressbar decimal points if TheOneProbe mod is installed.");
45+
showParallelControllerInfo = cfg.getBoolean("SHOW_PARALLEL_CONTROLLER_INFO", "display.theoneprobe",
46+
true, "Show parallel controller info if TheOneProbe mod is installed.");
4447
}
4548
}

src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/DynamicMachineInfoProvider.java renamed to src/main/java/hellfirepvp/modularmachinery/common/integration/theoneprobe/MMInfoProvider.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import hellfirepvp.modularmachinery.common.crafting.ActiveMachineRecipe;
44
import hellfirepvp.modularmachinery.common.integration.ModIntegrationTOP;
55
import hellfirepvp.modularmachinery.common.tiles.TileMachineController;
6+
import hellfirepvp.modularmachinery.common.tiles.TileParallelController;
67
import mcjty.theoneprobe.api.*;
78
import net.minecraft.block.state.IBlockState;
89
import net.minecraft.entity.player.EntityPlayer;
910
import net.minecraft.tileentity.TileEntity;
1011
import net.minecraft.util.text.TextFormatting;
1112
import net.minecraft.world.World;
1213

13-
public class DynamicMachineInfoProvider implements IProbeInfoProvider {
14+
public class MMInfoProvider implements IProbeInfoProvider {
1415
@Override
1516
public String getID() {
1617
return "modularmachinery:dynamic_machine_info_provider";
@@ -24,18 +25,38 @@ public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer play
2425
TileEntity tileEntity = world.getTileEntity(data.getPos());
2526
if (tileEntity == null) return;
2627
//判断是否为机械控制器
27-
TileMachineController machine = tileEntity instanceof TileMachineController ? (TileMachineController) tileEntity : null;
28-
if (machine == null) return;
28+
if (tileEntity instanceof TileMachineController) {
29+
processMachineControllerTOP((TileMachineController) tileEntity, probeInfo, player);
30+
}
31+
if (tileEntity instanceof TileParallelController) {
32+
processParallelControllerTOP((TileParallelController) tileEntity, probeInfo);
33+
}
34+
}
35+
36+
private static void processParallelControllerTOP(TileParallelController parallelController, IProbeInfo probeInfo) {
37+
if (!ModIntegrationTOP.showParallelControllerInfo) {
38+
return;
39+
}
40+
TileParallelController.ParallelControllerProvider provider = parallelController.provideComponent();
41+
probeInfo.text(TextFormatting.AQUA + "{*top.parallelism*}" + TextFormatting.GREEN + provider.getParallelism());
42+
probeInfo.text(TextFormatting.GOLD + "{*top.max_parallelism*}" + TextFormatting.YELLOW + provider.getMaxParallelism());
43+
}
2944

45+
private static void processMachineControllerTOP(TileMachineController machine, IProbeInfo probeInfo, EntityPlayer player) {
3046
//是否在工作
31-
if (machine.hasActiveRecipe() && machine.getFoundMachine() != null) {
47+
if (machine.getActiveRecipe() != null && machine.getFoundMachine() != null) {
3248
probeInfo.text(TextFormatting.GREEN + "{*top.machine.working*}");
3349

3450
ActiveMachineRecipe activeRecipe = machine.getActiveRecipe();
3551
int tick = activeRecipe.getTick();
3652
int totalTick = activeRecipe.getTotalTick();
3753
float progress = (float) (tick * 100) / totalTick;
3854

55+
if (activeRecipe.getParallelism() > 1) {
56+
probeInfo.text(TextFormatting.AQUA + "{*top.parallelism*}" + TextFormatting.GREEN + activeRecipe.getParallelism());
57+
probeInfo.text(TextFormatting.GOLD + "{*top.max_parallelism*}" + TextFormatting.YELLOW + activeRecipe.getMaxParallelism());
58+
}
59+
3960
String progressStr;
4061
if (player.isSneaking()) {
4162
//如:20.5 秒 / 40.0 秒

src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ private static void registerTiles() {
113113
}
114114

115115
private static void registerCustomControllers() {
116+
if (Config.onlyOneMachineController) {
117+
return;
118+
}
116119
List<DynamicMachine> waitForLoadMachines = MachineRegistry.getWaitForLoadMachines();
117120
for (MachineBuilder builder : MachineBuilder.PRE_LOAD_MACHINES.values()) {
118121
waitForLoadMachines.add(builder.getMachine());

src/main/java/hellfirepvp/modularmachinery/common/tiles/TileMachineController.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class TileMachineController extends TileEntityRestrictedTick implements I
8484
private final Map<String, RecipeModifier> customModifiers = new HashMap<>();
8585
private final Map<TileSmartInterface.SmartInterfaceProvider, String> foundSmartInterfaces = new HashMap<>();
8686
private final List<Tuple<MachineComponent<?>, ComponentSelectorTag>> foundComponents = new ArrayList<>();
87+
private final List<TileParallelController.ParallelControllerProvider> foundParallelControllers = new ArrayList<>();
8788
private BlockController parentController = null;
8889
private NBTTagCompound customData = new NBTTagCompound();
8990
private CraftingStatus craftingStatus = CraftingStatus.MISSING_STRUCTURE;
@@ -698,11 +699,8 @@ private boolean matchesRotation(TaggedPositionBlockArray pattern, DynamicMachine
698699

699700
public int getMaxParallelism() {
700701
int parallelism = 0;
701-
for (Tuple<MachineComponent<?>, ComponentSelectorTag> foundComponent : foundComponents) {
702-
if (foundComponent.getFirst() instanceof TileParallelController.ParallelControllerProvider) {
703-
TileParallelController.ParallelControllerProvider provider = (TileParallelController.ParallelControllerProvider) foundComponent.getFirst();
704-
parallelism += provider.getParallelism();
705-
}
702+
for (TileParallelController.ParallelControllerProvider provider : foundParallelControllers) {
703+
parallelism += provider.getParallelism();
706704
}
707705
return Math.min(Math.max(1, parallelism), foundMachine.getMaxParallelism());
708706
}
@@ -722,6 +720,7 @@ private void updateComponents() {
722720

723721
this.foundComponents.clear();
724722
this.foundSmartInterfaces.clear();
723+
this.foundParallelControllers.clear();
725724
for (BlockPos potentialPosition : this.foundPattern.getPattern().keySet()) {
726725
BlockPos realPos = getPos().add(potentialPosition);
727726
TileEntity te = getWorld().getTileEntity(realPos);
@@ -737,6 +736,11 @@ private void updateComponents() {
737736

738737
this.foundComponents.add(new Tuple<>(component, tag));
739738

739+
if (component instanceof TileParallelController.ParallelControllerProvider) {
740+
this.foundParallelControllers.add((TileParallelController.ParallelControllerProvider) component);
741+
continue;
742+
}
743+
740744
if (!(component instanceof TileSmartInterface.SmartInterfaceProvider) || foundMachine.smartInterfaceTypesIsEmpty()) {
741745
continue;
742746
}
@@ -877,7 +881,15 @@ public void readCustomNBT(NBTTagCompound compound) {
877881
} else {
878882
this.craftingStatus = CraftingStatus.deserialize(compound.getCompoundTag("statusTag"));
879883
}
880-
884+
if (compound.hasKey("parentMachine")) {
885+
ResourceLocation rl = new ResourceLocation(compound.getString("parentMachine"));
886+
parentMachine = MachineRegistry.getRegistry().getMachine(rl);
887+
if (parentMachine != null) {
888+
parentController = BlockController.MACHINE_CONTROLLERS.get(parentMachine);
889+
} else {
890+
ModularMachinery.log.info("Couldn't find machine named " + rl + " for controller at " + getPos());
891+
}
892+
}
881893
if (compound.hasKey("machine") && compound.hasKey("rotation")) {
882894
ResourceLocation rl = new ResourceLocation(compound.getString("machine"));
883895
DynamicMachine machine = MachineRegistry.getRegistry().getMachine(rl);
@@ -913,15 +925,6 @@ public void readCustomNBT(NBTTagCompound compound) {
913925
} else {
914926
resetMachine(false);
915927
}
916-
if (compound.hasKey("parentMachine")) {
917-
ResourceLocation rl = new ResourceLocation(compound.getString("parentMachine"));
918-
parentMachine = MachineRegistry.getRegistry().getMachine(rl);
919-
if (parentMachine != null) {
920-
parentController = BlockController.MACHINE_CONTROLLERS.get(parentMachine);
921-
} else {
922-
ModularMachinery.log.info("Couldn't find machine named " + rl + " for controller at " + getPos());
923-
}
924-
}
925928
if (compound.hasKey("activeRecipe")) {
926929
NBTTagCompound tag = compound.getCompoundTag("activeRecipe");
927930
ActiveMachineRecipe recipe = new ActiveMachineRecipe(tag);

src/main/resources/assets/modularmachinery/lang/en_US.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ top.recipe.progress=Progress
4242
top.machine.working=Processing
4343
top.machine.structure.found=Structure formed
4444
top.machine.structure.none=Missing structure
45+
top.max_parallelism=Max Parallelism:
46+
top.parallelism=Parallelism:
4547

4648
craftcheck.failure.item.input=Missing input item!
4749
craftcheck.failure.item.output.space=Not enough inventory space for item output(s)!

src/main/resources/assets/modularmachinery/lang/zh_CN.lang

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ top.recipe.progress=进度
4545
top.machine.working=工作中
4646
top.machine.structure.found=结构已形成
4747
top.machine.structure.none=结构不完整
48+
top.max_parallelism=最大并行数:
49+
top.parallelism=并行数:
4850

4951
craftcheck.failure.item.input=缺少物品输入!
5052
craftcheck.failure.item.output.space=没有足够的库存空间用于物品输出!

0 commit comments

Comments
 (0)