Skip to content

Commit 03e6158

Browse files
committed
Supports FluxNetworks, Allow maximum energy transfer over Integer.MAX_VALUE; Fixed item bus counter not working properly; TheOneProbe now displays a red progress bar (customizable) when it fails mid-run.
1 parent 97ee551 commit 03e6158

File tree

14 files changed

+264
-51
lines changed

14 files changed

+264
-51
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'net.minecraftforge.gradle' version '5.+'
33
}
44

5-
version = "1.12.2-1.11.1-r25-dev"
5+
version = "1.12.2-1.11.1-r26-dev"
66
group = "hellfirepvp.modularmachinery"
77

88
repositories {
@@ -88,6 +88,7 @@ dependencies {
8888
compileOnly "curse.maven:Mekanism-268560:2835175"
8989
compileOnly "curse.maven:industrialcraft-2-242638:3078604"
9090
compileOnly "curse.maven:nuclearcraft-overhauled-336895:3862197"
91+
compileOnly "curse.maven:flux-networks-248020:3178199"
9192

9293
}
9394

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Date: 26.06.2017 / 20:26
3636
*/
3737
@Mod(modid = ModularMachinery.MODID, name = ModularMachinery.NAME, version = ModularMachinery.VERSION,
38-
dependencies = "required-after:forge@[14.21.0.2371,);after:crafttweaker@[4.0.4,);after:jei@[4.13.1.222,)",
38+
dependencies = "required-after:forge@[14.21.0.2371,);after:crafttweaker@[4.0.4,);after:jei@[4.13.1.222,);after:fluxnetworks@[4.1.0,)",
3939
acceptedMinecraftVersions = "[1.12, 1.13)"
4040
)
4141
public class ModularMachinery {

src/main/java/hellfirepvp/modularmachinery/common/CommonProxy.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
import hellfirepvp.modularmachinery.common.crafting.IntegrationTypeHelper;
1717
import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry;
1818
import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterRegistry;
19+
import hellfirepvp.modularmachinery.common.data.Config;
1920
import hellfirepvp.modularmachinery.common.data.ModDataHolder;
2021
import hellfirepvp.modularmachinery.common.integration.ModIntegrationCrafttweaker;
2122
import hellfirepvp.modularmachinery.common.integration.ModIntegrationTOP;
2223
import hellfirepvp.modularmachinery.common.integration.crafttweaker.MachineBuilder;
2324
import hellfirepvp.modularmachinery.common.integration.crafttweaker.MachineModifier;
2425
import hellfirepvp.modularmachinery.common.integration.crafttweaker.event.MMEvents;
26+
import hellfirepvp.modularmachinery.common.integration.fluxnetworks.ModIntegrationFluxNetworks;
2527
import hellfirepvp.modularmachinery.common.lib.BlocksMM;
2628
import hellfirepvp.modularmachinery.common.machine.MachineRegistry;
2729
import hellfirepvp.modularmachinery.common.registry.internal.InternalRegistryPrimer;
@@ -78,18 +80,26 @@ public static void loadModData(File configDir) {
7880
}
7981

8082
private static void checkThirdPartyServer() {
81-
try {
82-
Class.forName("catserver.server.CatServer");
83+
if (isClassExist("catserver.server.CatServer") || isClassExist("com.mohistmc.MohistMC")) {
8384
ModularMachinery.log.warn("//////// Plugin Server Detected! ////////");
8485
ModularMachinery.log.warn("Plugin server will break MMCE's asynchronous functionality.");
8586
ModularMachinery.log.warn("Plugin server compatibility mode is enabled!");
8687
ModularMachinery.log.warn("This will cause asynchronous effects to drop and raise the overhead of the main thread!");
8788
ModularMachinery.pluginServerCompatibleMode = true;
88-
} catch (Exception e) {
89+
} else {
8990
ModularMachinery.pluginServerCompatibleMode = false;
9091
}
9192
}
9293

94+
private static boolean isClassExist(String className) {
95+
try {
96+
Class.forName(className);
97+
return true;
98+
} catch (Exception e) {
99+
return false;
100+
}
101+
}
102+
93103
public void preInit() {
94104
creativeTabModularMachinery = new CreativeTabs(ModularMachinery.MODID) {
95105
@Override
@@ -103,15 +113,20 @@ public ItemStack createIcon() {
103113
if (Mods.CRAFTTWEAKER.isPresent()) {
104114
MinecraftForge.EVENT_BUS.register(new ModIntegrationCrafttweaker());
105115
}
116+
if (Mods.FLUX_NETWORKS.isPresent() && Config.enableFluxNetworksIntegration) {
117+
ModIntegrationFluxNetworks.preInit();
118+
ModularMachinery.log.info("[ModularMachinery-CE] Flux Networks integration is enabled! Lets your network to transmit more power!");
119+
}
106120

107121
MachineRegistry.preloadMachines();
108122

109123
MinecraftForge.EVENT_BUS.register(AssemblyEventHandler.INSTANCE);
110124
MinecraftForge.EVENT_BUS.register(new EventHandler());
125+
111126
MinecraftForge.EVENT_BUS.register(ModularMachinery.EXECUTE_MANAGER);
112127
ModularMachinery.EXECUTE_MANAGER.init();
113128
checkThirdPartyServer();
114-
ModularMachinery.log.info(String.format("[ModularMachinery] Parallel executor is ready (%s Threads), Let's get started!!!", TaskExecutor.FORK_JOIN_POOL.getParallelism()));
129+
ModularMachinery.log.info(String.format("[ModularMachinery-CE] Parallel executor is ready (%s Threads), Let's get started!!!", TaskExecutor.FORK_JOIN_POOL.getParallelism()));
115130
}
116131

117132
public void init() {
@@ -133,6 +148,7 @@ public void init() {
133148

134149
if (Mods.TOP.isPresent()) {
135150
ModIntegrationTOP.registerProvider();
151+
ModularMachinery.log.info("[ModularMachinery-CE] TheOneProbe integration is enabled! Stop looking at the dark controller gui!");
136152
}
137153
}
138154

src/main/java/hellfirepvp/modularmachinery/common/base/Mods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum Mods {
2828
TOP("theoneprobe"),
2929
NUCLEARCRAFT_OVERHAULED("nuclearcraft"),
3030
RESOURCELOADER("resourceloader"),
31+
FLUX_NETWORKS("fluxnetworks"),
3132
;
3233

3334
public final String modid;

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Config {
3737
public static boolean selectiveUpdateTileEntity = false;
3838
public static boolean machineParallelizeEnabledByDefault = true;
3939
public static boolean recipeParallelizeEnabledByDefault = true;
40+
public static boolean enableFluxNetworksIntegration = true;
4041
public static int maxMachineParallelism = 2048;
4142

4243
private static File lastReadFile;
@@ -73,17 +74,29 @@ private static void load() {
7374
ModularMachinery.log.error("Machine-Casing color defined in the config is not a hex color: " + strColor);
7475
ModularMachinery.log.error("Using default color instead...");
7576
}
77+
78+
// General
7679
machineColor = col;
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.");
82+
83+
// Modular Controller Merge Support
7784
mocCompatibleMode = lastReadConfig.getBoolean(
7885
"modular-controller-compatible-mode", "general", false,
7986
"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.");
8287
disableMocDeprecatedTip = lastReadConfig.getBoolean(
8388
"disable-moc-deprecated-tip", "general", false,
8489
"Disable the ModularController is deprecated tooltip.");
90+
91+
// Performance
8592
selectiveUpdateTileEntity = lastReadConfig.getBoolean("selective-update-tileentity", "general", false,
8693
"Provide selective updates for certain tile entities that tend to consume a lot of bandwidth to relieve network pressure.");
94+
95+
// FluxNetworks Integration
96+
enableFluxNetworksIntegration = lastReadConfig.getBoolean("enable-fluxnetworks-integration", "general", true,
97+
"When enabled, allows you to use the flux network to transfer larger amounts of energy than 2147483647.");
98+
99+
// Parallelize Feature
87100
machineParallelizeEnabledByDefault = lastReadConfig.getBoolean("machine-parallelize-enabled-bydefault",
88101
"parallel-controller", true, "Whether the machine parallel recipe processing is enabled by default.");
89102
recipeParallelizeEnabledByDefault = lastReadConfig.getBoolean("recipe-parallelize-enabled-bydefault",

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
public class ModIntegrationTOP {
99
public static int recipeProgressBarFilledColor = 0xCC54FF9F;
10+
public static int failureProgressBarFilledColor = 0xCCFF4500;
1011
public static int recipeProgressBarAlternateFilledColor = 0xCC4EEE94;
12+
public static int failureProgressBarAlternateFilledColor = 0xCCFF6347;
1113
public static int recipeProgressBarBorderColor = 0xCC43CD80;
14+
public static int failureProgressBarBorderColor = 0xCCFF4500;
1215
public static int recipeProgressBarBackgroundColor = 0xFF000000;
1316
public static boolean showRecipeProgressBarDecimalPoints = true;
1417
public static boolean showParallelControllerInfo = true;
@@ -39,9 +42,26 @@ public static void loadFromConfig(Configuration cfg) {
3942
cfg.getString("RECIPE_PROGRESSBAR_BACKGROUND_COLOR", "display.theoneprobe",
4043
"FF000000", "Machine progressbar filled color if TheOneProbe mod is installed."),
4144
16);
45+
46+
failureProgressBarFilledColor = Integer.parseUnsignedInt(
47+
cfg.getString("FAILURE_PROGRESSBAR_FILLED_COLOR", "display.theoneprobe",
48+
"CCFF6347", "Similar to RECIPE_PROGRESSBAR_FILLED_COLOR, but only displayed if it fails in the middle of a mechanical run."),
49+
16);
50+
51+
failureProgressBarAlternateFilledColor = Integer.parseUnsignedInt(
52+
cfg.getString("FAILURE_PROGRESSBAR_ALTERNATE_FILLED_COLOR", "display.theoneprobe",
53+
"CCFF4500", "Similar to RECIPE_PROGRESSBAR_ALTERNATE_FILLED_COLOR, but only displayed if it fails in the middle of a mechanical run."),
54+
16);
55+
56+
failureProgressBarBorderColor = Integer.parseUnsignedInt(
57+
cfg.getString("FAILURE_PROGRESSBAR_BORDER_COLOR", "display.theoneprobe",
58+
"CCFF6347", "Similar to RECIPE_PROGRESSBAR_BACKGROUND_COLOR, but only displayed if it fails in the middle of a mechanical run."),
59+
16);
60+
4261
showRecipeProgressBarDecimalPoints = cfg.getBoolean("SHOW_RECIPE_PROGRESSBAR_DECIMAL_POINTS",
4362
"display.theoneprobe", true,
4463
"Show recipe progressbar decimal points if TheOneProbe mod is installed.");
64+
4565
showParallelControllerInfo = cfg.getBoolean("SHOW_PARALLEL_CONTROLLER_INFO", "display.theoneprobe",
4666
true, "Show parallel controller info if TheOneProbe mod is installed.");
4767
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package hellfirepvp.modularmachinery.common.integration.fluxnetworks;
2+
3+
import hellfirepvp.modularmachinery.common.tiles.base.TileEnergyHatch;
4+
import net.minecraft.tileentity.TileEntity;
5+
import net.minecraft.util.EnumFacing;
6+
import sonar.fluxnetworks.api.energy.ITileEnergyHandler;
7+
8+
import javax.annotation.Nonnull;
9+
10+
/**
11+
* <p>通量网络适配器</p>
12+
* <p>允许通量网络传输超过 Integer.MAX_VALUE 的能量值。</p>
13+
* <p>Flux Networks Adapter</p>
14+
* <p>Allows the flux network to transmit energy values that exceed Integer.MAX_VALUE.</p>
15+
*/
16+
public class MMEnergyHandler implements ITileEnergyHandler {
17+
public static final MMEnergyHandler INSTANCE = new MMEnergyHandler();
18+
19+
private MMEnergyHandler() {
20+
}
21+
22+
@Override
23+
public boolean hasCapability(@Nonnull TileEntity tile, EnumFacing side) {
24+
return !tile.isInvalid() && tile instanceof TileEnergyHatch;
25+
}
26+
27+
@Override
28+
public boolean canAddEnergy(@Nonnull TileEntity tile, EnumFacing side) {
29+
if (tile instanceof TileEnergyHatch) {
30+
TileEnergyHatch energyHatch = (TileEnergyHatch) tile;
31+
return energyHatch.canReceive();
32+
}
33+
return false;
34+
}
35+
36+
@Override
37+
public boolean canRemoveEnergy(@Nonnull TileEntity tile, EnumFacing side) {
38+
if (tile instanceof TileEnergyHatch) {
39+
TileEnergyHatch energyHatch = (TileEnergyHatch) tile;
40+
return energyHatch.canExtract();
41+
}
42+
return false;
43+
}
44+
45+
@Override
46+
public long addEnergy(long amount, @Nonnull TileEntity tile, EnumFacing side, boolean simulate) {
47+
if (!(tile instanceof TileEnergyHatch)) {
48+
return 0;
49+
}
50+
51+
TileEnergyHatch energyHatch = (TileEnergyHatch) tile;
52+
long remainingCapacity = energyHatch.getRemainingCapacity();
53+
if (simulate) {
54+
return amount - remainingCapacity;
55+
}
56+
57+
if (remainingCapacity < amount) {
58+
return energyHatch.receiveEnergy(remainingCapacity) ? remainingCapacity : 0;
59+
} else {
60+
return energyHatch.receiveEnergy(amount) ? amount : 0;
61+
}
62+
}
63+
64+
@Override
65+
public long removeEnergy(long amount, @Nonnull TileEntity tile, EnumFacing side) {
66+
if (!(tile instanceof TileEnergyHatch)) {
67+
return 0;
68+
}
69+
70+
TileEnergyHatch energyHatch = (TileEnergyHatch) tile;
71+
long currentEnergy = energyHatch.getCurrentEnergy();
72+
73+
if (currentEnergy < amount) {
74+
return energyHatch.extractEnergy(amount) ? amount : 0;
75+
} else {
76+
return energyHatch.extractEnergy(currentEnergy) ? currentEnergy : 0;
77+
}
78+
}
79+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package hellfirepvp.modularmachinery.common.integration.fluxnetworks;
2+
3+
import sonar.fluxnetworks.common.handler.TileEntityHandler;
4+
5+
public class ModIntegrationFluxNetworks {
6+
public static void preInit() {
7+
//在列表头部插入适配器,保证不被其他类型覆盖结果。
8+
//Insert adapters in the head of the list to ensure that the results are not overwritten by other types.
9+
TileEntityHandler.tileEnergyHandlers.add(0, MMEnergyHandler.INSTANCE);
10+
}
11+
}

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

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,62 @@ private static void processParallelControllerTOP(TileParallelController parallel
4343
}
4444

4545
private static void processMachineControllerTOP(TileMachineController machine, IProbeInfo probeInfo, EntityPlayer player) {
46+
//是否形成结构
47+
if (machine.isStructureFormed()) {
48+
probeInfo.text(TextFormatting.GREEN + "{*top.machine.structure.found*}");
49+
}
50+
4651
//是否在工作
47-
if (machine.getActiveRecipe() != null && machine.getFoundMachine() != null) {
48-
probeInfo.text(TextFormatting.GREEN + "{*top.machine.working*}");
52+
if (machine.getActiveRecipe() == null || machine.getFoundMachine() == null) {
53+
probeInfo.text(TextFormatting.RED + "{*" + machine.getCraftingStatus().getUnlocMessage() + "*}");
54+
return;
55+
}
56+
57+
int progressBarFilledColor = ModIntegrationTOP.recipeProgressBarFilledColor;
58+
int progressBarAlternateFilledColor = ModIntegrationTOP.recipeProgressBarAlternateFilledColor;
59+
int progressBarBorderColor = ModIntegrationTOP.recipeProgressBarBorderColor;
4960

50-
ActiveMachineRecipe activeRecipe = machine.getActiveRecipe();
51-
int tick = activeRecipe.getTick();
52-
int totalTick = activeRecipe.getTotalTick();
53-
float progress = (float) (tick * 100) / totalTick;
61+
if (machine.getCraftingStatus().isCrafting()) {
62+
probeInfo.text(TextFormatting.GREEN + "{*top.machine.working*}");
63+
} else {
64+
probeInfo.text(TextFormatting.RED + "{*" + machine.getCraftingStatus().getUnlocMessage() + "*}");
65+
progressBarFilledColor = ModIntegrationTOP.failureProgressBarFilledColor;
66+
progressBarAlternateFilledColor = ModIntegrationTOP.failureProgressBarAlternateFilledColor;
67+
progressBarBorderColor = ModIntegrationTOP.failureProgressBarBorderColor;
68+
}
5469

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-
}
70+
ActiveMachineRecipe activeRecipe = machine.getActiveRecipe();
71+
int tick = activeRecipe.getTick();
72+
int totalTick = activeRecipe.getTotalTick();
73+
float progress = (float) (tick * 100) / totalTick;
5974

60-
String progressStr;
61-
if (player.isSneaking()) {
62-
//如:20.5 秒 / 40.0 秒
63-
//Example: 20.5 Sec / 40.0 Sec
64-
progressStr = String.format("%.1f s / %.1f s", (float) tick / 20, (float) totalTick / 20);
65-
} else if (ModIntegrationTOP.showRecipeProgressBarDecimalPoints && totalTick >= 1000) {
66-
//只有当启用了显示小数点且配方耗时超过 1000 tick 才会显示小数点
67-
progressStr = String.format("%.2f", progress) + "%";
68-
} else {
69-
progressStr = String.format("%.0f", progress) + "%";
70-
}
75+
if (activeRecipe.getParallelism() > 1) {
76+
probeInfo.text(TextFormatting.AQUA + "{*top.parallelism*}" + TextFormatting.GREEN + activeRecipe.getParallelism());
77+
probeInfo.text(TextFormatting.GOLD + "{*top.max_parallelism*}" + TextFormatting.YELLOW + activeRecipe.getMaxParallelism());
78+
}
7179

72-
IProbeInfo progressLine = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
73-
progressLine.text("{*top.recipe.progress*}: ");
74-
progressLine.progress((int) progress, 100, probeInfo.defaultProgressStyle()
75-
.prefix(progressStr)
76-
.filledColor(ModIntegrationTOP.recipeProgressBarFilledColor)
77-
.alternateFilledColor(ModIntegrationTOP.recipeProgressBarAlternateFilledColor)
78-
.borderColor(ModIntegrationTOP.recipeProgressBarBorderColor)
79-
.backgroundColor(ModIntegrationTOP.recipeProgressBarBackgroundColor)
80-
.numberFormat(NumberFormat.NONE)
81-
);
80+
String progressStr;
81+
if (player.isSneaking()) {
82+
//如:20.5 秒 / 40.0 秒
83+
//Example: 20.5 Sec / 40.0 Sec
84+
progressStr = String.format("%.1f s / %.1f s", (float) tick / 20, (float) totalTick / 20);
85+
} else if (ModIntegrationTOP.showRecipeProgressBarDecimalPoints && totalTick >= 1000) {
86+
//只有当启用了显示小数点且配方耗时超过 1000 tick 才会显示小数点
87+
progressStr = String.format("%.2f", progress) + "%";
8288
} else {
83-
//是否形成结构
84-
if (machine.getFoundMachine() != null) {
85-
probeInfo.text(TextFormatting.GREEN + "{*top.machine.structure.found*}");
86-
}
87-
probeInfo.text(TextFormatting.RED + "{*" + machine.getCraftingStatus().getUnlocMessage() + "*}");
89+
progressStr = String.format("%.0f", progress) + "%";
8890
}
91+
92+
IProbeInfo progressLine = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
93+
progressLine.text("{*top.recipe.progress*}: ");
94+
progressLine.progress((int) progress, 100, probeInfo.defaultProgressStyle()
95+
.prefix(progressStr)
96+
.filledColor(progressBarFilledColor)
97+
.alternateFilledColor(progressBarAlternateFilledColor)
98+
.borderColor(progressBarBorderColor)
99+
.backgroundColor(ModIntegrationTOP.recipeProgressBarBackgroundColor)
100+
.numberFormat(NumberFormat.NONE)
101+
);
89102
}
90103

91104
}

0 commit comments

Comments
 (0)