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.
* projecte compat * address review request and merge mobs + peacefuls
- Loading branch information
1 parent
a0621bd
commit 7a7eb44
Showing
11 changed files
with
384 additions
and
0 deletions.
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,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() | ||
|
||
|
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
105 changes: 105 additions & 0 deletions
105
src/main/java/com/cleanroommc/groovyscript/compat/mods/projecte/EntityRandomizer.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,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(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/cleanroommc/groovyscript/compat/mods/projecte/ProjectE.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,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); | ||
} | ||
|
||
} |
163 changes: 163 additions & 0 deletions
163
src/main/java/com/cleanroommc/groovyscript/compat/mods/projecte/Transmutation.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,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; | ||
} | ||
} | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/cleanroommc/groovyscript/core/mixin/projecte/WorldHelperAccessor.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,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(); | ||
} | ||
|
||
} |
Oops, something went wrong.