Skip to content

Commit d366dc3

Browse files
committed
Supports ZenScript hot reload (Require ZenUtils).
1 parent f308849 commit d366dc3

26 files changed

+346
-52
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
import github.kasuminova.mmce.common.concurrent.TaskExecutor;
1212
import hellfirepvp.modularmachinery.common.CommonProxy;
13+
import hellfirepvp.modularmachinery.common.base.Mods;
14+
import hellfirepvp.modularmachinery.common.command.CommandGetBluePrint;
1315
import hellfirepvp.modularmachinery.common.command.CommandHand;
1416
import hellfirepvp.modularmachinery.common.command.CommandPerformanceReport;
1517
import hellfirepvp.modularmachinery.common.command.CommandSyntax;
18+
import hellfirepvp.modularmachinery.common.integration.crafttweaker.command.CommandCTReload;
1619
import hellfirepvp.modularmachinery.common.network.*;
1720
import net.minecraft.launchwrapper.Launch;
1821
import net.minecraftforge.fluids.FluidRegistry;
@@ -96,7 +99,12 @@ public void onServerStart(FMLServerStartingEvent event) {
9699
//Cmd registration
97100
event.registerServerCommand(new CommandSyntax());
98101
event.registerServerCommand(new CommandHand());
102+
event.registerServerCommand(new CommandGetBluePrint());
99103
event.registerServerCommand(new CommandPerformanceReport());
104+
105+
if (Mods.ZEN_UTILS.isPresent()) {
106+
event.registerServerCommand(new CommandCTReload());
107+
}
100108
}
101109

102110
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum Mods {
2929
NUCLEARCRAFT_OVERHAULED("nuclearcraft"),
3030
RESOURCELOADER("resourceloader"),
3131
FLUX_NETWORKS("fluxnetworks"),
32+
ZEN_UTILS("zenutils"),
3233
;
3334

3435
public final String modid;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package hellfirepvp.modularmachinery.common.command;
2+
3+
import hellfirepvp.modularmachinery.ModularMachinery;
4+
import hellfirepvp.modularmachinery.common.item.ItemBlueprint;
5+
import hellfirepvp.modularmachinery.common.lib.ItemsMM;
6+
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
7+
import hellfirepvp.modularmachinery.common.machine.MachineRegistry;
8+
import net.minecraft.command.CommandBase;
9+
import net.minecraft.command.ICommandSender;
10+
import net.minecraft.entity.player.EntityPlayer;
11+
import net.minecraft.item.ItemStack;
12+
import net.minecraft.server.MinecraftServer;
13+
import net.minecraft.util.ResourceLocation;
14+
import net.minecraft.util.text.TextComponentTranslation;
15+
16+
public class CommandGetBluePrint extends CommandBase {
17+
@Override
18+
public String getName() {
19+
return "mm-get_blueprint";
20+
}
21+
22+
@Override
23+
public String getUsage(ICommandSender sender) {
24+
return "command.modularmachinery.get_blueprint";
25+
}
26+
27+
@Override
28+
public int getRequiredPermissionLevel() {
29+
return 2;
30+
}
31+
32+
@Override
33+
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
34+
if (!(sender instanceof EntityPlayer)) {
35+
sender.sendMessage(new TextComponentTranslation("command.modularmachinery.get_blueprint.player_only"));
36+
return;
37+
}
38+
if (args.length < 1) {
39+
sender.sendMessage(new TextComponentTranslation(getUsage(sender)));
40+
return;
41+
}
42+
43+
String machineName = args[0];
44+
45+
DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName));
46+
if (machine == null) {
47+
sender.sendMessage(new TextComponentTranslation(
48+
"command.modularmachinery.get_blueprint.not_found", machineName));
49+
return;
50+
}
51+
52+
EntityPlayer player = (EntityPlayer) sender;
53+
ItemStack blueprint = new ItemStack(ItemsMM.blueprint);
54+
ItemBlueprint.setAssociatedMachine(blueprint, machine);
55+
56+
if (player.addItemStackToInventory(blueprint)) {
57+
sender.sendMessage(
58+
new TextComponentTranslation("command.modularmachinery.get_blueprint.success"));
59+
}
60+
}
61+
}

