mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 03:49:15 +00:00
feat(client): 添加 Fabric 客户端模组
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package net.momirealms.craftEngineFabricMod.client;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class CraftEngineFabricModClient implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.momirealms.craftEngineFabricMod;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.momirealms.craftEngineFabricMod.util.RegisterBlocks;
|
||||
import net.momirealms.craftEngineFabricMod.util.YamlUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CraftEngineFabricMod implements ModInitializer {
|
||||
public static final String MOD_ID = "craftengine";
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Map<String, String> mappings = YamlUtils.loadConfig();
|
||||
Map<String, Integer> blockCount = new HashMap<>();
|
||||
mappings.keySet().forEach(name -> {
|
||||
String blockName = YamlUtils.split(name);
|
||||
if (blockName != null) {
|
||||
if (blockCount.containsKey(blockName)) {
|
||||
blockCount.put(blockName, blockCount.get(blockName) + 1);
|
||||
} else {
|
||||
blockCount.put(blockName, 0);
|
||||
}
|
||||
RegisterBlocks.register(blockName + "_" + blockCount.get(blockName));
|
||||
}
|
||||
});
|
||||
mappings.clear();
|
||||
blockCount.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.momirealms.craftEngineFabricMod.util;
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.momirealms.craftEngineFabricMod.CraftEngineFabricMod;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class RegisterBlocks {
|
||||
public static Block register(String name) {
|
||||
return register(name, Block::new, Block.Settings.copy(Blocks.STONE));
|
||||
}
|
||||
|
||||
public static Block register(String name, Function<AbstractBlock.Settings, Block> blockFactory, AbstractBlock.Settings settings) {
|
||||
RegistryKey<Block> blockKey = keyOfBlock(name);
|
||||
Block block = blockFactory.apply(settings.registryKey(blockKey));
|
||||
|
||||
return Registry.register(Registries.BLOCK, blockKey, block);
|
||||
}
|
||||
|
||||
public static RegistryKey<Block> keyOfBlock(String name) {
|
||||
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(CraftEngineFabricMod.MOD_ID, name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.momirealms.craftEngineFabricMod.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
public class YamlUtils {
|
||||
|
||||
public static Map<String, String> loadConfig() {
|
||||
Yaml yaml = new Yaml();
|
||||
InputStream inputStream = YamlUtils.class.getClassLoader()
|
||||
.getResourceAsStream("mappings.yml");
|
||||
return yaml.load(inputStream);
|
||||
}
|
||||
|
||||
public static @Nullable String split(String str) {
|
||||
int colonIndex = str.indexOf(':');
|
||||
int bracketIndex = str.indexOf('[');
|
||||
if (colonIndex == -1 && bracketIndex == -1) return null;
|
||||
int start = (colonIndex != -1) ? colonIndex + 1 : 0;
|
||||
int end = (bracketIndex != -1) ? bracketIndex : str.length();
|
||||
if (start > end) start = end;
|
||||
return str.substring(start, end);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
25
client-mod/src/main/resources/fabric.mod.json
Normal file
25
client-mod/src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "craft-engine-fabric-mod",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "craft-engine-fabric-mod",
|
||||
"description": "",
|
||||
"authors": [],
|
||||
"contact": {},
|
||||
|
||||
"license": "GPL-3.0",
|
||||
"icon": "assets/craft-engine-fabric-mod/icon.png",
|
||||
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"client": ["net.momirealms.craftEngineFabricMod.client.CraftEngineFabricModClient"],
|
||||
"main": ["net.momirealms.craftEngineFabricMod.CraftEngineFabricMod"]
|
||||
},
|
||||
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric": "*",
|
||||
"minecraft": "${minecraft_version}"
|
||||
}
|
||||
}
|
||||
2029
client-mod/src/main/resources/mappings.yml
Normal file
2029
client-mod/src/main/resources/mappings.yml
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user