Skip to content

Commit 73e8d24

Browse files
authored
add Horse Power compat (#251)
* skip documenting bridge methods * Horse Power compat
1 parent 68ef30d commit 73e8d24

File tree

12 files changed

+817
-0
lines changed

12 files changed

+817
-0
lines changed

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ final def mod_dependencies = [
7171
'extra-utilities-2-225561:2678374' : [project.debug_extra_utilities_2],
7272
'forestry-59751:2918418' : [project.debug_forestry],
7373
'future-mc-310059:5626387' : [project.debug_future_mc],
74+
'horse-power-270466:2705433' : [project.debug_horse_power],
7475
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering, project.debug_immersive_petroleum, project.debug_immersive_technology],
7576
'immersive-petroleum-268250:3382321' : [project.debug_immersive_petroleum],
7677
'mct-immersive-technology-359407:5108047' : [project.debug_immersive_technology],

examples/postInit/horsepower.groovy

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
// Auto generated groovyscript example file
3+
// MODS_LOADED: horsepower
4+
5+
log.info 'mod \'horsepower\' detected, running script'
6+
7+
// Horse Chopping Block:
8+
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
9+
// amount of processing has been done. Depending on if the config option `Separate Chopping Recipes` is true, this may
10+
// affect both Horse and Hand Chopping Blocks. Only the Horse Chopping Block can produce secondary outputs.
11+
12+
mods.horsepower.chopping_block.removeByInput(item('minecraft:log:3'))
13+
mods.horsepower.chopping_block.removeByOutput(item('minecraft:planks:4'))
14+
// mods.horsepower.chopping_block.removeAll()
15+
16+
mods.horsepower.chopping_block.recipeBuilder()
17+
.input(item('minecraft:clay'))
18+
.output(item('minecraft:diamond') * 5)
19+
.time(5)
20+
.register()
21+
22+
mods.horsepower.chopping_block.recipeBuilder()
23+
.input(item('minecraft:diamond'))
24+
.output(item('minecraft:gold_ingot'))
25+
.time(1)
26+
.register()
27+
28+
mods.horsepower.chopping_block.recipeBuilder()
29+
.input(item('minecraft:gold_ingot'))
30+
.output(item('minecraft:clay'), item('minecraft:diamond'))
31+
.chance(50)
32+
.time(2)
33+
.register()
34+
35+
36+
// Horse Grindstone:
37+
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
38+
// amount of processing has been done. Depending on if the config option `Separate Grindstone Recipes` is true, this may
39+
// affect both Horse and Hand Grindstones.
40+
41+
mods.horsepower.grindstone.removeByInput(item('minecraft:double_plant:4'))
42+
mods.horsepower.grindstone.removeByOutput(item('minecraft:sugar'))
43+
// mods.horsepower.grindstone.removeAll()
44+
45+
mods.horsepower.grindstone.recipeBuilder()
46+
.input(item('minecraft:clay'))
47+
.output(item('minecraft:diamond') * 5)
48+
.time(5)
49+
.register()
50+
51+
mods.horsepower.grindstone.recipeBuilder()
52+
.input(item('minecraft:diamond'))
53+
.output(item('minecraft:gold_ingot'))
54+
.time(1)
55+
.register()
56+
57+
mods.horsepower.grindstone.recipeBuilder()
58+
.input(item('minecraft:gold_ingot'))
59+
.output(item('minecraft:clay'), item('minecraft:diamond'))
60+
.chance(50)
61+
.time(2)
62+
.register()
63+
64+
65+
// Manual Chopping Block:
66+
// Converts an itemstack input into an itemstack output after a configurable amount of processing has been done. Depending
67+
// on if the config option `Separate Chopping Recipes` is true, this may affect both Horse and Hand Chopping Blocks.
68+
69+
mods.horsepower.manual_chopping_block.removeByInput(item('minecraft:log:3'))
70+
mods.horsepower.manual_chopping_block.removeByOutput(item('minecraft:planks:4'))
71+
// mods.horsepower.manual_chopping_block.removeAll()
72+
73+
mods.horsepower.manual_chopping_block.recipeBuilder()
74+
.input(item('minecraft:clay'))
75+
.output(item('minecraft:diamond') * 5)
76+
.time(5)
77+
.register()
78+
79+
mods.horsepower.manual_chopping_block.recipeBuilder()
80+
.input(item('minecraft:diamond'))
81+
.output(item('minecraft:gold_ingot'))
82+
.time(1)
83+
.register()
84+
85+
86+
// Manual Grindstone:
87+
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
88+
// amount of processing has been done. Depending on if the config option `Separate Grindstone Recipes` is true, this may
89+
// affect both Horse and Hand Grindstones.
90+
91+
mods.horsepower.manual_grindstone.removeByInput(item('minecraft:double_plant:4'))
92+
mods.horsepower.manual_grindstone.removeByOutput(item('minecraft:sugar'))
93+
// mods.horsepower.manual_grindstone.removeAll()
94+
95+
mods.horsepower.manual_grindstone.recipeBuilder()
96+
.input(item('minecraft:clay'))
97+
.output(item('minecraft:diamond') * 5)
98+
.time(5)
99+
.register()
100+
101+
mods.horsepower.manual_grindstone.recipeBuilder()
102+
.input(item('minecraft:diamond'))
103+
.output(item('minecraft:gold_ingot'))
104+
.time(1)
105+
.register()
106+
107+
mods.horsepower.manual_grindstone.recipeBuilder()
108+
.input(item('minecraft:gold_ingot'))
109+
.output(item('minecraft:clay'), item('minecraft:diamond'))
110+
.chance(50)
111+
.time(2)
112+
.register()
113+
114+
115+
// Horse Press:
116+
// Converts an itemstack into another itemstack or a fluidstack by a horse running laps.
117+
118+
mods.horsepower.press.removeByInput(item('minecraft:wheat_seeds'))
119+
mods.horsepower.press.removeByOutput(fluid('water'))
120+
// mods.horsepower.press.removeByOutput(item('minecraft:dirt'))
121+
// mods.horsepower.press.removeAll()
122+
123+
mods.horsepower.press.recipeBuilder()
124+
.input(item('minecraft:clay'))
125+
.output(item('minecraft:diamond') * 5)
126+
.register()
127+
128+
mods.horsepower.press.recipeBuilder()
129+
.input(item('minecraft:diamond'))
130+
.fluidOutput(fluid('lava') * 500)
131+
.register()
132+
133+

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ debug_extra_utilities_2 = false
4747
debug_forestry = false
4848
debug_future_mc = false
4949

50+
debug_horse_power = false
51+
5052
debug_immersive_engineering = false
5153
debug_immersive_petroleum = false
5254
debug_immersive_technology = 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
@@ -31,6 +31,7 @@
3131
import com.cleanroommc.groovyscript.compat.mods.extrautils2.ExtraUtils2;
3232
import com.cleanroommc.groovyscript.compat.mods.forestry.Forestry;
3333
import com.cleanroommc.groovyscript.compat.mods.futuremc.FutureMC;
34+
import com.cleanroommc.groovyscript.compat.mods.horsepower.HorsePower;
3435
import com.cleanroommc.groovyscript.compat.mods.ic2.IC2;
3536
import com.cleanroommc.groovyscript.compat.mods.immersiveengineering.ImmersiveEngineering;
3637
import com.cleanroommc.groovyscript.compat.mods.immersivepetroleum.ImmersivePetroleum;
@@ -106,6 +107,7 @@ public class ModSupport {
106107
public static final GroovyContainer<ExtraUtils2> EXTRA_UTILITIES_2 = new InternalModContainer<>("extrautils2", "Extra Utilities 2", ExtraUtils2::new, "extrautilities2");
107108
public static final GroovyContainer<Forestry> FORESTRY = new InternalModContainer<>("forestry", "Forestry", Forestry::new);
108109
public static final GroovyContainer<FutureMC> FUTURE_MC = new InternalModContainer<>("futuremc", "Future MC", FutureMC::new);
110+
public static final GroovyContainer<HorsePower> HORSE_POWER = new InternalModContainer<>("horsepower", "Horse Power", HorsePower::new);
109111
public static final GroovyContainer<ImmersiveEngineering> IMMERSIVE_ENGINEERING = new InternalModContainer<>("immersiveengineering", "Immersive Engineering", ImmersiveEngineering::new, "ie");
110112
public static final GroovyContainer<ImmersivePetroleum> IMMERSIVE_PETROLEUM = new InternalModContainer<>("immersivepetroleum", "Immersive Petroleum", ImmersivePetroleum::new);
111113
public static final GroovyContainer<ImmersiveTechnology> IMMERSIVE_TECHNOLOGY = new InternalModContainer<>("immersivetech", "Immersive Technology", ImmersiveTechnology::new);
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.cleanroommc.groovyscript.compat.mods.horsepower;
2+
3+
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
4+
import com.cleanroommc.groovyscript.api.GroovyLog;
5+
import com.cleanroommc.groovyscript.api.IIngredient;
6+
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
7+
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
8+
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
9+
import com.cleanroommc.groovyscript.registry.StandardListRegistry;
10+
import net.minecraft.item.ItemStack;
11+
import org.jetbrains.annotations.ApiStatus;
12+
import org.jetbrains.annotations.Nullable;
13+
import se.gory_moon.horsepower.recipes.ChoppingBlockRecipe;
14+
import se.gory_moon.horsepower.recipes.HPRecipes;
15+
16+
import java.util.Collection;
17+
18+
@RegistryDescription
19+
public class ChoppingBlock extends StandardListRegistry<ChoppingBlockRecipe> {
20+
21+
@RecipeBuilderDescription(example = {
22+
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond') * 5).time(5)"),
23+
@Example(".input(item('minecraft:diamond')).output(item('minecraft:gold_ingot')).time(1)"),
24+
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'), item('minecraft:diamond')).chance(50).time(2)")
25+
})
26+
public static RecipeBuilder recipeBuilder() {
27+
return new RecipeBuilder();
28+
}
29+
30+
// have to override onReload and add to add recipes to the registry due to the actual setup being a map
31+
@Override
32+
public Collection<ChoppingBlockRecipe> getRecipes() {
33+
return HPRecipes.instance().getChoppingRecipes();
34+
}
35+
36+
@Override
37+
@GroovyBlacklist
38+
@ApiStatus.Internal
39+
public void onReload() {
40+
var recipes = getRecipes();
41+
recipes.removeAll(removeScripted());
42+
for (var recipe : restoreFromBackup()) {
43+
HPRecipes.instance().addChoppingRecipe(recipe, false);
44+
}
45+
}
46+
47+
@Override
48+
@MethodDescription(type = MethodDescription.Type.ADDITION, description = "groovyscript.wiki.add_to_list", priority = 500)
49+
public boolean add(ChoppingBlockRecipe recipe) {
50+
HPRecipes.instance().addChoppingRecipe(recipe, false);
51+
return recipe != null && doAddScripted(recipe);
52+
}
53+
54+
@MethodDescription(description = "groovyscript.wiki.horsepower.chopping_block.add0", type = MethodDescription.Type.ADDITION)
55+
public ChoppingBlockRecipe add(IIngredient input, ItemStack output, int time) {
56+
return recipeBuilder()
57+
.time(time)
58+
.output(output)
59+
.input(input)
60+
.register();
61+
}
62+
63+
@MethodDescription(description = "groovyscript.wiki.horsepower.chopping_block.add1", type = MethodDescription.Type.ADDITION)
64+
public ChoppingBlockRecipe add(IIngredient input, ItemStack output, ItemStack secondary, int chance, int time) {
65+
return recipeBuilder()
66+
.time(time)
67+
.chance(chance)
68+
.output(output, secondary)
69+
.input(input)
70+
.register();
71+
}
72+
73+
@MethodDescription(example = @Example("item('minecraft:log:3')"))
74+
public boolean removeByInput(IIngredient input) {
75+
return getRecipes().removeIf(entry -> input.test(entry.getInput()) && doAddBackup(entry));
76+
}
77+
78+
@MethodDescription(example = @Example("item('minecraft:planks:4')"))
79+
public boolean removeByOutput(IIngredient output) {
80+
return getRecipes().removeIf(entry -> (output.test(entry.getOutput()) || output.test(entry.getSecondary())) && doAddBackup(entry));
81+
}
82+
83+
@Property(property = "input", comp = @Comp(eq = 1))
84+
@Property(property = "output", comp = @Comp(gte = 1, lte = 2))
85+
public static class RecipeBuilder extends AbstractRecipeBuilder<ChoppingBlockRecipe> {
86+
87+
@Property(comp = @Comp(gte = 0, lte = 100))
88+
private int chance;
89+
@Property(comp = @Comp(gt = 0))
90+
private int time;
91+
92+
@RecipeBuilderMethodDescription
93+
public RecipeBuilder chance(int chance) {
94+
this.chance = chance;
95+
return this;
96+
}
97+
98+
@RecipeBuilderMethodDescription
99+
public RecipeBuilder time(int time) {
100+
this.time = time;
101+
return this;
102+
}
103+
104+
// todo this can only handle an input with a size of 1, should validate that here
105+
106+
@Override
107+
public String getErrorMsg() {
108+
return "Error adding Horse Power Chopping Block recipe";
109+
}
110+
111+
@Override
112+
public void validate(GroovyLog.Msg msg) {
113+
validateItems(msg, 1, 1, 1, 2);
114+
validateFluids(msg);
115+
msg.add(chance < 0 || chance > 100, "chance must be a non negative integer less than 100, yet it was {}", chance);
116+
msg.add(time <= 0, "time must be greater than 0, yet it was {}", time);
117+
}
118+
119+
@Override
120+
@RecipeBuilderRegistrationMethod
121+
public @Nullable ChoppingBlockRecipe register() {
122+
if (!validate()) return null;
123+
ChoppingBlockRecipe recipe = null;
124+
for (var stack : input.get(0).getMatchingStacks()) {
125+
recipe = new ChoppingBlockRecipe(stack, output.get(0), output.getOrEmpty(1), chance, time);
126+
ModSupport.HORSE_POWER.get().choppingBlock.add(recipe);
127+
}
128+
return recipe;
129+
}
130+
131+
}
132+
133+
}

0 commit comments

Comments
 (0)