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

More defaultValues for Object Mappers #249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void initialize(GroovyContainer<?> container) {
container.objectMapperBuilder("tunnel", TunnelType.class)
.parser(IObjectParser.wrapEnum(TunnelType.class, false))
.completerOfNamed(() -> Arrays.asList(TunnelType.values()), v -> v.name().toUpperCase(Locale.ROOT))
.defaultValue(() -> TunnelType.ME)
.docOfType("P2P tunnel type")
.register();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.cleanroommc.groovyscript.compat.mods.thermalexpansion;

import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import cofh.thermalexpansion.util.managers.machine.CompactorManager;
import com.cleanroommc.groovyscript.api.IObjectParser;
import com.cleanroommc.groovyscript.compat.mods.GroovyContainer;
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.compat.mods.thermalexpansion.device.*;
import com.cleanroommc.groovyscript.compat.mods.thermalexpansion.dynamo.*;
import com.cleanroommc.groovyscript.compat.mods.thermalexpansion.machine.*;
import com.cleanroommc.groovyscript.mapper.ObjectMapper;

import java.util.Arrays;
import java.util.Locale;
Expand Down Expand Up @@ -51,11 +50,11 @@ public class ThermalExpansion extends GroovyPropertyContainer {
public final XpCollector xpCollector = new XpCollector();

@Override
public void initialize(GroovyContainer<?> owner) {
ObjectMapper.builder("compactorMode", CompactorManager.Mode.class)
.mod("thermalexpansion")
public void initialize(GroovyContainer<?> container) {
container.objectMapperBuilder("compactorMode", CompactorManager.Mode.class)
.parser(IObjectParser.wrapEnum(CompactorManager.Mode.class, false))
.completerOfNamed(() -> Arrays.asList(CompactorManager.Mode.values()), v -> v.name().toUpperCase(Locale.ROOT))
.defaultValue(() -> CompactorManager.Mode.ALL)
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
Expand Down Expand Up @@ -105,6 +106,7 @@ public static void init() {
ObjectMapper.builder("block", Block.class)
.parser(IObjectParser.wrapForgeRegistry(ForgeRegistries.BLOCKS))
.completer(ForgeRegistries.BLOCKS)
.defaultValue(() -> Blocks.AIR)
.docOfType("block")
.register();
ObjectMapper.builder("blockstate", IBlockState.class)
Expand All @@ -113,6 +115,7 @@ public static void init() {
.addSignature(String.class, int.class)
.addSignature(String.class, String[].class)
.completer(ForgeRegistries.BLOCKS)
.defaultValue(() -> Blocks.AIR.getBlockState().getBaseState())
.docOfType("block state")
.register();
ObjectMapper.builder("enchantment", Enchantment.class)
Expand Down Expand Up @@ -174,15 +177,18 @@ public static void init() {
ObjectMapper.builder("creativeTab", CreativeTabs.class)
.parser(ObjectMappers::parseCreativeTab)
.completerOfNamed(() -> Arrays.asList(CreativeTabs.CREATIVE_TAB_ARRAY), v -> ((CreativeTabsAccessor) v).getTabLabel2())
.defaultValue(() -> CreativeTabs.SEARCH)
.docOfType("creative tab")
.register();
ObjectMapper.builder("textformat", TextFormatting.class)
.parser(ObjectMappers::parseTextFormatting)
.completerOfNamed(() -> Arrays.asList(TextFormatting.values()), format -> format.name().toLowerCase(Locale.ROOT).replaceAll("[^a-z]", ""))
.defaultValue(() -> TextFormatting.RESET)
.docOfType("text format")
.register();
ObjectMapper.builder("nbt", NBTTagCompound.class)
.parser(ObjectMappers::parseNBT)
.defaultValue(NBTTagCompound::new)
.docOfType("nbt tag")
.register();
}
Expand Down