Skip to content

Commit

Permalink
game object handlers now with builders & completion for all
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Mar 12, 2024
1 parent 3fd0ab1 commit b0b3ebc
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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<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<Roots> ROOTS = new InternalModContainer<>("roots", "Roots 3", () -> new Roots());
public static final GroovyContainer<Thaumcraft> THAUMCRAFT = new InternalModContainer<>("thaumcraft", "Thaumcraft", Thaumcraft::new, "tc", "thaum");
public static final GroovyContainer<ThermalExpansion> THERMAL_EXPANSION = new InternalModContainer<>("thermalexpansion", "Thermal Expansion", ThermalExpansion::new, "te", "thermal");
public static final GroovyContainer<TinkersComplement> TINKERS_COMPLEMENT = new InternalModContainer<>("tcomplement", "Tinkers Complement", TinkersComplement::new, "tcomp", "tinkerscomplement");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import appeng.api.config.TunnelType;
import com.cleanroommc.groovyscript.api.IGameObjectHandler;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;

import java.util.Arrays;
import java.util.Locale;

public class AppliedEnergistics2 extends ModPropertyContainer {

Expand All @@ -23,7 +26,10 @@ public AppliedEnergistics2() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("appliedenergistics2", "tunnel", TunnelType.class,
IGameObjectHandler.wrapEnum(TunnelType.class, false));
GameObjectHandler.builder("tunnel", TunnelType.class)
.mod("appliedenergistics2")
.parser(IGameObjectHandler.wrapEnum(TunnelType.class, false))
.completerOfNamed(() -> Arrays.asList(TunnelType.values()), v -> v.name().toUpperCase(Locale.ROOT))
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.perktree.PerkTreeConfig;
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.starlightaltar.StarlightAltar;
import com.cleanroommc.groovyscript.core.mixin.astralsorcery.ConstellationRegistryAccessor;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import com.cleanroommc.groovyscript.sandbox.expand.ExpansionHelper;
import hellfirepvp.astralsorcery.common.constellation.IConstellation;
Expand Down Expand Up @@ -54,14 +54,18 @@ public AstralSorcery() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("astralsorcery", "constellation", IConstellation.class, (s, args) -> {
for (IConstellation constellation : ConstellationRegistryAccessor.getConstellationList()) {
if (constellation.getSimpleName().equalsIgnoreCase(s)) {
return Result.some(constellation);
}
}
return Result.error();
});
GameObjectHandler.builder("constellation", IConstellation.class)
.mod("astralsorcery")
.parser((s, args) -> {
for (IConstellation constellation : ConstellationRegistryAccessor.getConstellationList()) {
if (constellation.getSimpleName().equalsIgnoreCase(s)) {
return Result.some(constellation);
}
}
return Result.error();
})
.completerOfNamed(ConstellationRegistryAccessor::getConstellationList, IConstellation::getSimpleName)
.register();
ExpansionHelper.mixinClass(ItemStack.class, CrystalItemStackExpansion.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.cleanroommc.groovyscript.api.IGameObjectHandler;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.lexicon.LexiconCategory;
import vazkii.botania.api.lexicon.LexiconEntry;

import java.util.function.Supplier;

public class Botania extends ModPropertyContainer {

public final ElvenTrade elvenTrade = new ElvenTrade();
Expand Down Expand Up @@ -58,8 +56,11 @@ public static LexiconEntry getEntry(String name) {
@SuppressWarnings("Convert2MethodRef")
@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("botania", "brew", vazkii.botania.api.brew.Brew.class,
IGameObjectHandler.wrapStringGetter(val -> BotaniaAPI.brewMap.get(val), false),
(Supplier<vazkii.botania.api.brew.Brew>) () -> BotaniaAPI.fallbackBrew);
GameObjectHandler.builder("brew", vazkii.botania.api.brew.Brew.class)
.mod("botania")
.parser(IGameObjectHandler.wrapStringGetter(val -> BotaniaAPI.brewMap.get(val), false))
.completerOfNames(BotaniaAPI.brewMap::keySet)
.defaultValue(() -> BotaniaAPI.fallbackBrew)
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.cleanroommc.groovyscript.api.IGameObjectHandler;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import org.cyclops.evilcraft.core.weather.WeatherType;

import java.util.Arrays;
import java.util.List;

public class EvilCraft extends ModPropertyContainer {

public final BloodInfuser bloodInfuser = new BloodInfuser();
Expand All @@ -17,7 +20,12 @@ public EvilCraft() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("evilcraft", "weather", WeatherType.class,
IGameObjectHandler.wrapStringGetter(WeatherType::valueOf, true));
final List<String> weatherTypes = Arrays.asList("any", "clear", "rain", "lightning");
GameObjectHandler.builder("weather", WeatherType.class)
.mod("evilcraft")
.parser(IGameObjectHandler.wrapStringGetter(WeatherType::valueOf, true))
.completerOfNames(() -> weatherTypes) // elements don't have names
.defaultValue(() -> WeatherType.ANY)
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.cleanroommc.groovyscript.api.Result;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.core.ForestryAPI;
import forestry.api.genetics.AlleleManager;
Expand Down Expand Up @@ -44,7 +44,11 @@ public static Result<AlleleBeeSpecies> parseSpecies(String mainArg, Object... ar
}
String[] parts = mainArg.split(":");
if (parts.length < 2) {
Result.error("Can't find bee species for '{}'", mainArg);
if (args.length > 0 && args[0] instanceof String s) {
parts = new String[]{parts[0], s};
} else {
Result.error("Can't find bee species for '{}'", mainArg);
}
}
IAlleleBeeSpecies species = (IAlleleBeeSpecies) AlleleManager.alleleRegistry.getAllele(parts[0] + "." + parts[1]);
if (species instanceof AlleleBeeSpecies) return Result.some((AlleleBeeSpecies) species);
Expand All @@ -61,6 +65,10 @@ protected static String getNormalName(String name) {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("forestry", "species", AlleleBeeSpecies.class, Forestry::parseSpecies);
GameObjectHandler.builder("species", AlleleBeeSpecies.class)
.mod("forestry")
.parser(Forestry::parseSpecies)
.completerOfNamed(AlleleManager.alleleRegistry.getRegisteredAlleles()::keySet, s -> s.replace('.', ':')) // elements don't have names
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.Result;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
Expand Down Expand Up @@ -63,12 +63,19 @@ public Mekanism() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("mekanism", "gas", GasStack.class, (s, args) -> {
Gas gas = GasRegistry.getGas(s);
return gas == null ? Result.error() : Result.some(new GasStack(gas, 1));
});
GameObjectHandlerManager.registerGameObjectHandler("mekanism", "infusion", InfuseType.class,
IGameObjectHandler.wrapStringGetter(InfuseRegistry::get, true));
GameObjectHandler.builder("gas", GasStack.class)
.mod("mekanism")
.parser((s, args) -> {
Gas gas = GasRegistry.getGas(s);
return gas == null ? Result.error() : Result.some(new GasStack(gas, 1));
})
.completerOfNamed(GasRegistry::getRegisteredGasses, Gas::getName)
.register();
GameObjectHandler.builder("infusion", InfuseType.class)
.mod("mekanism")
.parser(IGameObjectHandler.wrapStringGetter(InfuseRegistry::get, true))
.completerOfNames(InfuseRegistry.getInfuseMap()::keySet)
.register();
}

@Optional.Method(modid = "mekanism")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.cleanroommc.groovyscript.api.IGameObjectHandler;
import com.cleanroommc.groovyscript.api.Result;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlers;
import epicsquid.roots.api.Herb;
import epicsquid.roots.init.HerbRegistry;
Expand All @@ -12,6 +12,7 @@
import epicsquid.roots.modifiers.ModifierRegistry;
import epicsquid.roots.ritual.RitualBase;
import epicsquid.roots.ritual.RitualRegistry;
import epicsquid.roots.spell.FakeSpell;
import epicsquid.roots.spell.SpellBase;
import epicsquid.roots.spell.SpellRegistry;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -63,11 +64,32 @@ public Roots() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("roots", "ritual", RitualBase.class, IGameObjectHandler.wrapStringGetter(RitualRegistry::getRitual));
GameObjectHandlerManager.registerGameObjectHandler("roots", "herb", Herb.class, IGameObjectHandler.wrapStringGetter(HerbRegistry::getHerbByName));
GameObjectHandlerManager.registerGameObjectHandler("roots", "cost", CostType.class, IGameObjectHandler.wrapEnum(CostType.class, false));
GameObjectHandlerManager.registerGameObjectHandler("roots", "spell", SpellBase.class, Roots::getSpell);
GameObjectHandlerManager.registerGameObjectHandler("roots", "modifier", Modifier.class, Roots::getModifier);
GameObjectHandler.builder("ritual", RitualBase.class)
.mod("roots")
.parser(IGameObjectHandler.wrapStringGetter(RitualRegistry::getRitual))
.completerOfNames(RitualRegistry.ritualRegistry::keySet)
.register();
GameObjectHandler.builder("herb", Herb.class)
.mod("roots")
.parser(IGameObjectHandler.wrapStringGetter(HerbRegistry::getHerbByName))
.completerOfNames(HerbRegistry.registry::keySet)
.register();
GameObjectHandler.builder("cost", CostType.class)
.mod("roots")
.parser(IGameObjectHandler.wrapEnum(CostType.class, false))
.completerOfEnum(CostType.class, false)
.register();
GameObjectHandler.builder("spell", SpellBase.class)
.mod("roots")
.parser(Roots::getSpell)
.completer(SpellRegistry.spellRegistry::keySet)
.defaultValue(() -> FakeSpell.INSTANCE)
.register();
GameObjectHandler.builder("modifier", Modifier.class)
.mod("roots")
.parser(Roots::getModifier)
.completerOfNamed(ModifierRegistry::getModifiers, v -> v.getRegistryName().toString())
.register();
}

private static Result<SpellBase> getSpell(String s, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.cleanroommc.groovyscript.compat.mods.thaumcraft.aspect.AspectStack;
import com.cleanroommc.groovyscript.compat.mods.thaumcraft.warp.Warp;
import com.cleanroommc.groovyscript.compat.mods.thaumcraft.warp.WarpItemStackExpansion;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import com.cleanroommc.groovyscript.sandbox.expand.ExpansionHelper;
import net.minecraft.item.ItemStack;
import thaumcraft.api.ThaumcraftApiHelper;
Expand Down Expand Up @@ -47,10 +47,17 @@ public Thaumcraft() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("thaumcraft", "aspect", AspectStack.class,
IGameObjectHandler.wrapStringGetter(Thaumcraft::getAspect, AspectStack::new));
GameObjectHandlerManager.registerGameObjectHandler("thaumcraft", "crystal",
ItemStack.class, IGameObjectHandler.wrapStringGetter(Thaumcraft::getAspect, ThaumcraftApiHelper::makeCrystal));
GameObjectHandler.builder("aspect", AspectStack.class)
.mod("thaumcraft")
.parser(IGameObjectHandler.wrapStringGetter(Thaumcraft::getAspect, AspectStack::new))
.completerOfNames(thaumcraft.api.aspects.Aspect.aspects::keySet)
.register();
GameObjectHandler.builder("crystal", ItemStack.class)
.mod("thaumcraft")
.parser(IGameObjectHandler.wrapStringGetter(Thaumcraft::getAspect, ThaumcraftApiHelper::makeCrystal))
.completerOfNames(thaumcraft.api.aspects.Aspect.aspects::keySet)
.defaultValue(() -> ItemStack.EMPTY)
.register();
ExpansionHelper.mixinClass(ItemStack.class, AspectItemStackExpansion.class);
ExpansionHelper.mixinClass(ItemStack.class, WarpItemStackExpansion.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.material.ToolMaterialBuilder;
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.material.traits.TraitRegistryEvent;
import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandler;
import net.minecraftforge.common.MinecraftForge;
import slimeknights.tconstruct.library.materials.Material;
import slimeknights.tconstruct.library.traits.ITrait;
Expand All @@ -33,12 +33,22 @@ public TinkersConstruct() {

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("tconstruct", "toolMaterial", Material.class,
IGameObjectHandler.wrapStringGetter(TinkerRegistryAccessor.getMaterials()::get));
GameObjectHandlerManager.registerGameObjectHandler("tconstruct", "toolTrait", ITrait.class,
IGameObjectHandler.wrapStringGetter(TinkerRegistryAccessor.getTraits()::get));
GameObjectHandlerManager.registerGameObjectHandler("tconstruct", "armorTrait", ITrait.class,
IGameObjectHandler.wrapStringGetter(s -> TinkerRegistryAccessor.getTraits().get(s + "_armor")));
GameObjectHandler.builder("toolMaterial", Material.class)
.mod("tconstruct")
.parser(IGameObjectHandler.wrapStringGetter(TinkerRegistryAccessor.getMaterials()::get))
.completerOfNames(TinkerRegistryAccessor.getMaterials()::keySet)
.register();
GameObjectHandler.builder("toolTrait", ITrait.class)
.mod("tconstruct")
.parser(IGameObjectHandler.wrapStringGetter(TinkerRegistryAccessor.getTraits()::get))
.completerOfNamed(TinkerRegistryAccessor.getTraits()::keySet, v -> v.endsWith("_armor") ? null : v) // only suggest non armor traits
.register();
GameObjectHandler.builder("armorTrait", ITrait.class)
.mod("tconstruct")
.parser(IGameObjectHandler.wrapStringGetter(s -> TinkerRegistryAccessor.getTraits().get(s + "_armor")))
.completerOfNamed(TinkerRegistryAccessor.getTraits()::keySet, v -> v.endsWith("_armor") ? v.substring(0, v.length() - 6)
: null) // only suggest armor traits
.register();
}

public static void init() {
Expand Down
Loading

0 comments on commit b0b3ebc

Please sign in to comment.