Skip to content

Commit 0a9cdde

Browse files
authored
add Immersive Petroleum compat (#171)
* add Immersive Petroleum compat * remove incorrect annotation * convert distillation to use different method of adding chance * update ModPropertyContainer
1 parent 9fb2042 commit 0a9cdde

File tree

8 files changed

+517
-1
lines changed

8 files changed

+517
-1
lines changed

dependencies.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ final def mod_dependencies = [
6161
'extended-crafting-nomifactory-edition-398267:3613140': [project.debug_extended_crafting],
6262
'extra-utilities-2-225561:2678374' : [project.debug_extra_utilities_2],
6363
'forestry-59751:2918418' : [project.debug_forestry],
64-
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering],
64+
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering, project.debug_immersive_petroleum],
65+
'immersive-petroleum-268250:3382321' : [project.debug_immersive_petroleum],
6566
// WARNING: experimental must be placed before classic, otherwise you will crash when debugging either. Check FluidGenerator compat to confirm
6667
'industrialcraft_experimental-242638:3838713' : [project.debug_industrial_craft_2_experimental],
6768
'industrialcraft_classic-242942:3093607' : [project.debug_industrial_craft_2_classic],
@@ -137,6 +138,10 @@ dependencies {
137138
runtimeOnly rfg.deobf('curse.maven:jei-bees-248370:2490058')
138139
}
139140

