Skip to content

Commit

Permalink
GroovyScript 1.1.0 (#2506)
Browse files Browse the repository at this point in the history
(cherry picked from commit fe65538)
  • Loading branch information
brachy84 authored and ALongStringOfNumbers committed Jul 2, 2024
1 parent 1dca2cb commit cdf0e8b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.4.3") { transitive = false }
api("com.cleanroommc:groovyscript:1.0.1") { transitive = false }
api("com.cleanroommc:groovyscript:1.1.0") { transitive = false }
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.698")
api("appeng:ae2-uel:v0.56.4") { transitive = false }
api rfg.deobf("curse.maven:ctm-267602:2915363") // CTM 1.0.2.31
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
dependencies = "required:forge@[14.23.5.2847,);" + "required-after:codechickenlib@[3.2.3,);" +
"after:appliedenergistics2;" + "after:forestry;" + "after:extrabees;" + "after:extratrees;" +
"after:genetics;" + "after:magicbees;" + "after:jei@[4.15.0,);" + "after:crafttweaker@[4.1.20,);" +
"after:groovyscript@[1.0.1,);" + "after:theoneprobe;" + "after:hwyla;")
"after:groovyscript@[1.1.0,);" + "after:theoneprobe;" + "after:hwyla;")
public class GregTechMod {

// Hold this so that we can reference non-interface methods without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ private MaterialRegistryImpl createInternalRegistry() {
return registry;
}

@NotNull
public MaterialRegistry getDefaultRegistry() {
return gregtechRegistry;
}

@NotNull
public Material getDefaultFallback() {
return gregtechRegistry.getFallbackMaterial();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ public static Material.Builder components(Material.Builder builder, Object... ob
materialStacks.add(materialStack);
} else if (o instanceof Material material) {
materialStacks.add(new MaterialStack(material, 1));
} else if (o instanceof Integer) {
GroovyLog.msg("Error creating GregTech material")
.add("Tried to use old method for material components in the shape of (material1, amount1, material2, amount2)")
.add("Please change this into (material1 * amount1, material2 * amount2)")
.error().post();
} else {
GroovyLog.get()
.error("Material components must be of type Material or MaterialStack, but was of type {}",
o == null ? null : o.getClass());
GroovyLog.msg("Error creating GregTech material")
.add("Material components must be of type Material or MaterialStack, but was of type {}",
o == null ? null : o.getClass())
.error().post();
}
}
return builder.components(materialStacks.toArray(new MaterialStack[0]));
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/gregtech/integration/groovy/GroovyScriptModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@
import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.GroovyPlugin;
import com.cleanroommc.groovyscript.api.IGameObjectParser;
import com.cleanroommc.groovyscript.api.IObjectParser;
import com.cleanroommc.groovyscript.api.Result;
import com.cleanroommc.groovyscript.compat.mods.GroovyContainer;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.event.ScriptRunEvent;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import com.cleanroommc.groovyscript.helper.EnumHelper;
import com.cleanroommc.groovyscript.sandbox.expand.ExpansionHelper;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -118,6 +117,7 @@ public static <T extends Enum<T>> T parseAndValidateEnumValue(Class<T> clazz, St
return t;
}

@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
public static GroovyContainer<?> getInstance() {
return modSupportContainer;
}
Expand Down Expand Up @@ -238,34 +238,31 @@ public static void loadMetaItemBracketHandler() {

@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
@Override
public @Nullable ModPropertyContainer createModPropertyContainer() {
public @Nullable GroovyPropertyContainer createGroovyPropertyContainer() {
return new PropertyContainer();
}

@Optional.Method(modid = Mods.Names.GROOVY_SCRIPT)
@Override
public void onCompatLoaded(GroovyContainer<?> groovyContainer) {
GroovyScriptModule.modSupportContainer = groovyContainer;
GameObjectHandler.builder("recipemap", RecipeMap.class)
.mod(GTValues.MODID)
.parser(IGameObjectParser.wrapStringGetter(RecipeMap::getByName))
public void onCompatLoaded(GroovyContainer<?> container) {
GroovyScriptModule.modSupportContainer = container;
container.objectMapperBuilder("recipemap", RecipeMap.class)
.parser(IObjectParser.wrapStringGetter(RecipeMap::getByName))
.completerOfNamed(RecipeMap::getRecipeMaps, RecipeMap::getUnlocalizedName)
.register();
GameObjectHandler.builder("material", Material.class)
.mod(GTValues.MODID)
.parser(IGameObjectParser.wrapStringGetter(GregTechAPI.materialManager::getMaterial))
container.objectMapperBuilder("material", Material.class)
.parser(IObjectParser.wrapStringGetter(GregTechAPI.materialManager::getMaterial))
.completerOfNamed(GregTechAPI.materialManager::getRegisteredMaterials,
mat -> mat.getResourceLocation().toString())
.register();

GameObjectHandler.builder("oreprefix", OrePrefix.class)
.mod(GTValues.MODID)
.parser(IGameObjectParser.wrapStringGetter(OrePrefix::getPrefix))
container.objectMapperBuilder("oreprefix", OrePrefix.class)
.parser(IObjectParser.wrapStringGetter(OrePrefix::getPrefix))
.completerOfNamed(OrePrefix::values, v -> v.name)
.register();

GameObjectHandler.builder("metaitem", ItemStack.class)
.mod(GTValues.MODID)
.parser(IGameObjectParser.wrapStringGetter(GroovyScriptModule::getMetaItem))
container.objectMapperBuilder("metaitem", ItemStack.class)
.parser(IObjectParser.wrapStringGetter(GroovyScriptModule::getMetaItem))
.completer((paramIndex, items) -> {
if (paramIndex != 0) return;
for (var iterator = metaItems.object2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
Expand All @@ -280,8 +277,7 @@ public void onCompatLoaded(GroovyContainer<?> groovyContainer) {
})
.register();

GameObjectHandler.builder("element", Element.class)
.mod(GTValues.MODID)
container.objectMapperBuilder("element", Element.class)
.parser((s, args) -> {
Element element = Elements.get(s);
if (element != null) return Result.some(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.event.EventBusType;
import com.cleanroommc.groovyscript.event.GroovyEventManager;
import com.cleanroommc.groovyscript.sandbox.ClosureHelper;
import com.cleanroommc.groovyscript.sandbox.LoadStage;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;

public class PropertyContainer extends ModPropertyContainer {
public class PropertyContainer extends GroovyPropertyContainer {

public void materialEvent(EventPriority priority, @DelegatesTo(MaterialEvent.class) Closure<?> eventListener) {
if (GroovyScriptModule.isCurrentlyRunning() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VirtualizedRecipeMap extends VirtualizedRegistry<Recipe> {
public VirtualizedRecipeMap(RecipeMap<?> recipeMap) {
super(Alias.generateOf(recipeMap.unlocalizedName, CaseFormat.LOWER_UNDERSCORE));
this.recipeMap = recipeMap;
GroovyScriptModule.getInstance().getRegistrar().addRegistry(this);
GroovyScriptModule.getInstance().addProperty(this);
}

@Override
Expand Down

0 comments on commit cdf0e8b

Please sign in to comment.