Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ dependencies {
runtimeOnly rfg.deobf('net.sengir.forestry:forestry_1.12.2:5.8.2.422')
runtimeOnly rfg.deobf('curse.maven:jei-bees-248370:2490058')
}

compileOnly rfg.deobf('curse.maven:advancedmortars-283777:2780626')
if (project.debug_adv_mortars.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:advancedmortars-283777:2780626')
}

}

processResources {
Expand Down
49 changes: 49 additions & 0 deletions examples/advancedmortars.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

// add(List<String> types, ItemStack output, int duration, List<IIngredient> inputs)
mods.advancedmortars.Mortar.add(
['stone'],
item('minecraft:diamond') * 4,
4,
[ore('ingotGold')]
)

mods.advancedmortars.Mortar.add(
['stone'],
item('minecraft:tnt'),
4,
[ore('ingotGold')]
)

// add(List<String> types, ItemStack output, int duration, ItemStack secondaryOutput, float secondaryOutputChance, List<IIngredient> inputs)
mods.advancedmortars.Mortar.add(
['iron', 'wood'],
item('minecraft:tnt') * 5,
4,
item('minecraft:tnt'),
0.7,
[ore('ingotIron'), ore('ingotIron'), ore('ingotIron'), ore('ingotIron'), // max 8
ore('ingotIron'), ore('ingotIron'), ore('ingotIron'), ore('ingotIron')]
)

mods.advancedmortars.Mortar.recipeBuilder()
.type('stone') // EnumMortarType ('wood', 'stone', 'iron', 'diamond', 'gold', 'obsidian', 'emerald')
.duration(2) // int
.output(item('minecraft:grass')) // ItemStack
.input(item('minecraft:dirt')) // IIngredient
.register()

mods.advancedmortars.Mortar.recipeBuilder()
.type('emerald')
.duration(4)
.output(item('minecraft:wheat_seeds') * 16)
.secondaryOutput(item('minecraft:melon_seeds')) // ItemStack
.input(ore('cropWheat'))
.register()

mods.advancedmortars.Mortar.recipeBuilder()
.type('obsidian')
.duration(8)
.output(item('minecraft:wheat_seeds') * 16)
.secondaryOutput(item('minecraft:melon_seeds'), 0.5) // ItemStack, float
.input(ore('cropWheat'))
.register()
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ debug_roots = false
debug_blood_magic = false
debug_tinkers = false
debug_extended_crafting = false
debug_adv_mortars = false
debug_botania = false
debug_forestry = false
debug_inspirations = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.IDynamicGroovyProperty;
import com.cleanroommc.groovyscript.compat.mods.actuallyadditions.ActuallyAdditions;
import com.cleanroommc.groovyscript.compat.mods.advancedmortars.AdvancedMortars;
import com.cleanroommc.groovyscript.compat.mods.appliedenergistics2.AppliedEnergistics2;
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.AstralSorcery;
import com.cleanroommc.groovyscript.compat.mods.bloodmagic.BloodMagic;
Expand Down Expand Up @@ -66,6 +67,7 @@ public class ModSupport implements IDynamicGroovyProperty {
public static final Container<IC2> INDUSTRIALCRAFT = new Container<>("ic2", "Industrial Craft 2", IC2::new, "industrialcraft");
public static final Container<ExtendedCrafting> EXTENDED_CRAFTING = new Container<>("extendedcrafting", "Extended Crafting", ExtendedCrafting::new);
public static final Container<Forestry> FORESTRY = new Container<>("forestry", "Forestry", Forestry::new);
public static final Container<AdvancedMortars> ADVANCED_MORTARS = new Container<>("advancedmortars", "Advanced Mortars", AdvancedMortars::new);
public static final Container<Woot> WOOT = new Container<>("woot", "Woot", Woot::new);
public static final Container<Inspirations> INSPIRATIONS = new Container<>("inspirations", "Inspirations", Inspirations::new);
public static final Container<CompactMachines> COMPACT_MACHINES = new Container<>("compactmachines3", "Compact Machines 3", CompactMachines::new, "compactmachines");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cleanroommc.groovyscript.compat.mods.advancedmortars;

import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;

public class AdvancedMortars extends ModPropertyContainer {

public final Mortar mortar = new Mortar();

public AdvancedMortars() {
addRegistry(mortar);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.cleanroommc.groovyscript.compat.mods.advancedmortars;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.core.mixin.advancedmortars.RegistryRecipeMortarAccessor;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import com.codetaylor.mc.advancedmortars.modules.mortar.api.MortarAPI;
import com.codetaylor.mc.advancedmortars.modules.mortar.recipe.RecipeMortar;
import com.codetaylor.mc.advancedmortars.modules.mortar.reference.EnumMortarType;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Mortar extends VirtualizedRegistry<RecipeMortar> {

public Mortar() {
super();
}

public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
@GroovyBlacklist
public void onReload() {
removeScripted().forEach(recipe -> ((RegistryRecipeMortarAccessor) MortarAPI.RECIPE_REGISTRY).getRecipeMap().values().forEach(list -> list.removeIf(r -> r == recipe)));
restoreFromBackup().forEach(recipe -> getTypes(recipe).forEach(type -> add(type, recipe)));
}

public void add(List<String> types, ItemStack output, int duration, List<IIngredient> inputs) {
add(types, output, duration, ItemStack.EMPTY, 0.0f, inputs);
}

public void add(List<String> types, ItemStack output, int duration, ItemStack secondaryOutput, float secondaryOutputChance, List<IIngredient> inputs) {
if (inputs == null || inputs.size() == 0) return;
if (inputs.size() > 8) {
GroovyLog.msg("Error adding Advanced Mortars recipe")
.add("maximum number of 8 input ingredients exceeded: " + inputs.size())
.error()
.post();
return;
}
for (String type : types) {
EnumMortarType enumMortarType = EnumMortarType.fromName(type);
if (enumMortarType == null) {
GroovyLog.msg("Error adding Advanced Mortars recipe")
.add("invalid mortar type: " + type)
.add("valid types are: " + Arrays.toString(EnumMortarType.NAMES))
.error()
.post();
return;
}
add(enumMortarType, new RecipeMortar(output, duration, secondaryOutput, secondaryOutputChance, IngredientHelper.toIngredientNonNullList(inputs)));
}
}

public void add(EnumMortarType type, RecipeMortar recipe) {
List<RecipeMortar> list = ((RegistryRecipeMortarAccessor) MortarAPI.RECIPE_REGISTRY).getRecipeMap().computeIfAbsent(type, (k) -> new ArrayList<>());
list.add(recipe);
addScripted(recipe);
}

public static List<EnumMortarType> getTypes(RecipeMortar recipe) {
return ((RegistryRecipeMortarAccessor) MortarAPI.RECIPE_REGISTRY)
.getRecipeMap()
.entrySet()
.stream()
.filter(x -> x.getValue().contains(recipe))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
}

public class RecipeBuilder extends AbstractRecipeBuilder<RecipeMortar> {

private final List<String> types = new ArrayList<>();
private int duration;
private ItemStack secondaryOutput = ItemStack.EMPTY;
private float secondaryOutputChance = 1.0f;

public RecipeBuilder type(String... type) {
this.types.addAll(Arrays.asList(type));
return this;
}

public RecipeBuilder type(List<String> type) {
this.types.addAll(type);
return this;
}

public RecipeBuilder wood() {
this.types.add("wood");
return this;
}

public RecipeBuilder stone() {
this.types.add("stone");
return this;
}

public RecipeBuilder iron() {
this.types.add("iron");
return this;
}

public RecipeBuilder diamond() {
this.types.add("diamond");
return this;
}

public RecipeBuilder gold() {
this.types.add("gold");
return this;
}

public RecipeBuilder obsidian() {
this.types.add("obsidian");
return this;
}

public RecipeBuilder emerald() {
this.types.add("emerald");
return this;
}

public RecipeBuilder duration(int duration) {
this.duration = duration;
return this;
}

public RecipeBuilder secondaryOutput(ItemStack itemStack) {
this.secondaryOutput = itemStack;
return this;
}

public RecipeBuilder secondaryOutput(ItemStack itemStack, float chance) {
this.secondaryOutput = itemStack;
this.secondaryOutputChance = chance;
return this;
}

public RecipeBuilder secondaryOutputChance(float chance) {
this.secondaryOutputChance = chance;
return this;
}

@Override
public String getErrorMsg() {
return "Error adding Advanced Mortars recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 8, 1, 1);
for (String type : types) {
EnumMortarType enumMortarType = EnumMortarType.fromName(type);
if (enumMortarType == null) {
msg.add("invalid mortar type: " + type).add("valid types are: " + Arrays.toString(EnumMortarType.NAMES));
}
}
if (secondaryOutputChance > 1.0f) {
secondaryOutputChance = 1.0f;
}
}

@Override
public @Nullable RecipeMortar register() {
if (!validate()) return null;
RecipeMortar recipe = new RecipeMortar(output.get(0), duration, secondaryOutput, secondaryOutputChance, IngredientHelper.toIngredientNonNullList(input));
types.stream().map(EnumMortarType::fromName).forEach(enumMortarType -> add(enumMortarType, recipe));
return recipe;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class LateMixin implements ILateMixinLoader {

public static final List<String> modMixins = ImmutableList.of(
"advancedmortars",
"appliedenergistics2",
"astralsorcery",
"bloodmagic",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cleanroommc.groovyscript.core.mixin.advancedmortars;

import com.codetaylor.mc.advancedmortars.modules.mortar.recipe.RecipeMortar;
import com.codetaylor.mc.advancedmortars.modules.mortar.recipe.RegistryRecipeMortar;
import com.codetaylor.mc.advancedmortars.modules.mortar.reference.EnumMortarType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.EnumMap;
import java.util.List;

@Mixin(value = RegistryRecipeMortar.class, remap = false)
public interface RegistryRecipeMortarAccessor {

@Accessor
EnumMap<EnumMortarType, List<RecipeMortar>> getRecipeMap();

}
10 changes: 10 additions & 0 deletions src/main/resources/mixin.groovyscript.advancedmortars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package": "com.cleanroommc.groovyscript.core.mixin.advancedmortars",
"refmap": "mixins.groovyscript.refmap.json",
"target": "@env(DEFAULT)",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"RegistryRecipeMortarAccessor"
]
}