Skip to content

Commit

Permalink
add Immersive Petroleum compat (#171)
Browse files Browse the repository at this point in the history
* add Immersive Petroleum compat

* remove incorrect annotation

* convert distillation to use different method of adding chance

* update ModPropertyContainer
  • Loading branch information
WaitingIdly authored Jul 6, 2024
1 parent 9fb2042 commit 0a9cdde
Show file tree
Hide file tree
Showing 8 changed files with 517 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ final def mod_dependencies = [
'extended-crafting-nomifactory-edition-398267:3613140': [project.debug_extended_crafting],
'extra-utilities-2-225561:2678374' : [project.debug_extra_utilities_2],
'forestry-59751:2918418' : [project.debug_forestry],
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering],
'immersive_engineering-231951:2974106' : [project.debug_immersive_engineering, project.debug_immersive_petroleum],
'immersive-petroleum-268250:3382321' : [project.debug_immersive_petroleum],
// WARNING: experimental must be placed before classic, otherwise you will crash when debugging either. Check FluidGenerator compat to confirm
'industrialcraft_experimental-242638:3838713' : [project.debug_industrial_craft_2_experimental],
'industrialcraft_classic-242942:3093607' : [project.debug_industrial_craft_2_classic],
Expand Down Expand Up @@ -137,6 +138,10 @@ dependencies {
runtimeOnly rfg.deobf('curse.maven:jei-bees-248370:2490058')
}

if (project.debug_immersive_petroleum.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:just-enough-petroleum-291727:2549332')
}

if (project.debug_pyrotech.toBoolean()) {
runtimeOnly rfg.deobf("curse.maven:dropt-284973:3758733")
}
Expand Down
66 changes: 66 additions & 0 deletions examples/postInit/immersivepetroleum.groovy
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()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ debug_extended_crafting = false
debug_extra_utilities_2 = false
debug_forestry = false
debug_immersive_engineering = false
debug_immersive_petroleum = false
debug_industrial_craft_2_classic = false
debug_industrial_craft_2_experimental = false
debug_industrial_foregoing = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.cleanroommc.groovyscript.compat.mods.forestry.Forestry;
import com.cleanroommc.groovyscript.compat.mods.ic2.IC2;
import com.cleanroommc.groovyscript.compat.mods.immersiveengineering.ImmersiveEngineering;
import com.cleanroommc.groovyscript.compat.mods.immersivepetroleum.ImmersivePetroleum;
import com.cleanroommc.groovyscript.compat.mods.industrialforegoing.IndustrialForegoing;
import com.cleanroommc.groovyscript.compat.mods.inspirations.Inspirations;
import com.cleanroommc.groovyscript.compat.mods.integrateddynamics.IntegratedDynamics;
Expand Down Expand Up @@ -88,6 +89,7 @@ public class ModSupport {
public static final GroovyContainer<ExtraUtils2> EXTRA_UTILITIES_2 = new InternalModContainer<>("extrautils2", "Extra Utilities 2", ExtraUtils2::new, "extrautilities2");
public static final GroovyContainer<Forestry> FORESTRY = new InternalModContainer<>("forestry", "Forestry", Forestry::new);
public static final GroovyContainer<ImmersiveEngineering> IMMERSIVE_ENGINEERING = new InternalModContainer<>("immersiveengineering", "Immersive Engineering", ImmersiveEngineering::new, "ie");
public static final GroovyContainer<ImmersivePetroleum> IMMERSIVE_PETROLEUM = new InternalModContainer<>("immersivepetroleum", "Immersive Petroleum", ImmersivePetroleum::new);
public static final GroovyContainer<IC2> INDUSTRIALCRAFT = new InternalModContainer<>("ic2", "Industrial Craft 2", IC2::new, "industrialcraft");
public static final GroovyContainer<IndustrialForegoing> INDUSTRIAL_FOREGOING = new InternalModContainer<>("industrialforegoing", "Industrial Foregoing", IndustrialForegoing::new);
public static final GroovyContainer<Inspirations> INSPIRATIONS = new InternalModContainer<>("inspirations", "Inspirations", Inspirations::new);
Expand Down
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;
}
}

}
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();

}
Loading

0 comments on commit 0a9cdde

Please sign in to comment.