Skip to content
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 @@ -21,8 +21,8 @@
@Admonition(type = Admonition.Type.NOTE, value = "groovyscript.wiki.minecraft.crafting.note1"),
@Admonition(type = Admonition.Type.TIP, value = "groovyscript.wiki.minecraft.crafting.note2"),
}, override = @MethodOverride(method = {
@MethodDescription(method = "remove(Lnet/minecraft/util/ResourceLocation;)V", example = @Example("resource('minecraft:stonebrick')")),
@MethodDescription(method = "remove(Ljava/lang/String;)V", example = @Example("'minecraft:mossy_stonebrick'")),
@MethodDescription(method = "remove(Lnet/minecraft/util/ResourceLocation;)V", example = @Example("resource('minecraft:stonebrick')"), description = "groovyscript.wiki.forgewrapper.removeResource"),
@MethodDescription(method = "remove(Ljava/lang/String;)V", example = @Example("'minecraft:mossy_stonebrick'"), description = "groovyscript.wiki.forgewrapper.removeString"),
}))
public class Crafting extends ForgeRegistryWrapper<IRecipe> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cleanroommc.groovyscript.compat.vanilla.command.infoparser;

import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage;
import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter;
import net.minecraft.block.material.Material;
import org.jetbrains.annotations.NotNull;

public class InfoParserBlockMaterial extends GenericInfoParser<Material> {

public static final InfoParserBlockMaterial instance = new InfoParserBlockMaterial();

@Override
public String id() {
return "blockmaterial";
}

@Override
public String name() {
return "Block Material";
}

@Override
public String text(@NotNull Material entry, boolean colored, boolean prettyNbt) {
return GroovyScriptCodeConverter.asGroovyCode(entry, colored);
}

@Override
public void parse(InfoParserPackage info) {
if (info.getBlockState() == null) return;
instance.add(info.getMessages(), info.getBlockState().getMaterial(), info.isPrettyNbt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static void init() {
InfoParserRegistry.addInfoParser(InfoParserFluid.instance);
InfoParserRegistry.addInfoParser(InfoParserBlock.instance);
InfoParserRegistry.addInfoParser(InfoParserBlockState.instance);
InfoParserRegistry.addInfoParser(InfoParserBlockMaterial.instance);
InfoParserRegistry.addInfoParser(InfoParserOreDict.instance);
InfoParserRegistry.addInfoParser(InfoParserNBT.instance);
InfoParserRegistry.addInfoParser(InfoParserEntity.instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ public static void generateExamples(String target, GroovyContainer<? extends Gro
public static void logSkippedClasses() {
if (SKIPPED_CLASSES.isEmpty()) return;
GroovyLog.Msg log = GroovyLog.msg("Skipped documenting the following potentially valid locations (this may be the correct behavior!)");
SKIPPED_CLASSES.forEach((key, value) -> log.add(key + ": " + value.getName()));
SKIPPED_CLASSES.entrySet().stream()
.sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER))
.forEach(entry -> log.add(entry.getKey() + ": " + entry.getValue().getName()));
log.debug().post();
SKIPPED_CLASSES.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.cleanroommc.groovyscript.core.mixin.CreativeTabsAccessor;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import com.cleanroommc.groovyscript.mapper.ObjectParserHelper;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
Expand Down Expand Up @@ -209,6 +211,10 @@ public static String asGroovyCode(Block state, boolean colored) {
return formatResourceLocation("block", state.getRegistryName(), colored);
}

public static String asGroovyCode(Material material, boolean colored) {
return formatGenericHandler("blockMaterial", ObjectParserHelper.materials.inverse().get(material), colored);
}

@SuppressWarnings("all")
public static String asGroovyCode(IBlockState state, boolean colored) {
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static void init() {
.parser(IObjectParser.wrapStringGetter(ObjectParserHelper.materials::get))
.completerOfNames(ObjectParserHelper.materials::keySet)
.docOfType("block material")
.toGroovyCode(x -> GroovyScriptCodeConverter.asGroovyCode(x, false))
.register();
/*ObjectMapper.builder("blockstate", IBlockState.class)
.parser(ObjectMappers::parseBlockState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
package com.cleanroommc.groovyscript.mapper;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import net.minecraft.block.material.Material;

import java.lang.reflect.Modifier;
import java.util.Locale;
import java.util.Map;

public class ObjectParserHelper {

public static Map<String, Material> materials;
public static BiMap<String, Material> materials;

public static void init() {
materials = getMaterials();
}

private static ImmutableMap<String, Material> getMaterials() {
ImmutableMap.Builder<String, Material> materialBuilder = new ImmutableMap.Builder<>();
for (var field : Material.class.getFields()) {
if (Modifier.isStatic(field.getModifiers()) && field.getType() == Material.class) {
try {
var material = (Material) field.get(null);
materialBuilder.put(field.getName(), material);
materialBuilder.put(field.getName().toLowerCase(Locale.ROOT), material);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
return materialBuilder.build();
private static BiMap<String, Material> getMaterials() {
return new ImmutableBiMap.Builder<String, Material>()
.put("air", Material.AIR)
.put("grass", Material.GRASS)
.put("ground", Material.GROUND)
.put("wood", Material.WOOD)
.put("rock", Material.ROCK)
.put("iron", Material.IRON)
.put("anvil", Material.ANVIL)
.put("water", Material.WATER)
.put("lava", Material.LAVA)
.put("leaves", Material.LEAVES)
.put("plants", Material.PLANTS)
.put("vine", Material.VINE)
.put("sponge", Material.SPONGE)
.put("cloth", Material.CLOTH)
.put("fire", Material.FIRE)
.put("sand", Material.SAND)
.put("circuits", Material.CIRCUITS)
.put("carpet", Material.CARPET)
.put("glass", Material.GLASS)
.put("redstone_light", Material.REDSTONE_LIGHT)
.put("tnt", Material.TNT)
.put("coral", Material.CORAL)
.put("ice", Material.ICE)
.put("packed_ice", Material.PACKED_ICE)
.put("snow", Material.SNOW)
.put("crafted_snow", Material.CRAFTED_SNOW)
.put("cactus", Material.CACTUS)
.put("clay", Material.CLAY)
.put("gourd", Material.GOURD)
.put("dragon_egg", Material.DRAGON_EGG)
.put("portal", Material.PORTAL)
.put("cake", Material.CAKE)
.put("web", Material.WEB)
.put("piston", Material.PISTON)
.put("barrier", Material.BARRIER)
.put("structure_void", Material.STRUCTURE_VOID)
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/groovyscript/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ groovyscript.wiki.futuremc.composter.title=Composter
groovyscript.wiki.futuremc.composter.description=Converts input items into a chance to get a layer of compost, with 8 layers providing a single bonemeal
groovyscript.wiki.futuremc.composter.add=Adds entries in the format `ingredient`, `chance`
groovyscript.wiki.futuremc.composter.remove=Removes an entry with the same Ingredient
groovyscript.wiki.futuremc.composter.rarity.value=Sets the chance the recipe has to provide a layer of compost
groovyscript.wiki.futuremc.composter.chance.value=Sets the chance the recipe has to provide a layer of compost

groovyscript.wiki.futuremc.smithing.title=Smithing
groovyscript.wiki.futuremc.smithing.description=Converts two input itemstacks into an output output itemstack in the Smithing Table.
Expand Down