src/main/java/hellfirepvp/modularmachinery/common/command/CommandSyntax.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import net.minecraft.command.CommandBase;
1414
import net.minecraft.command.CommandException;
1515
import net.minecraft.command.ICommandSender;
16-
import net.minecraft.entity.player.EntityPlayerMP;
1716
import net.minecraft.server.MinecraftServer;
1817
import net.minecraft.util.text.TextComponentString;
1918

@@ -43,13 +42,12 @@ public String getUsage(ICommandSender sender) {
4342

4443
@Override
4544
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
46-
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
47-
player.sendMessage(new TextComponentString("Testing Machines:"));
45+
sender.sendMessage(new TextComponentString("Testing Machines:"));
4846
MachineRegistry.preloadMachines();
49-
MachineRegistry.loadMachines(player);
50-
player.sendMessage(new TextComponentString(""));
51-
player.sendMessage(new TextComponentString("Testing Recipes:"));
52-
RecipeRegistry.getRegistry().loadRecipeRegistry(player, false);
47+
MachineRegistry.loadMachines(sender);
48+
sender.sendMessage(new TextComponentString(""));
49+
sender.sendMessage(new TextComponentString("Testing Recipes:"));
50+
RecipeRegistry.getRegistry().loadRecipeRegistry(sender, false);
5351
}
5452

5553
}

src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeRegistry.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import hellfirepvp.modularmachinery.common.data.DataLoadProfiler;
1717
import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeAdapterBuilder;
1818
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
19-
import net.minecraft.entity.player.EntityPlayer;
19+
import net.minecraft.command.ICommandSender;
2020
import net.minecraft.util.ResourceLocation;
2121
import net.minecraft.util.Tuple;
2222
import net.minecraftforge.fml.common.ProgressManager;
@@ -63,7 +63,7 @@ public static MachineRecipe getRecipe(ResourceLocation key) {
6363
return RECIPE_REGISTRY.get(key);
6464
}
6565

66-
private static Map<DynamicMachine, List<MachineRecipe>> loadAdapters(@Nullable EntityPlayer player,
66+
private static Map<DynamicMachine, List<MachineRecipe>> loadAdapters(@Nullable ICommandSender sender,
6767
Map<ResourceLocation, MachineRecipe> sharedLoadRegistry,
6868
List<RecipeAdapterBuilder> earlyRecipeAdapters) {
6969
ProgressManager.ProgressBar barRecipes = ProgressManager.push("RecipeRegistry - Adapters", 3);
@@ -94,7 +94,7 @@ private static Map<DynamicMachine, List<MachineRecipe>> loadAdapters(@Nullable E
9494

9595
Map<DynamicMachine, List<MachineRecipe>> validRecipes = loadAndValidateRecipes(recipes, profiler, sharedLoadRegistry);
9696

97-
profiler.printLines(player);
97+
profiler.printLines(sender);
9898
ProgressManager.pop(barRecipes);
9999
return validRecipes;
100100
}
@@ -178,20 +178,24 @@ public static void registerRecipes(Map<DynamicMachine, List<MachineRecipe>> map)
178178
}
179179
}
180180

