Skip to content
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 ProjectE compat #163

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ final def mod_dependencies = [
'mekanism-268560:2835175' : [project.debug_mekanism],
'natures-aura-306626:2882138' : [project.debug_natures_aura],
'packmode-278398:2567799' : [project.debug_packmode],
'projecte-226410:2702991' : [project.debug_projecte],
'athenaeum-284350:4633750' : [project.debug_pyrotech],
'pyrotech-306676:4956838' : [project.debug_pyrotech],
'mystical_world-282940:3460961' : [project.debug_roots],
Expand Down
49 changes: 49 additions & 0 deletions examples/postInit/projecte.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

// Auto generated groovyscript example file
// MODS_LOADED: projecte

println 'mod \'projecte\' detected, running script'

// Mob Entity Randomizer:
// Converts an entity on the list into a random other entity on the list when a projectile fired from the Philosopher's
// Stone hits it. This list contains hostile mob entities by default.

mods.projecte.entity_randomizer_mob.remove(entity('minecraft:zombie'))
// mods.projecte.entity_randomizer_mob.removeAll()

mods.projecte.entity_randomizer_mob.add(entity('minecraft:pig'))

// Peaceful Entity Randomizer:
// Converts an entity on the list into a random other entity on the list when a projectile fired from the Philosopher's
// Stone hits it. This list contains peaceful entities by default.

mods.projecte.entity_randomizer_peaceful.remove(entity('minecraft:pig'))
// mods.projecte.entity_randomizer_peaceful.removeAll()

mods.projecte.entity_randomizer_peaceful.add(entity('minecraft:zombie'))

// World Transmutation:
// Converts an input blockstate into an output blockstate when right-clicked with by a Philosopher's Stone, with the abity
// to be converted into a different output blockstate when holding shift.

mods.projecte.transmutation.removeByInput(blockstate('minecraft:wool'))
mods.projecte.transmutation.removeByOutput(blockstate('minecraft:dirt'))
// mods.projecte.transmutation.removeAll()

mods.projecte.transmutation.recipeBuilder()
.input(blockstate('minecraft:end_stone'))
.output(blockstate('minecraft:diamond_block'), blockstate('minecraft:gold_block'))
.register()

mods.projecte.transmutation.recipeBuilder()
.input(blockstate('minecraft:diamond_block'))
.output(blockstate('minecraft:end_stone'))
.altOutput(blockstate('minecraft:gold_block'))
.register()

mods.projecte.transmutation.recipeBuilder()
.input(blockstate('minecraft:gold_block'))
.output(blockstate('minecraft:diamond_block'))
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ debug_integrated_dynamics = false
debug_mekanism = false
debug_natures_aura = false
debug_packmode = false
debug_projecte = false
debug_pyrotech = false
debug_roots = false
debug_rustic = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.cleanroommc.groovyscript.compat.mods.jei.JustEnoughItems;
import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism;
import com.cleanroommc.groovyscript.compat.mods.naturesaura.NaturesAura;
import com.cleanroommc.groovyscript.compat.mods.projecte.ProjectE;
import com.cleanroommc.groovyscript.compat.mods.pyrotech.PyroTech;
import com.cleanroommc.groovyscript.compat.mods.roots.Roots;
import com.cleanroommc.groovyscript.compat.mods.rustic.Rustic;
Expand Down Expand Up @@ -86,6 +87,7 @@ public class ModSupport implements IDynamicGroovyProperty {
public static final GroovyContainer<JustEnoughItems> JEI = new InternalModContainer<>("jei", "Just Enough Items", JustEnoughItems::new, "hei");
public static final GroovyContainer<Mekanism> MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::new);
public static final GroovyContainer<NaturesAura> NATURES_AURA = new InternalModContainer<>("naturesaura", "Nature's Aura", NaturesAura::new);
public static final GroovyContainer<ProjectE> PROJECT_E = new InternalModContainer<>("projecte", "ProjectE", ProjectE::new);
public static final GroovyContainer<PyroTech> PYROTECH = new InternalModContainer<>("pyrotech", "Pyrotech", PyroTech::new);
public static final GroovyContainer<Roots> ROOTS = new InternalModContainer<>("roots", "Roots 3", Roots::new);
public static final GroovyContainer<Rustic> RUSTIC = new InternalModContainer<>("rustic", "Rustic", Rustic::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.cleanroommc.groovyscript.compat.mods.projecte;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.core.mixin.projecte.WorldHelperAccessor;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.entity.EntityLiving;
import net.minecraftforge.fml.common.registry.EntityEntry;

@RegistryDescription(category = RegistryDescription.Category.ENTRIES)
public class EntityRandomizerMob extends VirtualizedRegistry<Class<? extends EntityLiving>> {

@Override
@GroovyBlacklist
public void onReload() {
WorldHelperAccessor.getMobs().removeAll(removeScripted());
WorldHelperAccessor.getMobs().addAll(restoreFromBackup());
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public void add(Class<? extends EntityLiving> entry) {
addScripted(entry);
WorldHelperAccessor.getMobs().add(entry);
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("entity('minecraft:pig')"))
public void add(EntityEntry entity) {
add((Class<? extends EntityLiving>) entity.getEntityClass());
}

@MethodDescription
public boolean remove(Class<? extends EntityLiving> entry) {
if (WorldHelperAccessor.getMobs().removeIf(r -> r == entry)) {
addBackup(entry);
return true;
}
return false;
}

@MethodDescription(example = @Example("entity('minecraft:zombie')"))
public boolean remove(EntityEntry entity) {
return remove((Class<? extends EntityLiving>) entity.getEntityClass());
}

@MethodDescription(type = MethodDescription.Type.QUERY)
public SimpleObjectStream<Class<? extends EntityLiving>> streamRecipes() {
return new SimpleObjectStream<>(WorldHelperAccessor.getMobs()).setRemover(this::remove);
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAll() {
WorldHelperAccessor.getMobs().forEach(this::addBackup);
WorldHelperAccessor.getMobs().clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.cleanroommc.groovyscript.compat.mods.projecte;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.core.mixin.projecte.WorldHelperAccessor;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.entity.EntityLiving;
import net.minecraftforge.fml.common.registry.EntityEntry;

@RegistryDescription(category = RegistryDescription.Category.ENTRIES)
public class EntityRandomizerPeaceful extends VirtualizedRegistry<Class<? extends EntityLiving>> {

@Override
@GroovyBlacklist
public void onReload() {
WorldHelperAccessor.getPeacefuls().removeAll(removeScripted());
WorldHelperAccessor.getPeacefuls().addAll(restoreFromBackup());
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public void add(Class<? extends EntityLiving> entry) {
addScripted(entry);
WorldHelperAccessor.getPeacefuls().add(entry);
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("entity('minecraft:zombie')"))
public void add(EntityEntry entity) {
add((Class<? extends EntityLiving>) entity.getEntityClass());
}

@MethodDescription
public boolean remove(Class<? extends EntityLiving> entry) {
if (WorldHelperAccessor.getPeacefuls().removeIf(r -> r == entry)) {
addBackup(entry);
return true;
}
return false;
}

@MethodDescription(example = @Example("entity('minecraft:pig')"))
public boolean remove(EntityEntry entity) {
return remove((Class<? extends EntityLiving>) entity.getEntityClass());
}

@MethodDescription(type = MethodDescription.Type.QUERY)
public SimpleObjectStream<Class<? extends EntityLiving>> streamRecipes() {
return new SimpleObjectStream<>(WorldHelperAccessor.getPeacefuls()).setRemover(this::remove);
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAll() {
WorldHelperAccessor.getPeacefuls().forEach(this::addBackup);
WorldHelperAccessor.getPeacefuls().clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.cleanroommc.groovyscript.compat.mods.projecte;

import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;

public class ProjectE extends ModPropertyContainer {

public final EntityRandomizerMob entityRandomizerMob = new EntityRandomizerMob();
public final EntityRandomizerPeaceful entityRandomizerPeaceful = new EntityRandomizerPeaceful();
public final Transmutation transmutation = new Transmutation();

public ProjectE() {
addRegistry(entityRandomizerMob);
addRegistry(entityRandomizerPeaceful);
addRegistry(transmutation);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.cleanroommc.groovyscript.compat.mods.projecte;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
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.SimpleObjectStream;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import moze_intel.projecte.utils.WorldTransmutations;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.jetbrains.annotations.Nullable;

@RegistryDescription
public class Transmutation extends VirtualizedRegistry<WorldTransmutations.Entry> {

@RecipeBuilderDescription(example = {
@Example(".input(blockstate('minecraft:end_stone')).output(blockstate('minecraft:diamond_block'), blockstate('minecraft:gold_block'))"),
@Example(".input(blockstate('minecraft:diamond_block')).output(blockstate('minecraft:end_stone')).altOutput(blockstate('minecraft:gold_block'))"),
@Example(".input(blockstate('minecraft:gold_block')).output(blockstate('minecraft:diamond_block'))")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
@GroovyBlacklist
public void onReload() {
WorldTransmutations.getWorldTransmutations().removeAll(removeScripted());
WorldTransmutations.getWorldTransmutations().addAll(restoreFromBackup());
}

public void add(WorldTransmutations.Entry recipe) {
addScripted(recipe);
WorldTransmutations.getWorldTransmutations().add(recipe);
}

public boolean remove(WorldTransmutations.Entry recipe) {
if (WorldTransmutations.getWorldTransmutations().removeIf(r -> r == recipe)) {
addBackup(recipe);
return true;
}
return false;
}

@MethodDescription(example = @Example("blockstate('minecraft:wool')"))
public boolean removeByInput(IBlockState input) {
return WorldTransmutations.getWorldTransmutations().removeIf(r -> {
if (input.equals(r.input)) {
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(example = @Example("blockstate('minecraft:dirt')"))
public boolean removeByOutput(IBlockState output) {
return WorldTransmutations.getWorldTransmutations().removeIf(r -> {
if (output.equals(r.outputs.getKey()) || output.equals(r.outputs.getValue())) {
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.QUERY)
public SimpleObjectStream<WorldTransmutations.Entry> streamRecipes() {
return new SimpleObjectStream<>(WorldTransmutations.getWorldTransmutations()).setRemover(this::remove);
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAll() {
WorldTransmutations.getWorldTransmutations().forEach(this::addBackup);
WorldTransmutations.getWorldTransmutations().clear();
}

public static class RecipeBuilder extends AbstractRecipeBuilder<WorldTransmutations.Entry> {

@Property(valid = @Comp(value = "null", type = Comp.Type.NOT), ignoresInheritedMethods = true)
IBlockState input;
@Property(valid = @Comp(value = "null", type = Comp.Type.NOT), ignoresInheritedMethods = true)
IBlockState output;
@Property
IBlockState altOutput;

@RecipeBuilderMethodDescription
public RecipeBuilder input(IBlockState input) {
this.input = input;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder output(IBlockState output) {
this.output = output;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder altOutput(IBlockState altOutput) {
this.altOutput = altOutput;
return this;
}

@RecipeBuilderMethodDescription(field = {"output", "altOutput"})
public RecipeBuilder output(IBlockState output, IBlockState altOutput) {
this.output = output;
this.altOutput = altOutput;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder input(Block input) {
this.input = input.getDefaultState();
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder output(Block output) {
this.output = output.getDefaultState();
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder altOutput(Block altOutput) {
this.altOutput = altOutput.getDefaultState();
return this;
}

@RecipeBuilderMethodDescription(field = {"output", "altOutput"})
public RecipeBuilder output(Block output, Block altOutput) {
this.output = output.getDefaultState();
this.altOutput = altOutput.getDefaultState();
return this;
}

@Override
public String getErrorMsg() {
return "Error adding ProjectE Transmutation recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg);
validateFluids(msg);
msg.add(input == null, "input must not be null");
msg.add(output == null, "output must not be null");
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable WorldTransmutations.Entry register() {
if (!validate()) return null;
WorldTransmutations.Entry recipe = new WorldTransmutations.Entry(input, ImmutablePair.of(output, altOutput));
ModSupport.PROJECT_E.get().transmutation.add(recipe);
return recipe;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class LateMixin implements ILateMixinLoader {
"inspirations",
"jei",
"mekanism",
"projecte",
"pyrotech",
"roots",
"tcomplement",
Expand Down
Loading