Skip to content

Commit 9f17261

Browse files
committed
Some fixes for known issues; and final feature refinements.
1 parent 5d5882c commit 9f17261

File tree

9 files changed

+93
-22
lines changed

9 files changed

+93
-22
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void drawRecipeInfo(RecipeThread thread, int id, int offsetY) {
9191

9292
// Daemon Thread Color
9393
if (thread.isDaemon()) {
94-
GlStateManager.color(0.5F, 0.8F, 1.0F, 1.0F);
94+
GlStateManager.color(0.7F, 0.9F, 1.0F, 1.0F);
9595
} else {
9696
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
9797
}
@@ -101,7 +101,7 @@ private void drawRecipeInfo(RecipeThread thread, int id, int offsetY) {
101101
if (status.isCrafting()) {
102102
GlStateManager.color(0.6F, 1.0F, 0.75F, 1.0F);
103103
} else {
104-
GlStateManager.color(1.0F, 0.45F, 0.45F, 1.0F);
104+
GlStateManager.color(1.0F, 0.6F, 0.6F, 1.0F);
105105
}
106106

107107
if (activeRecipe != null) {
@@ -145,15 +145,10 @@ private void drawRecipeStatus(RecipeThread thread, int id, int y) {
145145
}
146146
offsetY += 12;
147147

148-
if (status.isCrafting()) {
149-
fr.drawString(I18n.format("gui.controller.status.crafting"), offsetX, offsetY, 0x222222);
148+
List<String> out = fr.listFormattedStringToWidth(I18n.format(status.getUnlocMessage()), (int) ((FACTORY_ELEMENT_WIDTH - 6) / FONT_SCALE));
149+
for (String draw : out) {
150+
fr.drawString(draw, offsetX, offsetY, 0x222222);
150151
offsetY += 10;
151-
} else {
152-
List<String> out = fr.listFormattedStringToWidth(I18n.format(status.getUnlocMessage()), (int) ((FACTORY_ELEMENT_WIDTH - 6) / FONT_SCALE));
153-
for (String draw : out) {
154-
fr.drawString(draw, offsetX, offsetY, 0x222222);
155-
offsetY += 10;
156-
}
157152
}
158153

159154
if (activeRecipe != null && activeRecipe.getTotalTick() > 0) {
@@ -233,6 +228,10 @@ private int drawParallelismInfo(int offsetX, int y, FontRenderer fr) {
233228
}
234229
}
235230

231+
if (parallelism <= 1) {
232+
return offsetY;
233+
}
234+
236235
offsetY += 10;
237236
String parallelismStr = I18n.format("gui.controller.parallelism", parallelism);
238237
fr.drawStringWithShadow(parallelismStr, offsetX, offsetY, 0xFFFFFF);

src/main/java/hellfirepvp/modularmachinery/client/util/DynamicMachineRenderContext.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import hellfirepvp.modularmachinery.client.ClientScheduler;
1212
import hellfirepvp.modularmachinery.common.block.BlockController;
13+
import hellfirepvp.modularmachinery.common.block.BlockFactoryController;
14+
import hellfirepvp.modularmachinery.common.data.Config;
1315
import hellfirepvp.modularmachinery.common.lib.BlocksMM;
1416
import hellfirepvp.modularmachinery.common.machine.DynamicMachine;
1517
import hellfirepvp.modularmachinery.common.util.BlockArray;
@@ -24,10 +26,7 @@
2426
import net.minecraftforge.fml.relauncher.Side;
2527
import net.minecraftforge.fml.relauncher.SideOnly;
2628

27-
import java.util.Collections;
28-
import java.util.List;
29-
import java.util.Map;
30-
import java.util.Optional;
29+
import java.util.*;
3130

3231
/**
3332
* This class is part of the Modular Machinery Mod
@@ -67,11 +66,30 @@ private DynamicMachineRenderContext(DynamicMachine machine) {
6766
}
6867

6968
private void addControllerToBlockArray(DynamicMachine machine, BlockArray copy, Vec3i moveOffset) {
69+
// Factory Only
70+
if (machine.isHasFactory() && machine.isFactoryOnly()) {
71+
BlockFactoryController factory = BlockFactoryController.getControllerWithMachine(machine);
72+
if (factory == null) factory = BlocksMM.blockFactoryController;
73+
copy.addBlock(new BlockPos(moveOffset), new BlockArray.BlockInformation(
74+
Collections.singletonList(new IBlockStateDescriptor(factory.getDefaultState()))));
75+
return;
76+
}
77+
78+
List<IBlockStateDescriptor> descriptors = new ArrayList<>();
79+
80+
// Controller
7081
BlockController ctrl = BlockController.getControllerWithMachine(machine);
7182
if (ctrl == null) ctrl = BlocksMM.blockController;
83+
descriptors.add(new IBlockStateDescriptor(ctrl.getDefaultState()));
84+
85+
// Factory
86+
if (machine.isHasFactory() || Config.enableFactoryControllerByDefault) {
87+
BlockFactoryController factory = BlockFactoryController.getControllerWithMachine(machine);
88+
if (factory == null) factory = BlocksMM.blockFactoryController;
89+
descriptors.add(new IBlockStateDescriptor(factory.getDefaultState()));
90+
}
7291

73-
copy.addBlock(new BlockPos(moveOffset), new BlockArray.BlockInformation(
74-
Collections.singletonList(new IBlockStateDescriptor(ctrl.getDefaultState()))));
92+
copy.addBlock(new BlockPos(moveOffset), new BlockArray.BlockInformation(descriptors));
7593
}
7694

7795
public static void addReplacementToBlockArray(

src/main/java/hellfirepvp/modularmachinery/common/block/BlockFactoryController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public BlockFactoryController(DynamicMachine parentMachine) {
5252
);
5353
}
5454

55+
public static BlockFactoryController getControllerWithMachine(DynamicMachine machine) {
56+
return FACOTRY_CONTROLLERS.get(machine);
57+
}
58+
5559
public DynamicMachine getParentMachine() {
5660
return parentMachine;
5761
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import hellfirepvp.modularmachinery.ModularMachinery;
1313
import hellfirepvp.modularmachinery.common.base.Mods;
1414
import hellfirepvp.modularmachinery.common.block.BlockController;
15+
import hellfirepvp.modularmachinery.common.block.BlockFactoryController;
1516
import hellfirepvp.modularmachinery.common.crafting.MachineRecipe;
1617
import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry;
1718
import hellfirepvp.modularmachinery.common.integration.ingredient.HybridFluid;
@@ -139,6 +140,7 @@ public void register(IModRegistry registry) {
139140
RecipeLayoutHelper.init();
140141

141142
registry.addRecipeCatalyst(new ItemStack(BlocksMM.blockController), CATEGORY_PREVIEW);
143+
registry.addRecipeCatalyst(new ItemStack(BlocksMM.blockFactoryController), CATEGORY_PREVIEW);
142144
for (DynamicMachine machine : MachineRegistry.getRegistry()) {
143145
ItemStack stack = new ItemStack(ItemsMM.blueprint);
144146
ItemBlueprint.setAssociatedMachine(stack, machine);
@@ -169,6 +171,10 @@ public void register(IModRegistry registry) {
169171
registry.addRecipeCatalyst(new ItemStack(controller),
170172
getCategoryStringFor(controller.getParentMachine()))
171173
);
174+
BlockFactoryController.FACOTRY_CONTROLLERS.values().forEach(controller ->
175+
registry.addRecipeCatalyst(new ItemStack(controller),
176+
getCategoryStringFor(controller.getParentMachine()))
177+
);
172178
}
173179

174180
@Override

src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineModifier.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public static void setMaxParallelism(String machineName, int maxParallelism) {
5353

5454
@ZenMethod
5555
public static void setMaxThreads(String machineName, int maxThreads) {
56-
if (maxThreads < 1) {
57-
CraftTweakerAPI.logError("Max Threads must larger than 1!");
56+
// Maybe the author only wanted to use the daemon thread?
57+
if (maxThreads < 0) {
58+
CraftTweakerAPI.logError("Max Threads must larger than 0!");
5859
}
5960
WAIT_FOR_MODIFY.add(() -> {
6061
DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineName));

src/main/java/hellfirepvp/modularmachinery/common/integration/preview/StructurePreviewWrapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import hellfirepvp.modularmachinery.client.util.DynamicMachineRenderContext;
1717
import hellfirepvp.modularmachinery.client.util.RenderingUtils;
1818
import hellfirepvp.modularmachinery.common.block.BlockController;
19+
import hellfirepvp.modularmachinery.common.block.BlockFactoryController;
1920
import hellfirepvp.modularmachinery.common.integration.ModIntegrationJEI;
2021
import hellfirepvp.modularmachinery.common.item.ItemBlueprint;
2122
import hellfirepvp.modularmachinery.common.lib.BlocksMM;
@@ -538,6 +539,11 @@ public void getIngredients(@Nonnull IIngredients ingredients) {
538539
ItemStack ctrlStack = new ItemStack(mocCtrl);
539540
stackList.add(ctrlStack);
540541
}
542+
BlockFactoryController factory = BlockFactoryController.getControllerWithMachine(this.machine);
543+
if (factory != null) {
544+
ItemStack factoryStack = new ItemStack(factory);
545+
stackList.add(factoryStack);
546+
}
541547
stackList.add(bOut);
542548

543549
ingredients.setOutputs(VanillaTypes.ITEM, stackList);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static void processFactoryControllerTOP(TileFactoryController factory, I
117117
}
118118

119119
if (status.isCrafting()) {
120-
probeInfo.text(threadName + ": " + TextFormatting.GREEN + "{*top.machine.working*}");
120+
probeInfo.text(threadName + ": " + TextFormatting.GREEN + "{*" + status.getUnlocMessage() + "*}");
121121
} else {
122122
probeInfo.text(threadName + ": " + TextFormatting.RED + "{*" + status.getUnlocMessage() + "*}");
123123
progressBarFilledColor = ModIntegrationTOP.failureProgressBarFilledColor;

src/main/java/hellfirepvp/modularmachinery/common/machine/factory/RecipeThread.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
@ZenRegister
3636
@ZenClass("mods.modularmachinery.RecipeThread")
3737
public class RecipeThread {
38+
public static final int RECIPE_SEARCH_DELAY = 20;
39+
public static final int IDLE_TIME_OUT = 200;
3840
public static final List<Action> WAIT_FOR_ADD = new ArrayList<>();
39-
private static final int RECIPE_SEARCH_DELAY = 20;
4041
private final TreeSet<MachineRecipe> recipeSet = new TreeSet<>();
4142
private final Map<String, RecipeModifier> permanentModifiers = new HashMap<>();
4243
private final Map<String, RecipeModifier> semiPermanentModifiers = new HashMap<>();
44+
public int idleTime = 0;
4345
private TileFactoryController factory;
4446
private boolean isDaemon;
4547
private String threadName;
@@ -78,7 +80,7 @@ public CraftingStatus onTick() {
7880
if (context == null) {
7981
context = createContext(activeRecipe);
8082
}
81-
83+
idleTime = 0;
8284
return (status = activeRecipe.tick(factory, context));
8385
}
8486

@@ -136,6 +138,7 @@ public void searchAndStartRecipe() {
136138
RecipeCraftingContext context = null;
137139
try {
138140
context = searchTask.get();
141+
status = searchTask.getStatus();
139142
} catch (Exception e) {
140143
ModularMachinery.log.warn(ThrowableUtil.stackTraceToString(e));
141144
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import hellfirepvp.modularmachinery.common.crafting.helper.RecipeCraftingContext;
1616
import hellfirepvp.modularmachinery.common.integration.crafttweaker.event.recipe.*;
1717
import hellfirepvp.modularmachinery.common.lib.BlocksMM;
18+
import hellfirepvp.modularmachinery.common.machine.MachineRegistry;
1819
import hellfirepvp.modularmachinery.common.machine.factory.RecipeThread;
1920
import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController;
2021
import io.netty.util.internal.ThrowableUtil;
2122
import net.minecraft.block.state.IBlockState;
2223
import net.minecraft.nbt.NBTTagCompound;
2324
import net.minecraft.nbt.NBTTagList;
2425
import net.minecraft.util.EnumFacing;
26+
import net.minecraft.util.ResourceLocation;
2527
import net.minecraftforge.common.util.Constants;
2628

2729
import javax.annotation.Nonnull;
@@ -98,6 +100,7 @@ public void doRestrictedTick() {
98100
*/
99101
protected void doRecipeTick() {
100102
updateDaemonThread();
103+
cleanIdleTimeoutThread();
101104

102105
daemonRecipeThreads.values().forEach(thread -> {
103106
if (thread.getActiveRecipe() == null) {
@@ -115,6 +118,7 @@ protected void doRecipeTick() {
115118
protected void doThreadRecipeTick(RecipeThread thread) {
116119
ActiveMachineRecipe activeRecipe = thread.getActiveRecipe();
117120
if (activeRecipe == null) {
121+
thread.idleTime++;
118122
return;
119123
}
120124

@@ -396,14 +400,17 @@ protected void createRecipeSearchTask() {
396400
TaskExecutor.FORK_JOIN_POOL.submit(searchTask);
397401
}
398402

403+
/**
404+
* 更新守护线程列表。
405+
*/
399406
protected void updateDaemonThread() {
400407
Map<String, RecipeThread> threads = foundMachine.getDaemonThreads();
401408
if (threads.isEmpty()) {
402409
daemonRecipeThreads.clear();
403410
return;
404411
}
405412

406-
if (ticksExisted % 20 != 0) {
413+
if (!daemonRecipeThreads.isEmpty() && ticksExisted % 20 != 0) {
407414
return;
408415
}
409416

@@ -435,6 +442,19 @@ protected void updateDaemonThread() {
435442
}
436443
}
437444

445+
/**
446+
* 清理闲置时间过长的线程。
447+
*/
448+
protected void cleanIdleTimeoutThread() {
449+
for (int i = 0; i < recipeThreadList.size(); i++) {
450+
RecipeThread thread = recipeThreadList.get(i);
451+
if (thread.isIdle() && thread.idleTime >= RecipeThread.IDLE_TIME_OUT) {
452+
recipeThreadList.remove(i);
453+
i--;
454+
}
455+
}
456+
}
457+
438458
public boolean hasIdleThread() {
439459
if (recipeThreadList.size() < foundMachine.getMaxThreads()) {
440460
return true;
@@ -489,6 +509,20 @@ public void readCustomNBT(NBTTagCompound compound) {
489509
}
490510
}
491511

512+
@Override
513+
protected void readMachineNBT(NBTTagCompound compound) {
514+
if (compound.hasKey("parentMachine")) {
515+
ResourceLocation rl = new ResourceLocation(compound.getString("parentMachine"));
516+
parentMachine = MachineRegistry.getRegistry().getMachine(rl);
517+
if (parentMachine != null) {
518+
parentController = BlockFactoryController.FACOTRY_CONTROLLERS.get(parentMachine);
519+
} else {
520+
ModularMachinery.log.info("Couldn't find machine named " + rl + " for controller at " + getPos());
521+
}
522+
}
523+
super.readMachineNBT(compound);
524+
}
525+
492526
@Override
493527
public void writeCustomNBT(NBTTagCompound compound) {
494528
super.writeCustomNBT(compound);

0 commit comments

Comments
 (0)