generated from CleanroomMC/ForgeDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 30
Add Advanced Mortars compat #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7345db
Add Advanced Mortars compat
juraj-hrivnak b99bf1e
Add RecipeBuilder; Clean up code
juraj-hrivnak 88748e1
Clean up; Varargs & list for type;
juraj-hrivnak d00af63
Validate secondaryOutputChance
juraj-hrivnak 6e8a023
Fix remove; Add methods for each mortar type
juraj-hrivnak 312e50c
Merge branch 'master' into advanced-mortars
brachy84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cleanroommc/groovyscript/compat/mods/advancedmortars/AdvancedMortars.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } |
183 changes: 183 additions & 0 deletions
183
src/main/java/com/cleanroommc/groovyscript/compat/mods/advancedmortars/Mortar.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
juraj-hrivnak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .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") | ||
juraj-hrivnak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .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) { | ||
juraj-hrivnak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
juraj-hrivnak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...com/cleanroommc/groovyscript/core/mixin/advancedmortars/RegistryRecipeMortarAccessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
10
src/main/resources/mixin.groovyscript.advancedmortars.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.