Skip to content

Commit 723efb2

Browse files
authored
Material Info Parser and doc fixes (#346)
* fix compostor lang key * sort skipped classes before logging * fix crafting methods missing lang key * add info parser for blockMaterial * add toGroovyCode for blockMaterial * non-reflection blockMaterial map * block the material
1 parent 9da7d46 commit 723efb2

File tree

8 files changed

+88
-24
lines changed

8 files changed

+88
-24
lines changed

src/main/java/com/cleanroommc/groovyscript/compat/vanilla/Crafting.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
@Admonition(type = Admonition.Type.NOTE, value = "groovyscript.wiki.minecraft.crafting.note1"),
2222
@Admonition(type = Admonition.Type.TIP, value = "groovyscript.wiki.minecraft.crafting.note2"),
2323
}, override = @MethodOverride(method = {
24-
@MethodDescription(method = "remove(Lnet/minecraft/util/ResourceLocation;)V", example = @Example("resource('minecraft:stonebrick')")),
25-
@MethodDescription(method = "remove(Ljava/lang/String;)V", example = @Example("'minecraft:mossy_stonebrick'")),
24+
@MethodDescription(method = "remove(Lnet/minecraft/util/ResourceLocation;)V", example = @Example("resource('minecraft:stonebrick')"), description = "groovyscript.wiki.forgewrapper.removeResource"),
25+
@MethodDescription(method = "remove(Ljava/lang/String;)V", example = @Example("'minecraft:mossy_stonebrick'"), description = "groovyscript.wiki.forgewrapper.removeString"),
2626
}))
2727
public class Crafting extends ForgeRegistryWrapper<IRecipe> {
2828

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.cleanroommc.groovyscript.compat.vanilla.command.infoparser;
2+
3+
import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage;
4+
import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter;
5+
import net.minecraft.block.material.Material;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public class InfoParserBlockMaterial extends GenericInfoParser<Material> {
9+
10+
public static final InfoParserBlockMaterial instance = new InfoParserBlockMaterial();
11+
12+
@Override
13+
public String id() {
14+
return "blockmaterial";
15+
}
16+
17+
@Override
18+
public String name() {
19+
return "Block Material";
20+
}
21+
22+
@Override
23+
public String text(@NotNull Material entry, boolean colored, boolean prettyNbt) {
24+
return GroovyScriptCodeConverter.asGroovyCode(entry, colored);
25+
}
26+
27+
@Override
28+
public void parse(InfoParserPackage info) {
29+
if (info.getBlockState() == null) return;
30+
instance.add(info.getMessages(), info.getBlockState().getMaterial(), info.isPrettyNbt());
31+
}
32+
}

src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/StandardInfoParserRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void init() {
99
InfoParserRegistry.addInfoParser(InfoParserFluid.instance);
1010
InfoParserRegistry.addInfoParser(InfoParserBlock.instance);
1111
InfoParserRegistry.addInfoParser(InfoParserBlockState.instance);
12+
InfoParserRegistry.addInfoParser(InfoParserBlockMaterial.instance);
1213
InfoParserRegistry.addInfoParser(InfoParserOreDict.instance);
1314
InfoParserRegistry.addInfoParser(InfoParserNBT.instance);
1415
InfoParserRegistry.addInfoParser(InfoParserEntity.instance);

src/main/java/com/cleanroommc/groovyscript/documentation/Exporter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ public static void generateExamples(String target, GroovyContainer<? extends Gro
163163
public static void logSkippedClasses() {
164164
if (SKIPPED_CLASSES.isEmpty()) return;
165165
GroovyLog.Msg log = GroovyLog.msg("Skipped documenting the following potentially valid locations (this may be the correct behavior!)");
166-
SKIPPED_CLASSES.forEach((key, value) -> log.add(key + ": " + value.getName()));
166+
SKIPPED_CLASSES.entrySet().stream()
167+
.sorted(Map.Entry.comparingByKey(String.CASE_INSENSITIVE_ORDER))
168+
.forEach(entry -> log.add(entry.getKey() + ": " + entry.getValue().getName()));
167169
log.debug().post();
168170
SKIPPED_CLASSES.clear();
169171
}

src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.cleanroommc.groovyscript.core.mixin.CreativeTabsAccessor;
44
import com.cleanroommc.groovyscript.helper.StyleConstant;
5+
import com.cleanroommc.groovyscript.mapper.ObjectParserHelper;
56
import com.google.common.collect.Lists;
67
import net.minecraft.block.Block;
8+
import net.minecraft.block.material.Material;
79
import net.minecraft.block.properties.IProperty;
810
import net.minecraft.block.state.IBlockState;
911
import net.minecraft.creativetab.CreativeTabs;
@@ -209,6 +211,10 @@ public static String asGroovyCode(Block state, boolean colored) {
209211
return formatResourceLocation("block", state.getRegistryName(), colored);
210212
}
211213

214+
public static String asGroovyCode(Material material, boolean colored) {
215+
return formatGenericHandler("blockMaterial", ObjectParserHelper.materials.inverse().get(material), colored);
216+
}
217+
212218
@SuppressWarnings("all")
213219
public static String asGroovyCode(IBlockState state, boolean colored) {
214220
StringBuilder builder = new StringBuilder();

src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapperManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public static void init() {
132132
.parser(IObjectParser.wrapStringGetter(ObjectParserHelper.materials::get))
133133
.completerOfNames(ObjectParserHelper.materials::keySet)
134134
.docOfType("block material")
135+
.toGroovyCode(x -> GroovyScriptCodeConverter.asGroovyCode(x, false))
135136
.register();
136137
/*ObjectMapper.builder("blockstate", IBlockState.class)
137138
.parser(ObjectMappers::parseBlockState)
Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,55 @@
11
package com.cleanroommc.groovyscript.mapper;
22

3-
import com.google.common.collect.ImmutableMap;
3+
import com.google.common.collect.BiMap;
4+
import com.google.common.collect.ImmutableBiMap;
45
import net.minecraft.block.material.Material;
56

6-
import java.lang.reflect.Modifier;
7-
import java.util.Locale;
8-
import java.util.Map;
9-
107
public class ObjectParserHelper {
118

12-
public static Map<String, Material> materials;
9+
public static BiMap<String, Material> materials;
1310

1411
public static void init() {
1512
materials = getMaterials();
1613
}
1714

18-
private static ImmutableMap<String, Material> getMaterials() {
19-
ImmutableMap.Builder<String, Material> materialBuilder = new ImmutableMap.Builder<>();
20-
for (var field : Material.class.getFields()) {
21-
if (Modifier.isStatic(field.getModifiers()) && field.getType() == Material.class) {
22-
try {
23-
var material = (Material) field.get(null);
24-
materialBuilder.put(field.getName(), material);
25-
materialBuilder.put(field.getName().toLowerCase(Locale.ROOT), material);
26-
} catch (IllegalAccessException e) {
27-
throw new RuntimeException(e);
28-
}
29-
}
30-
}
31-
return materialBuilder.build();
15+
private static BiMap<String, Material> getMaterials() {
16+
return new ImmutableBiMap.Builder<String, Material>()
17+
.put("air", Material.AIR)
18+
.put("grass", Material.GRASS)
19+
.put("ground", Material.GROUND)
20+
.put("wood", Material.WOOD)
21+
.put("rock", Material.ROCK)
22+
.put("iron", Material.IRON)
23+
.put("anvil", Material.ANVIL)
24+
.put("water", Material.WATER)
25+
.put("lava", Material.LAVA)
26+
.put("leaves", Material.LEAVES)
27+
.put("plants", Material.PLANTS)
28+
.put("vine", Material.VINE)
29+
.put("sponge", Material.SPONGE)
30+
.put("cloth", Material.CLOTH)
31+
.put("fire", Material.FIRE)
32+
.put("sand", Material.SAND)
33+
.put("circuits", Material.CIRCUITS)
34+
.put("carpet", Material.CARPET)
35+
.put("glass", Material.GLASS)
36+
.put("redstone_light", Material.REDSTONE_LIGHT)
37+
.put("tnt", Material.TNT)
38+
.put("coral", Material.CORAL)
39+
.put("ice", Material.ICE)
40+
.put("packed_ice", Material.PACKED_ICE)
41+
.put("snow", Material.SNOW)
42+
.put("crafted_snow", Material.CRAFTED_SNOW)
43+
.put("cactus", Material.CACTUS)
44+
.put("clay", Material.CLAY)
45+
.put("gourd", Material.GOURD)
46+
.put("dragon_egg", Material.DRAGON_EGG)
47+
.put("portal", Material.PORTAL)
48+
.put("cake", Material.CAKE)
49+
.put("web", Material.WEB)
50+
.put("piston", Material.PISTON)
51+
.put("barrier", Material.BARRIER)
52+
.put("structure_void", Material.STRUCTURE_VOID)
53+
.build();
3254
}
3355
}

src/main/resources/assets/groovyscript/lang/en_us.lang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ groovyscript.wiki.futuremc.composter.title=Composter
15691569
groovyscript.wiki.futuremc.composter.description=Converts input items into a chance to get a layer of compost, with 8 layers providing a single bonemeal
15701570
groovyscript.wiki.futuremc.composter.add=Adds entries in the format `ingredient`, `chance`
15711571
groovyscript.wiki.futuremc.composter.remove=Removes an entry with the same Ingredient
1572-
groovyscript.wiki.futuremc.composter.rarity.value=Sets the chance the recipe has to provide a layer of compost
1572+
groovyscript.wiki.futuremc.composter.chance.value=Sets the chance the recipe has to provide a layer of compost
15731573

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

0 commit comments

Comments
 (0)