141+
if (project.debug_immersive_petroleum.toBoolean()) {
142+
runtimeOnly rfg.deobf('curse.maven:just-enough-petroleum-291727:2549332')
143+
}
144+
140145
if (project.debug_pyrotech.toBoolean()) {
141146
runtimeOnly rfg.deobf("curse.maven:dropt-284973:3758733")
142147
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
// Auto generated groovyscript example file
3+
// MODS_LOADED: immersivepetroleum
4+
5+
println 'mod \'immersivepetroleum\' detected, running script'
6+
7+
// Distillation Tower:
8+
// Converts an input fluidstack into any number of output fluidstacks and any number of output itemstacks, with each
9+
// itemstack having the ability to have a custom chance, using energy and taking time.
10+
11+
mods.immersivepetroleum.distillation.removeByInput(fluid('oil'))
12+
// mods.immersivepetroleum.distillation.removeByOutput(fluid('lubricant'))
13+
// mods.immersivepetroleum.distillation.removeByOutput(item('immersivepetroleum:material'))
14+
// mods.immersivepetroleum.distillation.removeAll()
15+
16+
mods.immersivepetroleum.distillation.recipeBuilder()
17+
.fluidInput(fluid('water') * 100)
18+
.fluidOutput(fluid('water') * 50, fluid('lava') * 30)
19+
.output(item('minecraft:diamond'), 0.5)
20+
.output(item('minecraft:clay'), 0.2)
21+
.output(item('minecraft:diamond'), 0.1)
22+
.output(item('minecraft:clay'), 0.5)
23+
.output(item('minecraft:diamond') * 5, 0.01)
24+
.time(5)
25+
.energy(1000)
26+
.register()
27+
28+
mods.immersivepetroleum.distillation.recipeBuilder()
29+
.fluidInput(fluid('lava') * 5)
30+
.output(item('minecraft:diamond'))
31+
.time(1)
32+
.register()
33+
34+
35+
// Reservoir:
36+
// Adds a Reservoir Type with the given name, weight, minimum size, maximum size, replenishment rate, allowed dimensions,
37+
// and allowed biomes. A Reservoir Type can be extracted by an Pumpjack Multiblock and scanned via a Core Sample Drill.
38+
39+
mods.immersivepetroleum.reservoir.removeByName('aquifer')
40+
mods.immersivepetroleum.reservoir.removeByOutput(fluid('oil'))
41+
// mods.immersivepetroleum.reservoir.removeAll()
42+
43+
mods.immersivepetroleum.reservoir.recipeBuilder()
44+
.name('demo')
45+
.fluidOutput(fluid('water'))
46+
.weight(20000)
47+
.minSize(100)
48+
.maxSize(100)
49+
.dimension(0, 1)
50+
.biome('hot')
51+
.register()
52+
53+
mods.immersivepetroleum.reservoir.recipeBuilder()
54+
.name('demo')
55+
.fluidOutput(fluid('lava'))
56+
.weight(2000)
57+
.minSize(1000)
58+
.maxSize(5000)
59+
.replenishRate(100)
60+
.dimension(-1, 1)
61+
.dimensionBlacklist()
62+
.biome('cold')
63+
.biomeBlacklist()
64+
.register()
65+
66+

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ debug_extended_crafting = false
3434
debug_extra_utilities_2 = false
3535
debug_forestry = false
3636
debug_immersive_engineering = false
37+
debug_immersive_petroleum = false
3738
debug_industrial_craft_2_classic = false
3839
debug_industrial_craft_2_experimental = false
3940
debug_industrial_foregoing = false

src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cleanroommc.groovyscript.compat.mods.forestry.Forestry;
2727
import com.cleanroommc.groovyscript.compat.mods.ic2.IC2;
2828
import com.cleanroommc.groovyscript.compat.mods.immersiveengineering.ImmersiveEngineering;
29+
import com.cleanroommc.groovyscript.compat.mods.immersivepetroleum.ImmersivePetroleum;
2930
import com.cleanroommc.groovyscript.compat.mods.industrialforegoing.IndustrialForegoing;
3031
import com.cleanroommc.groovyscript.compat.mods.inspirations.Inspirations;
3132
import com.cleanroommc.groovyscript.compat.mods.integrateddynamics.IntegratedDynamics;
@@ -88,6 +89,7 @@ public class ModSupport {
8889
public static final GroovyContainer<ExtraUtils2> EXTRA_UTILITIES_2 = new InternalModContainer<>("extrautils2", "Extra Utilities 2", ExtraUtils2::new, "extrautilities2");
8990
public static final GroovyContainer<Forestry> FORESTRY = new InternalModContainer<>("forestry", "Forestry", Forestry::new);
9091
public static final GroovyContainer<ImmersiveEngineering> IMMERSIVE_ENGINEERING = new InternalModContainer<>("immersiveengineering", "Immersive Engineering", ImmersiveEngineering::new, "ie");
92+
public static final GroovyContainer<ImmersivePetroleum> IMMERSIVE_PETROLEUM = new InternalModContainer<>("immersivepetroleum", "Immersive Petroleum", ImmersivePetroleum::new);
9193
public static final GroovyContainer<IC2> INDUSTRIALCRAFT = new InternalModContainer<>("ic2", "Industrial Craft 2", IC2::new, "industrialcraft");
9294
public static final GroovyContainer<IndustrialForegoing> INDUSTRIAL_FOREGOING = new InternalModContainer<>("industrialforegoing", "Industrial Foregoing", IndustrialForegoing::new);
9395
public static final GroovyContainer<Inspirations> INSPIRATIONS = new InternalModContainer<>("inspirations", "Inspirations", Inspirations::new);
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package com.cleanroommc.groovyscript.compat.mods.immersivepetroleum;
2+
3+
import com.cleanroommc.groovyscript.api.GroovyBlacklist;
4+
import com.cleanroommc.groovyscript.api.GroovyLog;
5+
import com.cleanroommc.groovyscript.api.IIngredient;
6+
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
7+
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
8+
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
9+
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
10+
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
11+
import flaxbeard.immersivepetroleum.api.crafting.DistillationRecipe;
12+
import it.unimi.dsi.fastutil.floats.FloatArrayList;
13+
import net.minecraft.item.ItemStack;
14+
import net.minecraftforge.fluids.FluidStack;
15+
import org.jetbrains.annotations.ApiStatus;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
@RegistryDescription
19+
public class Distillation extends VirtualizedRegistry<DistillationRecipe> {
20+
21+
@RecipeBuilderDescription(example = {
22+
@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)"),
23+
@Example(".fluidInput(fluid('lava') * 5).output(item('minecraft:diamond')).time(1)")
24+
})
25+
public RecipeBuilder recipeBuilder() {
26+
return new RecipeBuilder();
27+
}
28+
29+
@Override
30+
@GroovyBlacklist
31+
@ApiStatus.Internal
32+
public void onReload() {
33+
removeScripted().forEach(recipe -> DistillationRecipe.recipeList.removeIf(r -> r == recipe));
34+
DistillationRecipe.recipeList.addAll(restoreFromBackup());
35+
}
36+
37+
public void add(DistillationRecipe recipe) {
38+
if (recipe != null) {
39+
addScripted(recipe);
40+
DistillationRecipe.recipeList.add(recipe);
41+
}
42+
}
43+
44+
public boolean remove(DistillationRecipe recipe) {
45+
if (DistillationRecipe.recipeList.removeIf(r -> r == recipe)) {
46+
addBackup(recipe);
47+
return true;
48+
}
49+
return false;
50+
}
51+
52+
@MethodDescription(example = {
53+
@Example(value = "item('immersivepetroleum:material')", commented = true),
54+
@Example(value = "fluid('lubricant')", commented = true)
55+
})
56+
public void removeByOutput(IIngredient output) {
57+
DistillationRecipe.recipeList.removeIf(r -> {
58+
for (ItemStack itemstack : r.getItemOutputs()) {
59+
if (output.test(itemstack)) {
60+
addBackup(r);
61+
return true;
62+
}
63+
}
64+
for (FluidStack fluidStack : r.getFluidOutputs()) {
65+
if (output.test(fluidStack)) {
66+
addBackup(r);
67+
return true;
68+
}
69+
}
70+
return false;
71+
});
72+
}
73+
74+
@MethodDescription(example = @Example("fluid('oil')"))
75+
public void removeByInput(IIngredient input) {
76+
DistillationRecipe.recipeList.removeIf(r -> {
77+
for (FluidStack fluidStack : r.getFluidInputs()) {
78+
if (input.test(fluidStack)) {
79+
addBackup(r);
80+
return true;
81+
}
82+
}
83+
return false;
84+
});
85+
}
86+
87+
@MethodDescription(type = MethodDescription.Type.QUERY)
88+
public SimpleObjectStream<DistillationRecipe> streamRecipes() {
89+
return new SimpleObjectStream<>(DistillationRecipe.recipeList).setRemover(this::remove);
90+
}
91+
92+
@MethodDescription(priority = 2000, example = @Example(commented = true))
93+
public void removeAll() {
94+
DistillationRecipe.recipeList.forEach(this::addBackup);
95+
DistillationRecipe.recipeList.clear();
96+
}
97+
98+
@Property(property = "fluidInput", valid = @Comp("1"))
99+
@Property(property = "output", valid = {@Comp(type = Comp.Type.GTE, value = "0"), @Comp(type = Comp.Type.LTE, value = "Integer.MAX_VALUE")})
100+
@Property(property = "fluidOutput", valid = {@Comp(type = Comp.Type.GTE, value = "0"), @Comp(type = Comp.Type.LTE, value = "Integer.MAX_VALUE")})
101+
public static class RecipeBuilder extends AbstractRecipeBuilder<DistillationRecipe> {
102+
103+
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE))
104+
private final FloatArrayList chance = new FloatArrayList();
105+
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE))
106+
private int time;
107+
@Property(valid = @Comp(value = "0", type = Comp.Type.GTE))
108+
private int energy;
109+
110+
@RecipeBuilderMethodDescription(field = {"output", "chance"})
111+
public RecipeBuilder output(ItemStack output, float chance) {
112+
this.output.add(output);
113+
this.chance.add(chance);
114+
return this;
115+
}
116+
117+
@Override
118+
@RecipeBuilderMethodDescription(field = {"output", "chance"})
119+
public RecipeBuilder output(ItemStack output) {
120+
return this.output(output, 1);
121+
}
122+
123+
@RecipeBuilderMethodDescription
124+
public RecipeBuilder time(int time) {
125+
this.time = time;
126+
return this;
127+
}
128+
129+
@RecipeBuilderMethodDescription
130+
public RecipeBuilder energy(int energy) {
131+
this.energy = energy;
132+
return this;
133+
}
134+
135+
@Override
136+
public String getErrorMsg() {
137+
return "Error adding Immersive Petroleum Distillation recipe";
138+
}
139+
140+
@Override
141+
public void validate(GroovyLog.Msg msg) {
142+
validateItems(msg, 0, 0, 0, Integer.MAX_VALUE);
143+
validateFluids(msg, 1, 1, 0, Integer.MAX_VALUE);
144+
chance.trim();
145+
msg.add(output.size() != chance.size(), "output and chance must be of equal length, yet output was {} and chance was {}", output.size(), chance.size());
146+
msg.add(time <= 0, "time must be greater than or equal to 1, yet it was {}", time);
147+
msg.add(energy < 0, "energy must be a non negative integer, yet it was {}", energy);
148+
}
149+
150+
@Override
151+
@RecipeBuilderRegistrationMethod
152+
public @Nullable DistillationRecipe register() {
153+
if (!validate()) return null;
154+
DistillationRecipe recipe = new DistillationRecipe(fluidOutput.toArray(new FluidStack[0]), output.toArray(new ItemStack[0]), fluidInput.get(0), energy, time, chance.elements());
155+
ModSupport.IMMERSIVE_PETROLEUM.get().distillation.add(recipe);
156+
return recipe;
157+
}
158+
}
159+
160+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.cleanroommc.groovyscript.compat.mods.immersivepetroleum;
2+
3+
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
4+
5+
public class ImmersivePetroleum extends GroovyPropertyContainer {
6+
7+
public final Distillation distillation = new Distillation();
8+
public final Reservoir reservoir = new Reservoir();
9+
10+
}

0 commit comments

Comments
 (0)