Skip to content

Commit 0bb7738

Browse files
committed
Fix JSON Machine cannot reload problem; Add client-only reload command.
1 parent d366dc3 commit 0bb7738

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

src/main/java/hellfirepvp/modularmachinery/client/ClientProxy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import hellfirepvp.modularmachinery.common.block.BlockController;
1919
import hellfirepvp.modularmachinery.common.block.BlockDynamicColor;
2020
import hellfirepvp.modularmachinery.common.block.BlockVariants;
21+
import hellfirepvp.modularmachinery.common.integration.crafttweaker.command.CommandCTReloadClient;
2122
import hellfirepvp.modularmachinery.common.item.ItemBlueprint;
2223
import hellfirepvp.modularmachinery.common.item.ItemDynamicColor;
2324
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
@@ -46,6 +47,7 @@
4647
import net.minecraft.util.math.BlockPos;
4748
import net.minecraft.util.math.MathHelper;
4849
import net.minecraft.world.World;
50+
import net.minecraftforge.client.ClientCommandHandler;
4951
import net.minecraftforge.client.event.ModelRegistryEvent;
5052
import net.minecraftforge.client.model.ModelLoader;
5153
import net.minecraftforge.common.MinecraftForge;
@@ -170,6 +172,7 @@ public void init() {
170172
@Override
171173
public void postInit() {
172174
super.postInit();
175+
ClientCommandHandler.instance.registerCommand(new CommandCTReloadClient());
173176
}
174177

175178
@Override

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ public void onScriptsReloading(ScriptReloadEvent.Pre event) {
6262
// Reset RecipeAdapterIncId
6363
RegistriesMM.ADAPTER_REGISTRY.getValuesCollection().forEach(RecipeAdapter::resetIncId);
6464

65-
// Reload JSON Machine
6665
for (DynamicMachine loadedMachine : MachineRegistry.getLoadedMachines()) {
6766
loadedMachine.getMachineEventHandlers().clear();
6867
loadedMachine.getSmartInterfaceTypes().clear();
6968
}
69+
// Reload JSON Machine
70+
MachineRegistry.preloadMachines();
71+
// Reload All Machine
7072
MachineRegistry.reloadMachine(MachineRegistry.loadMachines(null));
7173
sender.sendMessage(new TextComponentTranslation(
7274
"message.reloaded.machines", MachineRegistry.getLoadedMachines().size()));
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package hellfirepvp.modularmachinery.common.integration.crafttweaker.command;
2+
3+
import crafttweaker.CraftTweakerAPI;
4+
import crafttweaker.runtime.ScriptLoader;
5+
import net.minecraft.command.CommandBase;
6+
import net.minecraft.command.ICommandSender;
7+
import net.minecraft.server.MinecraftServer;
8+
import net.minecraft.util.text.TextFormatting;
9+
import net.minecraftforge.common.MinecraftForge;
10+
import stanhebben.zenscript.ZenModule;
11+
import youyihj.zenutils.ZenUtils;
12+
import youyihj.zenutils.api.reload.ScriptReloadEvent;
13+
14+
import static crafttweaker.mc1120.commands.SpecialMessagesChat.getNormalMessage;
15+
import static youyihj.zenutils.impl.reload.ReloadCommand.RELOADABLE_LOADER;
16+
17+
/**
18+
* Similar to {@link CommandCTReload}, but only works in client.
19+
*/
20+
public class CommandCTReloadClient extends CommandBase {
21+
@Override
22+
public String getName() {
23+
return "mm-reload_client";
24+
}
25+
26+
@Override
27+
public String getUsage(ICommandSender sender) {
28+
return "command.modularmachinery.reload_client";
29+
}
30+
31+
@Override
32+
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
33+
sender.sendMessage(getNormalMessage(TextFormatting.AQUA + "Beginning reload scripts"));
34+
sender.sendMessage(getNormalMessage("Only scripts that marked " + TextFormatting.GRAY + "#loader reloadable " + TextFormatting.RESET + "can be reloaded."));
35+
sender.sendMessage(getNormalMessage(TextFormatting.YELLOW + "Most recipe modifications are not reloadable, they will be ignored."));
36+
ZenUtils.tweaker.freezeActionApplying();
37+
ZenModule.loadedClasses.clear();
38+
ZenUtils.crafttweakerLogger.clear();
39+
MinecraftForge.EVENT_BUS.post(new ScriptReloadEvent.Pre(sender));
40+
ScriptLoader loader = RELOADABLE_LOADER.get();
41+
loader.setLoaderStage(ScriptLoader.LoaderStage.NOT_LOADED);
42+
CraftTweakerAPI.tweaker.loadScript(false, loader);
43+
if (loader.getLoaderStage() == ScriptLoader.LoaderStage.ERROR) {
44+
sender.sendMessage(getNormalMessage(TextFormatting.DARK_RED + "Failed to reload scripts"));
45+
} else {
46+
sender.sendMessage(getNormalMessage("Reloaded successfully"));
47+
}
48+
MinecraftForge.EVENT_BUS.post(new ScriptReloadEvent.Post(sender));
49+
}
50+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ public void onFinished() {
408408

409409
this.context.finishCrafting();
410410

411-
this.activeRecipe.reset();
412-
this.activeRecipe.setMaxParallelism(getMaxParallelism());
411+
this.activeRecipe = new ActiveMachineRecipe(this.activeRecipe.getRecipe(), getMaxParallelism());
413412
this.context = createContext(this.activeRecipe);
414413
tryStartRecipe(context);
415414
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ command.modularmachinery.get_blueprint.player_only=§cThis command can only be e
88
command.modularmachinery.get_blueprint.not_found=The machine with the registered name %s was not found!
99
command.modularmachinery.get_blueprint.success=Blueprints have been given.
1010
command.modularmachinery.reload=/mm-reload
11+
command.modularmachinery.reload_client=/mm-reload_client
1112
command.modularmachinery.performance_report=/mm-performance_report [reset]
1213
command.modularmachinery.performance_report.title=Modular Machinery - Concurrent Performance Reporting (%s Executions Counted)
1314
command.modularmachinery.performance_report.reset=Performance report has been reset.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ command.modularmachinery.get_blueprint=/mm-get_blueprint <machineName>
77
command.modularmachinery.get_blueprint.player_only=§c该指令只能由玩家执行。
88
command.modularmachinery.get_blueprint.not_found=未找到注册名为 %s 的机械!
99
command.modularmachinery.get_blueprint.success=已给予机械蓝图。
10+
command.modularmachinery.reload=/mm-reload
11+
command.modularmachinery.reload_client=/mm-reload_client
1012
command.modularmachinery.performance_report=/mm-performance_report [reset]
1113
command.modularmachinery.performance_report.title=模块化机械 - 并行性能报告(已统计 %s 次执行)
1214
command.modularmachinery.performance_report.reset=性能报告数据已重置。

0 commit comments

Comments
 (0)