Skip to content

Commit

Permalink
add Horse Power compat (#251)
Browse files Browse the repository at this point in the history
* skip documenting bridge methods

* Horse Power compat
  • Loading branch information
WaitingIdly authored Nov 8, 2024
1 parent 68ef30d commit 73e8d24
Show file tree
Hide file tree
Showing 12 changed files with 817 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ final def mod_dependencies = [
'extra-utilities-2-225561:2678374' : [project.debug_extra_utilities_2],
'forestry-59751:2918418' : [project.debug_forestry],
'future-mc-310059:5626387' : [project.debug_future_mc],
'horse-power-270466:2705433' : [project.debug_horse_power],
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering, project.debug_immersive_petroleum, project.debug_immersive_technology],
'immersive-petroleum-268250:3382321' : [project.debug_immersive_petroleum],
'mct-immersive-technology-359407:5108047' : [project.debug_immersive_technology],
Expand Down
133 changes: 133 additions & 0 deletions examples/postInit/horsepower.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@

// Auto generated groovyscript example file
// MODS_LOADED: horsepower

log.info 'mod \'horsepower\' detected, running script'

// Horse Chopping Block:
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
// amount of processing has been done. Depending on if the config option `Separate Chopping Recipes` is true, this may
// affect both Horse and Hand Chopping Blocks. Only the Horse Chopping Block can produce secondary outputs.

mods.horsepower.chopping_block.removeByInput(item('minecraft:log:3'))
mods.horsepower.chopping_block.removeByOutput(item('minecraft:planks:4'))
// mods.horsepower.chopping_block.removeAll()

mods.horsepower.chopping_block.recipeBuilder()
.input(item('minecraft:clay'))
.output(item('minecraft:diamond') * 5)
.time(5)
.register()

mods.horsepower.chopping_block.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:gold_ingot'))
.time(1)
.register()

mods.horsepower.chopping_block.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'), item('minecraft:diamond'))
.chance(50)
.time(2)
.register()


// Horse Grindstone:
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
// amount of processing has been done. Depending on if the config option `Separate Grindstone Recipes` is true, this may
// affect both Horse and Hand Grindstones.

mods.horsepower.grindstone.removeByInput(item('minecraft:double_plant:4'))
mods.horsepower.grindstone.removeByOutput(item('minecraft:sugar'))
// mods.horsepower.grindstone.removeAll()

mods.horsepower.grindstone.recipeBuilder()
.input(item('minecraft:clay'))
.output(item('minecraft:diamond') * 5)
.time(5)
.register()

mods.horsepower.grindstone.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:gold_ingot'))
.time(1)
.register()

mods.horsepower.grindstone.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'), item('minecraft:diamond'))
.chance(50)
.time(2)
.register()


// Manual Chopping Block:
// Converts an itemstack input into an itemstack output after a configurable amount of processing has been done. Depending
// on if the config option `Separate Chopping Recipes` is true, this may affect both Horse and Hand Chopping Blocks.

mods.horsepower.manual_chopping_block.removeByInput(item('minecraft:log:3'))
mods.horsepower.manual_chopping_block.removeByOutput(item('minecraft:planks:4'))
// mods.horsepower.manual_chopping_block.removeAll()

mods.horsepower.manual_chopping_block.recipeBuilder()
.input(item('minecraft:clay'))
.output(item('minecraft:diamond') * 5)
.time(5)
.register()

mods.horsepower.manual_chopping_block.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:gold_ingot'))
.time(1)
.register()


// Manual Grindstone:
// Converts an itemstack input into an itemstack output, with the chance of an additional output after a configurable
// amount of processing has been done. Depending on if the config option `Separate Grindstone Recipes` is true, this may
// affect both Horse and Hand Grindstones.

mods.horsepower.manual_grindstone.removeByInput(item('minecraft:double_plant:4'))
mods.horsepower.manual_grindstone.removeByOutput(item('minecraft:sugar'))
// mods.horsepower.manual_grindstone.removeAll()

mods.horsepower.manual_grindstone.recipeBuilder()
.input(item('minecraft:clay'))
.output(item('minecraft:diamond') * 5)
.time(5)
.register()

mods.horsepower.manual_grindstone.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:gold_ingot'))
.time(1)
.register()

mods.horsepower.manual_grindstone.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'), item('minecraft:diamond'))
.chance(50)
.time(2)
.register()


// Horse Press:
// Converts an itemstack into another itemstack or a fluidstack by a horse running laps.

mods.horsepower.press.removeByInput(item('minecraft:wheat_seeds'))
mods.horsepower.press.removeByOutput(fluid('water'))
// mods.horsepower.press.removeByOutput(item('minecraft:dirt'))
// mods.horsepower.press.removeAll()

mods.horsepower.press.recipeBuilder()
.input(item('minecraft:clay'))
.output(item('minecraft:diamond') * 5)
.register()

mods.horsepower.press.recipeBuilder()
.input(item('minecraft:diamond'))
.fluidOutput(fluid('lava') * 500)
.register()


2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ debug_extra_utilities_2 = false
debug_forestry = false
debug_future_mc = false

debug_horse_power = false

debug_immersive_engineering = false
debug_immersive_petroleum = false
debug_immersive_technology = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.cleanroommc.groovyscript.compat.mods.extrautils2.ExtraUtils2;
import com.cleanroommc.groovyscript.compat.mods.forestry.Forestry;
import com.cleanroommc.groovyscript.compat.mods.futuremc.FutureMC;
import com.cleanroommc.groovyscript.compat.mods.horsepower.HorsePower;
import com.cleanroommc.groovyscript.compat.mods.ic2.IC2;
import com.cleanroommc.groovyscript.compat.mods.immersiveengineering.ImmersiveEngineering;
import com.cleanroommc.groovyscript.compat.mods.immersivepetroleum.ImmersivePetroleum;
Expand Down Expand Up @@ -106,6 +107,7 @@ public class ModSupport {
public static final GroovyContainer<ExtraUtils2> EXTRA_UTILITIES_2 = new InternalModContainer<>("extrautils2", "Extra Utilities 2", ExtraUtils2::new, "extrautilities2");
public static final GroovyContainer<Forestry> FORESTRY = new InternalModContainer<>("forestry", "Forestry", Forestry::new);
public static final GroovyContainer<FutureMC> FUTURE_MC = new InternalModContainer<>("futuremc", "Future MC", FutureMC::new);
public static final GroovyContainer<HorsePower> HORSE_POWER = new InternalModContainer<>("horsepower", "Horse Power", HorsePower::new);
public static final GroovyContainer<ImmersiveEngineering> IMMERSIVE_ENGINEERING = new InternalModContainer<>("immersiveengineering", "Immersive Engineering", ImmersiveEngineering::new, "ie");
public static final GroovyContainer<ImmersivePetroleum> IMMERSIVE_PETROLEUM = new InternalModContainer<>("immersivepetroleum", "Immersive Petroleum", ImmersivePetroleum::new);
public static final GroovyContainer<ImmersiveTechnology> IMMERSIVE_TECHNOLOGY = new InternalModContainer<>("immersivetech", "Immersive Technology", ImmersiveTechnology::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.cleanroommc.groovyscript.compat.mods.horsepower;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.StandardListRegistry;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import se.gory_moon.horsepower.recipes.ChoppingBlockRecipe;
import se.gory_moon.horsepower.recipes.HPRecipes;

import java.util.Collection;

@RegistryDescription
public class ChoppingBlock extends StandardListRegistry<ChoppingBlockRecipe> {

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:clay')).output(item('minecraft:diamond') * 5).time(5)"),
@Example(".input(item('minecraft:diamond')).output(item('minecraft:gold_ingot')).time(1)"),
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'), item('minecraft:diamond')).chance(50).time(2)")
})
public static RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

// have to override onReload and add to add recipes to the registry due to the actual setup being a map
@Override
public Collection<ChoppingBlockRecipe> getRecipes() {
return HPRecipes.instance().getChoppingRecipes();
}

@Override
@GroovyBlacklist
@ApiStatus.Internal
public void onReload() {
var recipes = getRecipes();
recipes.removeAll(removeScripted());
for (var recipe : restoreFromBackup()) {
HPRecipes.instance().addChoppingRecipe(recipe, false);
}
}

@Override
@MethodDescription(type = MethodDescription.Type.ADDITION, description = "groovyscript.wiki.add_to_list", priority = 500)
public boolean add(ChoppingBlockRecipe recipe) {
HPRecipes.instance().addChoppingRecipe(recipe, false);
return recipe != null && doAddScripted(recipe);
}

@MethodDescription(description = "groovyscript.wiki.horsepower.chopping_block.add0", type = MethodDescription.Type.ADDITION)
public ChoppingBlockRecipe add(IIngredient input, ItemStack output, int time) {
return recipeBuilder()
.time(time)
.output(output)
.input(input)
.register();
}

@MethodDescription(description = "groovyscript.wiki.horsepower.chopping_block.add1", type = MethodDescription.Type.ADDITION)
public ChoppingBlockRecipe add(IIngredient input, ItemStack output, ItemStack secondary, int chance, int time) {
return recipeBuilder()
.time(time)
.chance(chance)
.output(output, secondary)
.input(input)
.register();
}

@MethodDescription(example = @Example("item('minecraft:log:3')"))
public boolean removeByInput(IIngredient input) {
return getRecipes().removeIf(entry -> input.test(entry.getInput()) && doAddBackup(entry));
}

@MethodDescription(example = @Example("item('minecraft:planks:4')"))
public boolean removeByOutput(IIngredient output) {
return getRecipes().removeIf(entry -> (output.test(entry.getOutput()) || output.test(entry.getSecondary())) && doAddBackup(entry));
}

@Property(property = "input", comp = @Comp(eq = 1))
@Property(property = "output", comp = @Comp(gte = 1, lte = 2))
public static class RecipeBuilder extends AbstractRecipeBuilder<ChoppingBlockRecipe> {

@Property(comp = @Comp(gte = 0, lte = 100))
private int chance;
@Property(comp = @Comp(gt = 0))
private int time;

@RecipeBuilderMethodDescription
public RecipeBuilder chance(int chance) {
this.chance = chance;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder time(int time) {
this.time = time;
return this;
}

// todo this can only handle an input with a size of 1, should validate that here

@Override
public String getErrorMsg() {
return "Error adding Horse Power Chopping Block recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 2);
validateFluids(msg);
msg.add(chance < 0 || chance > 100, "chance must be a non negative integer less than 100, yet it was {}", chance);
msg.add(time <= 0, "time must be greater than 0, yet it was {}", time);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable ChoppingBlockRecipe register() {
if (!validate()) return null;
ChoppingBlockRecipe recipe = null;
for (var stack : input.get(0).getMatchingStacks()) {
recipe = new ChoppingBlockRecipe(stack, output.get(0), output.getOrEmpty(1), chance, time);
ModSupport.HORSE_POWER.get().choppingBlock.add(recipe);
}
return recipe;
}

}

}
Loading

0 comments on commit 73e8d24

Please sign in to comment.