mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
feat(client): 添加 Fabric 客户端模组
This commit is contained in:
90
client-mod/build.gradle
Normal file
90
client-mod/build.gradle
Normal file
@@ -0,0 +1,90 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.10-SNAPSHOT'
|
||||
id 'com.gradleup.shadow' version '9.0.0-beta11'
|
||||
}
|
||||
|
||||
version = project.project_version
|
||||
group = project.project_group
|
||||
|
||||
base {
|
||||
archivesName = "craft-engine-fabric-mod"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
client {
|
||||
compileClasspath += main.compileClasspath
|
||||
runtimeClasspath += main.runtimeClasspath
|
||||
}
|
||||
main {
|
||||
output.dir(client.output)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.yaml', 'net.momirealms.craftengine.libraries.org.yaml')
|
||||
configurations = [project.configurations.shadow]
|
||||
archiveFileName = "${base.archivesName.get()}-${project.version}-shadow.jar"
|
||||
from sourceSets.main.output
|
||||
from sourceSets.client.output
|
||||
}
|
||||
|
||||
remapJar {
|
||||
dependsOn shadowJar
|
||||
inputFile = shadowJar.archiveFile
|
||||
|
||||
destinationDirectory = file("$rootDir/target")
|
||||
archiveFileName = "${base.archivesName.get()}-${project.version}.jar"
|
||||
}
|
||||
|
||||
loom {
|
||||
mods {
|
||||
"craft-engine-fabric-mod" {
|
||||
sourceSet sourceSets.main
|
||||
sourceSet sourceSets.client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
shadow
|
||||
implementation.extendsFrom(shadow)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.latest_minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
shadow 'org.yaml:snakeyaml:2.4'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
inputs.property "minecraft_version", project.latest_minecraft_version
|
||||
inputs.property "loader_version", project.loader_version
|
||||
filteringCharset "UTF-8"
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version,
|
||||
"minecraft_version": project.latest_minecraft_version,
|
||||
"loader_version": project.loader_version
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 21
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
it.options.release.set(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks.build.dependsOn
|
||||
@@ -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
@@ -47,7 +47,12 @@ mojang_brigadier_version=1.0.18
|
||||
byte_buddy_version=1.15.11
|
||||
snake_yaml_version=2.3
|
||||
anti_grief_version=0.13
|
||||
# Fabric Dependencies
|
||||
fabric_version=0.119.2+1.21.4
|
||||
yarn_mappings=1.21.4+build.8
|
||||
loader_version=0.16.10
|
||||
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
# Proxy settings
|
||||
#systemProp.socks.proxyHost=127.0.0.1
|
||||
#systemProp.socks.proxyPort=7890
|
||||
|
||||
@@ -6,6 +6,7 @@ include(":bukkit:legacy")
|
||||
include(":bukkit:compatibility")
|
||||
include(":bukkit-loader")
|
||||
include(":server-mod")
|
||||
include(":client-mod")
|
||||
pluginManagement {
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.20"
|
||||
@@ -13,6 +14,6 @@ pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://maven.fabricmc.net/")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user