-
Notifications
You must be signed in to change notification settings - Fork 28
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
add Additional Enchanted Miner compat #277
Changes from 11 commits
84f80fa
a109ea5
1e5591b
a21e084
5daf8b6
9f291e4
5f3462f
b6d3f28
254a1b0
edd26ff
9a6721d
d7b4b29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
// Auto generated groovyscript example file | ||
// MODS_LOADED: quarryplus | ||
|
||
log.info 'mod \'quarryplus\' detected, running script' | ||
|
||
// groovyscript.wiki.quarryplus.work_bench_plus.title: | ||
// groovyscript.wiki.quarryplus.work_bench_plus.description. | ||
|
||
mods.quarryplus.work_bench_plus.removeByOutput(item('quarryplus:quarry')) | ||
// mods.quarryplus.work_bench_plus.removeAll() | ||
|
||
mods.quarryplus.work_bench_plus.recipeBuilder() | ||
.output(item('minecraft:nether_star')) | ||
.input(item('minecraft:diamond'),item('minecraft:gold_ingot')) | ||
.energy(10000) | ||
.register() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; | ||
|
||
public class AdditionalEnchantedMiner extends GroovyPropertyContainer { | ||
public final WorkBenchPlus WorkBenchPlus = new WorkBenchPlus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fields should be in |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; | ||
|
||
import com.cleanroommc.groovyscript.api.GroovyLog; | ||
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.VirtualizedRegistry; | ||
import com.yogpc.qp.recipe.WorkbenchRecipe; | ||
import com.yogpc.qp.tile.ItemDamage; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.jetbrains.annotations.Nullable; | ||
import scala.collection.JavaConversions; | ||
import scala.collection.Map; | ||
|
||
@RegistryDescription | ||
public class WorkBenchPlus extends VirtualizedRegistry<WorkbenchPlusRecipe> { | ||
|
||
@Override | ||
public void onReload() { | ||
removeScripted().forEach(recipe -> WorkbenchRecipe.removeRecipe(recipe.getLocation())); | ||
restoreFromBackup().forEach(ModSupport.ADDITIONAL_ENCHANTED_MINER.get().WorkBenchPlus::add); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calling this method adds the method to the scripted list, which should not be done. |
||
} | ||
|
||
@MethodDescription(example = @Example("item('quarryplus:quarry')")) | ||
public boolean removeByOutput(ItemStack output) { | ||
ItemDamage itemDamage = ItemDamage.apply(output); | ||
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap(); | ||
Iterable<WorkbenchRecipe> iterable = JavaConversions.asJavaIterable(recipeMap.values()); | ||
iterable.forEach(recipe -> { | ||
if (recipe.key().equals(itemDamage)) { | ||
addBackup(new WorkbenchPlusRecipe(recipe.inputs(), recipe.getOutput(), recipe.energy(), recipe.location())); | ||
} | ||
}); | ||
return WorkbenchPlusRecipe.removeByOutput(output); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have direct access to the Map, why do you need to call a different method? |
||
} | ||
|
||
@MethodDescription(priority = 2000,example = @Example(commented = true)) | ||
public void removeAll() { | ||
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap(); | ||
Iterable<ResourceLocation> iterableRecipe = JavaConversions.asJavaIterable(recipeMap.keys()); | ||
iterableRecipe.forEach( | ||
location -> WorkbenchPlusRecipe.removeById(location.toString()) | ||
); | ||
} | ||
|
||
private void add(WorkbenchPlusRecipe recipe) { | ||
addScripted(recipe); | ||
WorkbenchPlusRecipe.addRecipe(recipe); | ||
} | ||
|
||
@RecipeBuilderDescription(example = | ||
@Example(".output(item('minecraft:nether_star')).input(item('minecraft:diamond'),item('minecraft:gold_ingot')).energy(10000)")) | ||
public RecipeBuilder recipeBuilder(){return new RecipeBuilder();} | ||
|
||
@Property(property = "input", comp = @Comp(gte = 1 , lte = 27)) | ||
@Property(property = "output", comp = @Comp(eq = 1)) | ||
public static class RecipeBuilder extends AbstractRecipeBuilder<WorkbenchPlusRecipe> { | ||
|
||
@Property(comp = @Comp(gt = 0)) | ||
private double energy; | ||
|
||
@RecipeBuilderMethodDescription | ||
public RecipeBuilder energy(double energy) { | ||
this.energy = energy; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getRecipeNamePrefix() { | ||
return "additionalenchantedminer_workbenchplus_"; | ||
} | ||
|
||
@Override | ||
public String getErrorMsg() { | ||
return "Error adding Additional Enchanted Miner WorkbenchPlus recipe"; | ||
} | ||
|
||
@Override | ||
public void validate(GroovyLog.Msg msg) { | ||
validateName(); | ||
validateItems(msg, 1, 27, 1, 1); | ||
msg.add(energy <= 0, "energy must be an integer greater than 0, yet it was {}", energy); | ||
} | ||
|
||
@Override | ||
@RecipeBuilderRegistrationMethod | ||
public @Nullable WorkbenchPlusRecipe register() { | ||
if (!validate()) return null; | ||
WorkbenchPlusRecipe recipe = new WorkbenchPlusRecipe(this.input, this.output.get(0), this.energy, super.name); | ||
ModSupport.ADDITIONAL_ENCHANTED_MINER.get().WorkBenchPlus.add(recipe); | ||
return recipe; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; | ||
|
||
import com.cleanroommc.groovyscript.api.IIngredient; | ||
import com.yogpc.qp.recipe.WorkbenchRecipe; | ||
import com.yogpc.qp.tile.ItemDamage; | ||
import com.yogpc.qp.utils.IngredientWithCount; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import scala.collection.JavaConversions; | ||
import scala.collection.Seq; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.yogpc.qp.recipe.WorkbenchRecipe.addIngredientRecipe; | ||
|
||
public class WorkbenchPlusRecipe { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the point of this class? what purpose does it serve that it couldnt be replaced by some code in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, I realize that I don't need WorkbenchPlusRecipe, I'll fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nothing changed here. |
||
private final List<List<IngredientWithCount>> input; | ||
private final ItemStack output; | ||
private final Double energy; | ||
private final ResourceLocation location; | ||
|
||
public WorkbenchPlusRecipe(Collection<IIngredient> input, ItemStack output, Double energy , ResourceLocation location) { | ||
|
||
this.input = input.stream() | ||
.map(i -> new IngredientWithCount(i.toMcIngredient(), i.getAmount())) | ||
.map(Collections::singletonList) | ||
.collect(Collectors.toList()); | ||
this.output = output; | ||
this.energy = energy; | ||
this.location = location; | ||
} | ||
|
||
public WorkbenchPlusRecipe(Seq<Seq<IngredientWithCount>> input, ItemStack output, Double energy , ResourceLocation location) { | ||
this.input = JavaConversions.seqAsJavaList(input).stream() | ||
.map(JavaConversions::seqAsJavaList) | ||
.collect(Collectors.toList()); | ||
this.output = output; | ||
this.energy = energy; | ||
this.location = location; | ||
|
||
} | ||
|
||
|
||
public static boolean addRecipe(WorkbenchPlusRecipe recipe) { | ||
addIngredientRecipe(recipe.location, recipe.output, recipe.energy, recipe.input, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not |
||
return true; | ||
} | ||
|
||
public static boolean removeByOutput(ItemStack output) { | ||
ItemDamage itemDamage = ItemDamage.apply(output); | ||
WorkbenchRecipe.removeRecipe(itemDamage); | ||
return true; | ||
} | ||
|
||
public static void removeById(String id) { | ||
ResourceLocation resourceLocation = new ResourceLocation(id); | ||
WorkbenchRecipe.removeRecipe(resourceLocation); | ||
} | ||
|
||
public ResourceLocation getLocation() { | ||
return location; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where lang? peep the
groovy.log
to see the missing lang keys and add a translation for those