Skip to content

Commit

Permalink
add ProjectE compat (#163)
Browse files Browse the repository at this point in the history
* projecte compat

* address review request and merge mobs + peacefuls
  • Loading branch information
WaitingIdly authored Jul 3, 2024
1 parent a0621bd commit 7a7eb44
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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
44 changes: 44 additions & 0 deletions examples/postInit/projecte.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

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

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

// 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. There are two lists, one for 'mobs' and the other for 'peacefuls', but any entity can go on either list.

mods.projecte.entity_randomizer.removeMob(entity('minecraft:zombie'))
mods.projecte.entity_randomizer.removePeaceful(entity('minecraft:pig'))
// mods.projecte.entity_randomizer.removeAll()
// mods.projecte.entity_randomizer.removeAllMobs()
// mods.projecte.entity_randomizer.removeAllPeacefuls()

mods.projecte.entity_randomizer.addMob(entity('minecraft:pig'))
mods.projecte.entity_randomizer.addPeaceful(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 @@ -42,6 +42,7 @@ debug_lazy_ae2 = 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 @@ -32,6 +32,7 @@
import com.cleanroommc.groovyscript.compat.mods.lazyae2.LazyAE2;
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 @@ -91,6 +92,7 @@ public class ModSupport {
public static final GroovyContainer<Mekanism> MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::new);
public static final GroovyContainer<LazyAE2> LAZYAE2 = new InternalModContainer<>("threng", "LazyAE2", LazyAE2::new, "lazyae2");
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,105 @@
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.AbstractReloadableStorage;
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 EntityRandomizer extends VirtualizedRegistry<Class<? extends EntityLiving>> {

private final AbstractReloadableStorage<Class<? extends EntityLiving>> peacefulStorage = new AbstractReloadableStorage<>();

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

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

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

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

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

@MethodDescription
public boolean removeMob(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 removeMob(EntityEntry entity) {
return removeMob((Class<? extends EntityLiving>) entity.getEntityClass());
}

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

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

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

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

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAllMobs() {
WorldHelperAccessor.getMobs().forEach(this::addBackup);
WorldHelperAccessor.getMobs().clear();
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAllPeacefuls() {
WorldHelperAccessor.getPeacefuls().forEach(peacefulStorage::addBackup);
WorldHelperAccessor.getPeacefuls().clear();
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAll() {
removeAllMobs();
removeAllPeacefuls();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cleanroommc.groovyscript.compat.mods.projecte;

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

public class ProjectE extends ModPropertyContainer {

public final EntityRandomizer entityRandomizer = new EntityRandomizer();
public final Transmutation transmutation = new Transmutation();

public ProjectE() {
addRegistry(entityRandomizer);
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 @@ -29,6 +29,7 @@ public class LateMixin implements ILateMixinLoader {
"inspirations",
"jei",
"mekanism",
"projecte",
"pyrotech",
"roots",
"tcomplement",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cleanroommc.groovyscript.core.mixin.projecte;

import moze_intel.projecte.utils.WorldHelper;
import net.minecraft.entity.EntityLiving;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(value = WorldHelper.class, remap = false)
public interface WorldHelperAccessor {

@Accessor
static List<Class<? extends EntityLiving>> getPeacefuls() {
throw new UnsupportedOperationException();
}

@Accessor
static List<Class<? extends EntityLiving>> getMobs() {
throw new UnsupportedOperationException();
}

}
Loading

0 comments on commit 7a7eb44

Please sign in to comment.