-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
670 additions
and
8 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
Allay-API/src/main/java/org/allaymc/api/block/tag/BlockTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.allaymc.api.block.tag; | ||
|
||
/** | ||
* Allay Project 2024/6/11 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public record BlockTag(String name) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Allay-API/src/main/java/org/allaymc/api/data/VanillaBlockTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.allaymc.api.data; | ||
|
||
import java.lang.String; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.allaymc.api.block.tag.BlockTag; | ||
|
||
/** | ||
* Automatically generated by {@code org.allaymc.codegen.VanillaBlockTagGen} <br> | ||
* Allay Project <p> | ||
* @author daoge_cmd | ||
*/ | ||
public interface VanillaBlockTags { | ||
Map<String, BlockTag> NAME_TO_TAG = new HashMap<>(); | ||
|
||
BlockTag CROP = create("minecraft:crop"); | ||
|
||
BlockTag LOG = create("log"); | ||
|
||
BlockTag STONE_PICK_DIGGABLE = create("stone_pick_diggable"); | ||
|
||
BlockTag GRASS = create("grass"); | ||
|
||
BlockTag OAK = create("oak"); | ||
|
||
BlockTag WOOD = create("wood"); | ||
|
||
BlockTag DARK_OAK = create("dark_oak"); | ||
|
||
BlockTag FERTILIZE_AREA = create("fertilize_area"); | ||
|
||
BlockTag SPRUCE = create("spruce"); | ||
|
||
BlockTag GOLD_PICK_DIGGABLE = create("gold_pick_diggable"); | ||
|
||
BlockTag TRAPDOORS = create("trapdoors"); | ||
|
||
BlockTag IRON_PICK_DIGGABLE = create("iron_pick_diggable"); | ||
|
||
BlockTag BIRCH = create("birch"); | ||
|
||
BlockTag RAIL = create("rail"); | ||
|
||
BlockTag DIRT = create("dirt"); | ||
|
||
BlockTag METAL = create("metal"); | ||
|
||
BlockTag TEXT_SIGN = create("text_sign"); | ||
|
||
BlockTag WATER = create("water"); | ||
|
||
BlockTag DIAMOND_PICK_DIGGABLE = create("diamond_pick_diggable"); | ||
|
||
BlockTag STONE = create("stone"); | ||
|
||
BlockTag GRAVEL = create("gravel"); | ||
|
||
BlockTag SAND = create("sand"); | ||
|
||
BlockTag SNOW = create("snow"); | ||
|
||
BlockTag PLANT = create("plant"); | ||
|
||
BlockTag WOOD_PICK_DIGGABLE = create("wood_pick_diggable"); | ||
|
||
BlockTag ACACIA = create("acacia"); | ||
|
||
BlockTag NOT_FEATURE_REPLACEABLE = create("not_feature_replaceable"); | ||
|
||
BlockTag JUNGLE = create("jungle"); | ||
|
||
BlockTag MOB_SPAWNER = create("mob_spawner"); | ||
|
||
BlockTag PUMPKIN = create("pumpkin"); | ||
|
||
static BlockTag create(String name) { | ||
var tag = new BlockTag(name); | ||
NAME_TO_TAG.put(name, tag); | ||
return tag; | ||
} | ||
|
||
static BlockTag getTagByName(String name) { | ||
return NAME_TO_TAG.get(name); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Allay-CodeGen/src/main/java/org/allaymc/codegen/VanillaBlockTagGen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.allaymc.codegen; | ||
|
||
import com.google.gson.JsonParser; | ||
import com.squareup.javapoet.*; | ||
import lombok.SneakyThrows; | ||
import org.allaymc.dependence.StringUtils; | ||
|
||
import javax.lang.model.element.Modifier; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Allay Project 2023/11/18 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class VanillaBlockTagGen { | ||
static final Path BLOCK_TAGS_FILE_PATH = Path.of(CodeGen.DATA_PATH + "block_tags.json"); | ||
static final ClassName BLOCK_TAG_CLASS = ClassName.get("org.allaymc.api.block.tag", "BlockTag"); | ||
static final Set<String> KEYS = new HashSet<>(); | ||
static final String JAVA_DOC = """ | ||
Automatically generated by {@code org.allaymc.codegen.VanillaBlockTagGen} <br> | ||
Allay Project <p> | ||
@author daoge_cmd | ||
"""; | ||
|
||
static { | ||
try { | ||
JsonParser | ||
.parseReader(Files.newBufferedReader(BLOCK_TAGS_FILE_PATH)) | ||
.getAsJsonObject() | ||
.entrySet() | ||
.forEach(entry -> KEYS.add(entry.getKey())); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
generate(); | ||
} | ||
|
||
@SneakyThrows | ||
public static void generate() { | ||
TypeSpec.Builder codeBuilder = TypeSpec.interfaceBuilder("VanillaBlockTags") | ||
.addJavadoc(JAVA_DOC) | ||
.addModifiers(Modifier.PUBLIC) | ||
.addField( | ||
FieldSpec | ||
.builder(ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(String.class), BLOCK_TAG_CLASS), "NAME_TO_TAG", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) | ||
.initializer("new $T<>()", HashMap.class) | ||
.build() | ||
) | ||
.addMethod( | ||
MethodSpec | ||
.methodBuilder("create") | ||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC) | ||
.returns(BLOCK_TAG_CLASS) | ||
.addParameter(String.class, "name") | ||
.addStatement("var tag = new $T(name)", BLOCK_TAG_CLASS) | ||
.addStatement("NAME_TO_TAG.put(name, tag)") | ||
.addStatement("return tag") | ||
.build() | ||
) | ||
.addMethod( | ||
MethodSpec | ||
.methodBuilder("getTagByName") | ||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC) | ||
.returns(BLOCK_TAG_CLASS) | ||
.addParameter(String.class, "name") | ||
.addStatement("return NAME_TO_TAG.get(name)") | ||
.build() | ||
); | ||
var fieldNames = new HashSet<String>(); | ||
for (var key : KEYS) { | ||
var fieldName = StringUtils.fastTwoPartSplit(key, ":", "")[1].toUpperCase(); | ||
fieldNames.add(fieldName); | ||
codeBuilder.addField( | ||
FieldSpec | ||
.builder(BLOCK_TAG_CLASS, fieldName) | ||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) | ||
.initializer("create($S)", key) | ||
.build() | ||
); | ||
} | ||
|
||
var javaFile = JavaFile.builder("org.allaymc.api.data", codeBuilder.build()).build(); | ||
Files.writeString(Path.of("Allay-API/src/main/java/org/allaymc/api/data/VanillaBlockTags.java"), javaFile.toString()); | ||
} | ||
} |
Oops, something went wrong.