181-
public void loadRecipeRegistry(@Nullable EntityPlayer player, boolean doRegister) {
181+
public static int registeredRecipeCount() {
182+
return RECIPE_REGISTRY.size();
183+
}
184+
185+
public void loadRecipeRegistry(@Nullable ICommandSender sender, boolean doRegister) {
182186
Map<ResourceLocation, MachineRecipe> sharedLoadRegistry = new HashMap<>();
183187

184-
Map<DynamicMachine, List<MachineRecipe>> recipes = loadRecipes(player, sharedLoadRegistry);
188+
Map<DynamicMachine, List<MachineRecipe>> recipes = loadRecipes(sender, sharedLoadRegistry);
185189
if (doRegister) {
186190
registerRecipes(recipes);
187191
}
188-
recipes = loadAdapters(player, sharedLoadRegistry, earlyRecipeAdapters);
192+
recipes = loadAdapters(sender, sharedLoadRegistry, earlyRecipeAdapters);
189193
if (doRegister) {
190194
registerRecipes(recipes);
191195
}
192196
}
193197

194-
private Map<DynamicMachine, List<MachineRecipe>> loadRecipes(@Nullable EntityPlayer player, Map<ResourceLocation, MachineRecipe> sharedLoadRegistry) {
198+
private Map<DynamicMachine, List<MachineRecipe>> loadRecipes(@Nullable ICommandSender player, Map<ResourceLocation, MachineRecipe> sharedLoadRegistry) {
195199
ProgressManager.ProgressBar barRecipes = ProgressManager.push("RecipeRegistry - Recipes", 3);
196200
barRecipes.step("Discovering Files");
197201
DataLoadProfiler profiler = new DataLoadProfiler();
@@ -238,4 +242,10 @@ public void clearLingeringRecipes() {
238242
this.earlyRecipeAdapters.clear();
239243
}
240244

245+
public void clearAllRecipes() {
246+
RECIPE_REGISTRY.clear();
247+
REGISTRY_RECIPE_BY_MACHINE.clear();
248+
this.earlyRecipes.clear();
249+
this.earlyRecipeAdapters.clear();
250+
}
241251
}

src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterIC2Compressor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
public class AdapterIC2Compressor extends RecipeAdapter {
2525
public static final int workTime = 300;
26-
private int incId = 0;
2726

2827
public AdapterIC2Compressor() {
2928
super(new ResourceLocation("ic2", "te_compressor"));

src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
*/
3838
public class AdapterMinecraftFurnace extends RecipeAdapter {
3939

40-
private int incId = 0;
41-
4240
public AdapterMinecraftFurnace() {
4341
super(new ResourceLocation("minecraft", "furnace"));
4442
}

src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
*/
3434
public class DynamicMachineRecipeAdapter extends RecipeAdapter {
3535
private final DynamicMachine originalMachine;
36-
private int incId = 0;
3736

3837
public DynamicMachineRecipeAdapter(@Nonnull ResourceLocation registryName, DynamicMachine originalMachine) {
3938
super(registryName);

src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
public abstract class RecipeAdapter implements IForgeRegistryEntry<RecipeAdapter> {
3333

3434
private final ResourceLocation registryName;
35+
protected int incId = 0;
3536

3637
public RecipeAdapter(@Nonnull ResourceLocation registryName) {
3738
this.registryName = registryName;
@@ -66,6 +67,10 @@ public MachineRecipe createRecipeShell(ResourceLocation uniqueRecipeName, Resour
6667
uniqueRecipeName, owningMachineName, tickTime, priority, voidPerTickFailure, Config.recipeParallelizeEnabledByDefault);
6768
}
6869

70+
public void resetIncId() {
71+
incId = 0;
72+
}
73+
6974
public static void addAdditionalRequirements(MachineRecipe recipe,
7075
List<ComponentRequirement<?, ?>> additionalRequirements,
7176
Map<Class<?>, List<IEventHandler<RecipeEvent>>> eventHandlers,

src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapter;
77
import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement;
88
import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementEnergy;
9-
import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementItem;
109
import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementIngredientArray;
10+
import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementItem;
1111
import hellfirepvp.modularmachinery.common.integration.crafttweaker.event.recipe.RecipeEvent;
1212
import hellfirepvp.modularmachinery.common.lib.RequirementTypesMM;
1313
import hellfirepvp.modularmachinery.common.machine.IOType;
@@ -30,7 +30,6 @@
3030
public class AdapterNCOAlloyFurnace extends RecipeAdapter {
3131
public static final int WORK_TIME = 400;
3232
public static final int BASE_ENERGY_USAGE = 10;
33-
private int incId = 0;
3433

3534
public AdapterNCOAlloyFurnace() {
3635
super(new ResourceLocation("nuclearcraft", "alloy_furnace"));

0 commit comments

Comments
 (0)