Skip to content

Commit bf0b322

Browse files
add Additional Enchanted Miner compat (#282)
* add WorkBenchPlus injection * add * add * add * add * Update src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkBenchPlus.java Co-authored-by: Waiting Idly <[email protected]> * add * fix * fix * remove WorkbenchPlusRecipe.java * miss --------- Co-authored-by: Waiting Idly <[email protected]>
1 parent 4a0cfc2 commit bf0b322

File tree

7 files changed

+158
-0
lines changed

7 files changed

+158
-0
lines changed

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
// Sorted by alphabetical name of the `project.debug_[this]` value
2929
final def mod_dependencies = [
3030
'actually-additions-228404:3117927' : [project.debug_actually_additions],
31+
'additionalenchantedminer-282837:3851282' : [project.debug_additional_enchanted_miner],
3132
'advancedmortars-283777:2780626' : [project.debug_adv_mortars],
3233
'advanced-rocketry-236542:4671856' : [project.debug_advanced_rocketry],
3334
'libvulpes-236541:3801015' : [project.debug_advanced_rocketry],
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// Auto generated groovyscript example file
3+
// MODS_LOADED: quarryplus
4+
5+
log.info 'mod \'quarryplus\' detected, running script'
6+
7+
// Work bench:
8+
// Workbench for crafting items using electricity.
9+
10+
mods.quarryplus.work_bench_plus.removeByOutput(item('quarryplus:quarry'))
11+
// mods.quarryplus.work_bench_plus.removeAll()
12+
13+
mods.quarryplus.work_bench_plus.recipeBuilder()
14+
.output(item('minecraft:nether_star'))
15+
.input(item('minecraft:diamond'),item('minecraft:gold_ingot'))
16+
.energy(10000)
17+
.register()
18+
19+

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ debug_disable_cache = false
1414
# SECTION: debug mod compat
1515

1616
debug_actually_additions = false
17+
debug_additional_enchanted_miner = false
1718
debug_adv_mortars = false
1819
debug_advanced_rocketry = false
1920
debug_aether = false

src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
55
import com.cleanroommc.groovyscript.api.GroovyPlugin;
66
import com.cleanroommc.groovyscript.compat.mods.actuallyadditions.ActuallyAdditions;
7+
import com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer.AdditionalEnchantedMiner;
78
import com.cleanroommc.groovyscript.compat.mods.advancedmortars.AdvancedMortars;
89
import com.cleanroommc.groovyscript.compat.mods.advancedrocketry.AdvancedRocketry;
910
import com.cleanroommc.groovyscript.compat.mods.aetherlegacy.Aether;
@@ -85,6 +86,7 @@ public class ModSupport {
8586
public static final ModSupport INSTANCE = new ModSupport(); // Just for Binding purposes
8687

8788
public static final GroovyContainer<ActuallyAdditions> ACTUALLY_ADDITIONS = new InternalModContainer<>("actuallyadditions", "Actually Additions", ActuallyAdditions::new, "aa");
89+
public static final GroovyContainer<AdditionalEnchantedMiner> ADDITIONAL_ENCHANTED_MINER = new InternalModContainer<>("quarryplus", "Additional Enchanted Miner", AdditionalEnchantedMiner::new);
8890
public static final GroovyContainer<AdvancedMortars> ADVANCED_MORTARS = new InternalModContainer<>("advancedmortars", "Advanced Mortars", AdvancedMortars::new);
8991
public static final GroovyContainer<AdvancedRocketry> ADVANCED_ROCKETRY = new InternalModContainer<>("advancedrocketry", "Advanced Rocketry", AdvancedRocketry::new);
9092
public static final GroovyContainer<Aether> AETHER = new InternalModContainer<>("aether_legacy", "Aether Legacy", Aether::new, "aether");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer;
2+
3+
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
4+
5+
public class AdditionalEnchantedMiner extends GroovyPropertyContainer {
6+
7+
public final WorkBenchPlus workBenchPlus = new WorkBenchPlus();
8+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer;
2+
3+
import com.cleanroommc.groovyscript.api.GroovyLog;
4+
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
5+
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
6+
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
7+
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
8+
import com.yogpc.qp.recipe.IngredientRecipe;
9+
import com.yogpc.qp.recipe.WorkbenchRecipe;
10+
import com.yogpc.qp.tile.ItemDamage;
11+
import com.yogpc.qp.utils.IngredientWithCount;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.util.ResourceLocation;
14+
import org.jetbrains.annotations.Nullable;
15+
import scala.collection.JavaConversions;
16+
import scala.collection.JavaConverters;
17+
import scala.collection.Seq;
18+
import scala.collection.SeqLike;
19+
import scala.collection.convert.Decorators;
20+
import scala.collection.immutable.Map;
21+
22+
import java.util.Collections;
23+
import java.util.List;
24+
import java.util.stream.Collectors;
25+
26+
@RegistryDescription
27+
public class WorkBenchPlus extends VirtualizedRegistry<IngredientRecipe> {
28+
29+
@Override
30+
public void onReload() {
31+
removeScripted().forEach(recipe -> WorkbenchRecipe.removeRecipe(recipe.location()));
32+
restoreFromBackup().forEach(recipe -> WorkbenchRecipe.addIngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.inputs(), recipe.hardCode(), recipe.showInJEI()));
33+
}
34+
35+
@MethodDescription(example = @Example("item('quarryplus:quarry')"))
36+
public void removeByOutput(ItemStack output) {
37+
ItemDamage itemDamage = ItemDamage.apply(output);
38+
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap();
39+
Iterable<WorkbenchRecipe> iterable = JavaConversions.asJavaIterable(recipeMap.values());
40+
iterable.forEach(recipe -> {
41+
if (recipe.key().equals(itemDamage)) {
42+
addBackup(new IngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.showInJEI(), recipe.inputs(), recipe.hardCode()));
43+
}
44+
});
45+
WorkbenchRecipe.removeRecipe(ItemDamage.apply(output));
46+
}
47+
48+
@MethodDescription(priority = 2000, example = @Example(commented = true))
49+
public void removeAll() {
50+
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap();
51+
Iterable<ResourceLocation> iterableLocation = JavaConversions.asJavaIterable(recipeMap.keys());
52+
Iterable<WorkbenchRecipe> iterableRecipe = JavaConversions.asJavaIterable(recipeMap.values());
53+
iterableLocation.forEach(
54+
WorkbenchRecipe::removeRecipe
55+
);
56+
iterableRecipe.forEach(
57+
recipe -> addBackup(new IngredientRecipe(recipe.location(),recipe.getOutput(),recipe.energy(),recipe.showInJEI(),recipe.inputs(),recipe.hardCode()))
58+
);
59+
}
60+
61+
private void add(IngredientRecipe recipe) {
62+
addScripted(recipe);
63+
WorkbenchRecipe.addIngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.inputs(), recipe.hardCode(), recipe.showInJEI());
64+
}
65+
66+
@RecipeBuilderDescription(example = @Example(".output(item('minecraft:nether_star')).input(item('minecraft:diamond'),item('minecraft:gold_ingot')).energy(10000)"))
67+
public RecipeBuilder recipeBuilder() {
68+
return new RecipeBuilder();
69+
}
70+
71+
@Property(property = "input", comp = @Comp(gte = 1, lte = 27))
72+
@Property(property = "output", comp = @Comp(eq = 1))
73+
public static class RecipeBuilder extends AbstractRecipeBuilder<IngredientRecipe> {
74+
75+
@Property(comp = @Comp(gt = 0))
76+
private double energy;
77+
78+
@RecipeBuilderMethodDescription
79+
public RecipeBuilder energy(double energy) {
80+
this.energy = energy;
81+
return this;
82+
}
83+
84+
@Override
85+
public String getRecipeNamePrefix() {
86+
return "additionalenchantedminer_workbenchplus_";
87+
}
88+
89+
@Override
90+
public String getErrorMsg() {
91+
return "Error adding Additional Enchanted Miner WorkbenchPlus recipe";
92+
}
93+
94+
@Override
95+
public void validate(GroovyLog.Msg msg) {
96+
validateName();
97+
validateItems(msg, 1, 27, 1, 1);
98+
msg.add(energy <= 0, "energy must be an integer greater than 0, yet it was {}", energy);
99+
}
100+
101+
@Override
102+
@RecipeBuilderRegistrationMethod
103+
public @Nullable IngredientRecipe register() {
104+
if (!validate()) return null;
105+
//convert Java List to Scala Seq
106+
List<List<IngredientWithCount>> inputJavaList = input.stream()
107+
.map(i -> {
108+
IngredientWithCount ingredient = new IngredientWithCount(i.toMcIngredient(), i.getAmount());
109+
return Collections.singletonList(ingredient);
110+
})
111+
.collect(Collectors.toList());
112+
Seq<Seq<IngredientWithCount>> inputScalaList = JavaConverters.asScalaBufferConverter(
113+
inputJavaList.stream()
114+
.map(JavaConverters::asScalaBufferConverter)
115+
.map(Decorators.AsScala::asScala)
116+
.map(SeqLike::toSeq)
117+
.collect(Collectors.toList())).asScala().toSeq();
118+
IngredientRecipe recipe = new IngredientRecipe(this.name, output.get(0), energy, true, inputScalaList, true);
119+
ModSupport.ADDITIONAL_ENCHANTED_MINER.get().workBenchPlus.add(recipe);
120+
return recipe;
121+
}
122+
}
123+
}

src/main/resources/assets/groovyscript/lang/en_us.lang

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ groovyscript.wiki.actuallyadditions.treasure_chest.min.required=less than or equ
174174
groovyscript.wiki.actuallyadditions.treasure_chest.max.value=Sets the maximum stack size given when rolled
175175
groovyscript.wiki.actuallyadditions.treasure_chest.max.required=greater than or equal to the size of min
176176

177+
#Additional Enchanted Miner
178+
groovyscript.wiki.quarryplus.work_bench_plus.title=Work bench
179+
groovyscript.wiki.quarryplus.work_bench_plus.description=Workbench for crafting items using electricity.
180+
177181
# Advanced Mortars
178182
groovyscript.wiki.advancedmortars.mortar.title=Mortar
179183
groovyscript.wiki.advancedmortars.mortar.description=Uses any number of specific types of Mortars to convert multiple items into a single output with a possible chance output after a number of player interactions.

0 commit comments

Comments
 (0)