generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Immersive Petroleum compat (#171)
* add Immersive Petroleum compat * remove incorrect annotation * convert distillation to use different method of adding chance * update ModPropertyContainer
- Loading branch information
1 parent
9fb2042
commit 0a9cdde
Showing
8 changed files
with
517 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,66 @@ | ||
|
||
// Auto generated groovyscript example file | ||
// MODS_LOADED: immersivepetroleum | ||
|
||
println 'mod \'immersivepetroleum\' detected, running script' | ||
|
||
// Distillation Tower: | ||
// Converts an input fluidstack into any number of output fluidstacks and any number of output itemstacks, with each | ||
// itemstack having the ability to have a custom chance, using energy and taking time. | ||
|
||
mods.immersivepetroleum.distillation.removeByInput(fluid('oil')) | ||
// mods.immersivepetroleum.distillation.removeByOutput(fluid('lubricant')) | ||
// mods.immersivepetroleum.distillation.removeByOutput(item('immersivepetroleum:material')) | ||
// mods.immersivepetroleum.distillation.removeAll() | ||
|
||
mods.immersivepetroleum.distillation.recipeBuilder() | ||
.fluidInput(fluid('water') * 100) | ||
.fluidOutput(fluid('water') * 50, fluid('lava') * 30) | ||
.output(item('minecraft:diamond'), 0.5) | ||
.output(item('minecraft:clay'), 0.2) | ||
.output(item('minecraft:diamond'), 0.1) | ||
.output(item('minecraft:clay'), 0.5) | ||
.output(item('minecraft:diamond') * 5, 0.01) | ||
.time(5) | ||
.energy(1000) | ||
.register() | ||
|
||
mods.immersivepetroleum.distillation.recipeBuilder() | ||
.fluidInput(fluid('lava') * 5) | ||
.output(item('minecraft:diamond')) | ||
.time(1) | ||
.register() | ||
|
||
|
||
// Reservoir: | ||
// Adds a Reservoir Type with the given name, weight, minimum size, maximum size, replenishment rate, allowed dimensions, | ||
// and allowed biomes. A Reservoir Type can be extracted by an Pumpjack Multiblock and scanned via a Core Sample Drill. | ||
|
||
mods.immersivepetroleum.reservoir.removeByName('aquifer') | ||
mods.immersivepetroleum.reservoir.removeByOutput(fluid('oil')) | ||
// mods.immersivepetroleum.reservoir.removeAll() | ||
|
||
mods.immersivepetroleum.reservoir.recipeBuilder() | ||
.name('demo') | ||
.fluidOutput(fluid('water')) | ||
.weight(20000) | ||
.minSize(100) | ||
.maxSize(100) | ||
.dimension(0, 1) | ||
.biome('hot') | ||
.register() | ||
|
||
mods.immersivepetroleum.reservoir.recipeBuilder() | ||
.name('demo') | ||
.fluidOutput(fluid('lava')) | ||
.weight(2000) | ||
.minSize(1000) | ||
.maxSize(5000) | ||
.replenishRate(100) | ||
.dimension(-1, 1) | ||
.dimensionBlacklist() | ||
.biome('cold') | ||
.biomeBlacklist() | ||
.register() | ||
|
||
|
This file contains 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 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
160 changes: 160 additions & 0 deletions
160
src/main/java/com/cleanroommc/groovyscript/compat/mods/immersivepetroleum/Distillation.java
This file contains 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,160 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.immersivepetroleum; | ||
|
||
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.SimpleObjectStream; | ||
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; | ||
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; | ||
import flaxbeard.immersivepetroleum.api.crafting.DistillationRecipe; | ||
import it.unimi.dsi.fastutil.floats.FloatArrayList; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@RegistryDescription | ||
public class Distillation extends VirtualizedRegistry<DistillationRecipe> { | ||
|
||
@RecipeBuilderDescription(example = { | ||
@Example(".fluidInput(fluid('water') * 100).fluidOutput(fluid('water') * 50, fluid('lava') * 30).output(item('minecraft:diamond'), 0.5).output(item('minecraft:clay'), 0.2).output(item('minecraft:diamond'), 0.1).output(item('minecraft:clay'), 0.5).output(item('minecraft:diamond') * 5, 0.01).time(5).energy(1000)"), | ||
@Example(".fluidInput(fluid('lava') * 5).output(item('minecraft:diamond')).time(1)") | ||
}) | ||
public RecipeBuilder recipeBuilder() { | ||
return new RecipeBuilder(); | ||
} | ||
|
||
@Override | ||
@GroovyBlacklist | ||
@ApiStatus.Internal | ||
public void onReload() { | ||
removeScripted().forEach(recipe -> DistillationRecipe.recipeList.removeIf(r -> r == recipe)); | ||
DistillationRecipe.recipeList.addAll(restoreFromBackup()); | ||
} | ||
|
||
public void add(DistillationRecipe recipe) { | ||
if (recipe != null) { | ||
addScripted(recipe); | ||
DistillationRecipe.recipeList.add(recipe); | ||
} | ||
} | ||
|
||
public boolean remove(DistillationRecipe recipe) { | ||
if (DistillationRecipe.recipeList.removeIf(r -> r == recipe)) { | ||
addBackup(recipe); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@MethodDescription(example = { | ||
@Example(value = "item('immersivepetroleum:material')", commented = true), | ||
@Example(value = "fluid('lubricant')", commented = true) | ||
}) | ||
public void removeByOutput(IIngredient output) { | ||
DistillationRecipe.recipeList.removeIf(r -> { | ||
for (ItemStack itemstack : r.getItemOutputs()) { | ||
if (output.test(itemstack)) { | ||
addBackup(r); | ||
return true; | ||
} | ||
} | ||
for (FluidStack fluidStack : r.getFluidOutputs()) { | ||
if (output.test(fluidStack)) { | ||
addBackup(r); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
@MethodDescription(example = @Example("fluid('oil')")) | ||
public void removeByInput(IIngredient input) { | ||
DistillationRecipe.recipeList.removeIf(r -> { | ||
for (FluidStack fluidStack : r.getFluidInputs()) { | ||
if (input.test(fluidStack)) { | ||
addBackup(r); | ||
return true; | ||
} | ||
} | ||
return false; | ||
}); | ||
} | ||
|
||
@MethodDescription(type = MethodDescription.Type.QUERY) | ||
public SimpleObjectStream<DistillationRecipe> streamRecipes() { | ||
return new SimpleObjectStream<>(DistillationRecipe.recipeList).setRemover(this::remove); | ||
} | ||
|
||
@MethodDescription(priority = 2000, example = @Example(commented = true)) | ||
public void removeAll() { | ||
DistillationRecipe.recipeList.forEach(this::addBackup); | ||
DistillationRecipe.recipeList.clear(); | ||
} | ||
|
||
@Property(property = "fluidInput", valid = @Comp("1")) | ||
@Property(property = "output", valid = {@Comp(type = Comp.Type.GTE, value = "0"), @Comp(type = Comp.Type.LTE, value = "Integer.MAX_VALUE")}) | ||
@Property(property = "fluidOutput", valid = {@Comp(type = Comp.Type.GTE, value = "0"), @Comp(type = Comp.Type.LTE, value = "Integer.MAX_VALUE")}) | ||
public static class RecipeBuilder extends AbstractRecipeBuilder<DistillationRecipe> { | ||
|
||
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE)) | ||
private final FloatArrayList chance = new FloatArrayList(); | ||
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE)) | ||
private int time; | ||
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE)) | ||
private int energy; | ||
|
||
@RecipeBuilderMethodDescription(field = {"output", "chance"}) | ||
public RecipeBuilder output(ItemStack output, float chance) { | ||
this.output.add(output); | ||
this.chance.add(chance); | ||
return this; | ||
} | ||
|
||
@Override | ||
@RecipeBuilderMethodDescription(field = {"output", "chance"}) | ||
public RecipeBuilder output(ItemStack output) { | ||
return this.output(output, 1); | ||
} | ||
|
||
@RecipeBuilderMethodDescription | ||
public RecipeBuilder time(int time) { | ||
this.time = time; | ||
return this; | ||
} | ||
|
||
@RecipeBuilderMethodDescription | ||
public RecipeBuilder energy(int energy) { | ||
this.energy = energy; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getErrorMsg() { | ||
return "Error adding Immersive Petroleum Distillation recipe"; | ||
} | ||
|
||
@Override | ||
public void validate(GroovyLog.Msg msg) { | ||
validateItems(msg, 0, 0, 0, Integer.MAX_VALUE); | ||
validateFluids(msg, 1, 1, 0, Integer.MAX_VALUE); | ||
chance.trim(); | ||
msg.add(output.size() != chance.size(), "output and chance must be of equal length, yet output was {} and chance was {}", output.size(), chance.size()); | ||
msg.add(time <= 0, "time must be greater than or equal to 1, yet it was {}", time); | ||
msg.add(energy < 0, "energy must be a non negative integer, yet it was {}", energy); | ||
} | ||
|
||
@Override | ||
@RecipeBuilderRegistrationMethod | ||
public @Nullable DistillationRecipe register() { | ||
if (!validate()) return null; | ||
DistillationRecipe recipe = new DistillationRecipe(fluidOutput.toArray(new FluidStack[0]), output.toArray(new ItemStack[0]), fluidInput.get(0), energy, time, chance.elements()); | ||
ModSupport.IMMERSIVE_PETROLEUM.get().distillation.add(recipe); | ||
return recipe; | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
.../java/com/cleanroommc/groovyscript/compat/mods/immersivepetroleum/ImmersivePetroleum.java
This file contains 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.compat.mods.immersivepetroleum; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; | ||
|
||
public class ImmersivePetroleum extends GroovyPropertyContainer { | ||
|
||
public final Distillation distillation = new Distillation(); | ||
public final Reservoir reservoir = new Reservoir(); | ||
|
||
} |
Oops, something went wrong.