Skip to content

Commit 7db9528

Browse files
committed
允许crt编写的配方不显示在JEI中,使用setLoadJEI(boolean)设置可见性,默认为true
1 parent 34ab8a1 commit 7db9528

5 files changed

Lines changed: 40 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class MachineRecipe implements Comparable<MachineRecipe> {
5151

5252
protected static int counter = 0;
5353

54+
protected final boolean loadJEI;
5455
protected final int sortId;
5556
protected final String recipeFilePath;
5657
protected final ResourceLocation owningMachine, registryName;
@@ -81,12 +82,13 @@ public MachineRecipe(String path, ResourceLocation registryName, ResourceLocatio
8182
this.tooltipList = new ArrayList<>();
8283
this.threadName = "";
8384
this.maxThreads = -1;
85+
this.loadJEI = true;
8486
}
8587

8688
public MachineRecipe(String path, ResourceLocation registryName, ResourceLocation owningMachine,
8789
int tickTime, int configuredPriority, boolean voidPerTickFailure, boolean parallelized,
8890
Map<Class<?>, List<IEventHandler<RecipeEvent>>> recipeEventHandlers, List<String> tooltipList,
89-
String threadName, int maxThreads) {
91+
String threadName, int maxThreads, boolean loadJEI) {
9092
this.sortId = counter;
9193
counter++;
9294
this.recipeFilePath = path;
@@ -100,6 +102,7 @@ public MachineRecipe(String path, ResourceLocation registryName, ResourceLocatio
100102
this.tooltipList = tooltipList;
101103
this.threadName = threadName;
102104
this.maxThreads = maxThreads;
105+
this.loadJEI = loadJEI;
103106
}
104107

105108
public MachineRecipe(PreparedRecipe preparedRecipe) {
@@ -116,6 +119,7 @@ public MachineRecipe(PreparedRecipe preparedRecipe) {
116119
this.tooltipList = preparedRecipe.getTooltipList();
117120
this.threadName = preparedRecipe.getThreadName();
118121
this.maxThreads = preparedRecipe.getMaxThreads();
122+
this.loadJEI = preparedRecipe.getLoadJEI();
119123
}
120124

121125
public void mergeAdapter(final RecipeAdapterBuilder adapterBuilder) {
@@ -148,7 +152,6 @@ public List<String> getFormattedTooltip() {
148152
.collect(Collectors.toList());
149153
}
150154

151-
@SuppressWarnings("unchecked")
152155
public <H extends RecipeEvent> void addRecipeEventHandler(Class<?> hClass, IEventHandler<H> handler) {
153156
recipeEventHandlers.putIfAbsent(hClass, new ArrayList<>());
154157
recipeEventHandlers.get(hClass).add((IEventHandler<RecipeEvent>) handler);
@@ -171,6 +174,10 @@ public String getRecipeFilePath() {
171174
return recipeFilePath;
172175
}
173176

177+
public boolean getLoadJEI(){
178+
return loadJEI;
179+
}
180+
174181
public ResourceLocation getRegistryName() {
175182
return registryName;
176183
}
@@ -236,7 +243,9 @@ public MachineRecipe copy(Function<ResourceLocation, ResourceLocation> registryN
236243
this.recipeEventHandlers,
237244
this.tooltipList,
238245
this.threadName,
239-
this.maxThreads);
246+
this.maxThreads,
247+
this.loadJEI
248+
);
240249

241250
for (ComponentRequirement<?, ?> requirement : this.getCraftingRequirements()) {
242251
copy.addRequirement(requirement.deepCopyModified(modifiers).postDeepCopy(requirement));
@@ -433,8 +442,7 @@ public static class ComponentDeserializer implements JsonDeserializer<ComponentR
433442
if (requirementType == null) {
434443
requirementType = IntegrationTypeHelper.searchRequirementType(type);
435444
if (requirementType != null) {
436-
ModularMachinery.log.info("[Modular Machinery]: Deprecated requirement name '"
437-
+ type + "'! Consider using " + requirementType.getRegistryName().toString());
445+
ModularMachinery.log.info("[Modular Machinery]: Deprecated requirement name '{}'! Consider using {}", type, requirementType.getRegistryName().toString());
438446
}
439447
}
440448
if (requirementType == null) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface PreparedRecipe {
3030
ResourceLocation getRecipeRegistryName();
3131

3232
ResourceLocation getAssociatedMachineName();
33+
3334
ResourceLocation getParentMachineName();
3435

3536
int getTotalProcessingTickTime();
@@ -45,8 +46,14 @@ default boolean voidPerTickFailure() {
4546
Map<Class<?>, List<IEventHandler<RecipeEvent>>> getRecipeEventHandlers();
4647

4748
List<String> getTooltipList();
49+
4850
boolean isParallelized();
51+
4952
int getMaxThreads();
53+
5054
String getThreadName();
55+
5156
void loadNeedAfterInitActions();
57+
58+
boolean getLoadJEI();
5259
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public static void reloadRecipeWrappers() {
9898
Iterable<MachineRecipe> recipes = RecipeRegistry.getRecipesFor(machine);
9999
Map<ResourceLocation, DynamicRecipeWrapper> wrappers = MACHINE_RECIPE_WRAPPERS.computeIfAbsent(machine, v -> new LinkedHashMap<>());
100100
for (MachineRecipe recipe : recipes) {
101+
if (!recipe.getLoadJEI())continue;
101102
DynamicRecipeWrapper wrapper = wrappers.get(recipe.getRegistryName());
102103
if (wrapper != null) {
103104
wrapper.reloadWrapper(recipe);
@@ -202,6 +203,7 @@ public void register(IModRegistry registry) {
202203
Iterable<MachineRecipe> recipes = RecipeRegistry.getRecipesFor(machine);
203204
Map<ResourceLocation, DynamicRecipeWrapper> wrappers = MACHINE_RECIPE_WRAPPERS.computeIfAbsent(machine, v -> new LinkedHashMap<>());
204205
for (MachineRecipe recipe : recipes) {
206+
if (!recipe.getLoadJEI())continue;
205207
wrappers.put(recipe.getRegistryName(), new DynamicRecipeWrapper(recipe));
206208
}
207209
registry.addRecipes(wrappers.values(), getCategoryStringFor(machine));

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class RecipePrimer implements PreparedRecipe {
6969
private final Map<Class<?>, List<IEventHandler<RecipeEvent>>> recipeEventHandlers = new HashMap<>();
7070

7171
private boolean parallelized = Config.recipeParallelizeEnabledByDefault;
72+
private boolean loadJEI = true;
7273
private int maxThreads = -1;
7374
private String threadName = "";
7475
private ComponentRequirement<?, ?> lastComponent = null;
@@ -374,7 +375,6 @@ public RecipePrimer addFactoryFinishHandler(IEventHandler<FactoryRecipeFinishEve
374375
return this;
375376
}
376377

377-
@SuppressWarnings("unchecked")
378378
private <H extends RecipeEvent> void addRecipeEventHandler(Class<H> hClass, IEventHandler<H> handler) {
379379
recipeEventHandlers.putIfAbsent(hClass, new ArrayList<>());
380380
recipeEventHandlers.get(hClass).add((IEventHandler<RecipeEvent>) handler);
@@ -649,6 +649,16 @@ public RecipePrimer addIngredientArrayInput(IngredientArrayPrimer ingredientArra
649649
return this;
650650
}
651651

652+
/**
653+
* <p>设置为false时不再为JEI注册对应配方</p>
654+
* <p>默认情况在为true</p>
655+
*/
656+
@ZenMethod
657+
public RecipePrimer setLoadJEI(boolean load) {
658+
this.loadJEI = load;
659+
return this;
660+
}
661+
652662
/**
653663
* <p>随机选择给定的一组物品中的其中一个输出。</p>
654664
* <p>虽然都使用 IngredientArrayPrimer 作为参数,但是输出的工作机制要<strong>稍有不同</strong>。</p>
@@ -936,4 +946,9 @@ public void loadNeedAfterInitActions() {
936946
needAfterInitAction.doAction();
937947
}
938948
}
949+
950+
@Override
951+
public boolean getLoadJEI() {
952+
return loadJEI;
953+
}
939954
}

src/main/java/hellfirepvp/modularmachinery/common/integration/recipe/CategoryDynamicRecipe.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private Point buildRecipeComponents() {
8383
int widestTooltip = 0;
8484

8585
for (MachineRecipe recipe : recipes) {
86+
if (!recipe.getLoadJEI())continue;
8687
Map<IOType, Object2IntOpenHashMap<Class<?>>> tempComp = new EnumMap<>(IOType.class);
8788
for (ComponentRequirement<?, ?> req : recipe.getCraftingRequirements()) {
8889
req.initializeJEIRequirements();
@@ -264,7 +265,7 @@ public void drawExtras(@Nonnull Minecraft minecraft) {
264265
}
265266

266267
@Override
267-
@SuppressWarnings({"rawtypes", "unchecked"})
268+
@SuppressWarnings({"rawtypes"})
268269
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull DynamicRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) {
269270
List<Class<?>> foundClasses = new LinkedList<>();
270271

0 commit comments

Comments
 (0)