修改第七部分
调整部分代码 TODO 待解决问题: forge使用的common refmap还是使用的yarn而不是srg导致无法mixin在生产环境找到对应的类
This commit is contained in:
parent
c8edb2d74f
commit
ea571e942a
54
build.gradle
54
build.gradle
|
|
@ -1,4 +1,5 @@
|
|||
plugins {
|
||||
id 'base'
|
||||
id 'dev.architectury.loom' version '1.10-SNAPSHOT' apply false
|
||||
id 'architectury-plugin' version '3.4-SNAPSHOT'
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
|
||||
|
|
@ -6,11 +7,33 @@ plugins {
|
|||
|
||||
architectury {
|
||||
minecraft = project.minecraft_version
|
||||
injectInjectables = false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group = rootProject.maven_group
|
||||
version = rootProject.mod_version
|
||||
base.archivesBaseName = project.archives_base_name
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
it.options.release = 17
|
||||
def resourceTargets=["pack.mcmeta","fabric.mod.json",'META-INF/mods.toml',"*.mixins.json"];
|
||||
def replaceProperties = [
|
||||
mod_name: mod_name,
|
||||
mod_version: mod_version,
|
||||
mod_source:mod_source,
|
||||
mod_credits:mod_credits,
|
||||
mod_authors: mod_authors,
|
||||
mod_description: mod_description,
|
||||
mod_licence:mod_licence,
|
||||
group:maven_group]
|
||||
processResources {
|
||||
filesMatching(resourceTargets) {
|
||||
expand replaceProperties
|
||||
}
|
||||
inputs.properties replaceProperties
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
|
@ -20,7 +43,7 @@ subprojects {
|
|||
|
||||
base {
|
||||
// Set up a suffixed format for the mod jar names, e.g. `example-fabric`.
|
||||
archivesName = "$rootProject.archives_name-$project.name"
|
||||
archivesName = "${mod_id}-mc${minecraft_version}"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
@ -29,10 +52,18 @@ subprojects {
|
|||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||
// for more information about repositories.
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://maven.architectury.dev/"
|
||||
}
|
||||
maven { url = 'https://maven.parchmentmc.org' }
|
||||
mavenLocal()
|
||||
}
|
||||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
mixin {
|
||||
defaultRefmapName = "jsonem-common.refmap.json"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
|
||||
|
|
@ -52,27 +83,6 @@ subprojects {
|
|||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.encoding = "UTF-8"
|
||||
it.options.release = 17
|
||||
def resourceTargets=["fabric.mod.json",'META-INF/mods.toml'];
|
||||
def replaceProperties = [
|
||||
mod_name: mod_name,
|
||||
mod_version: mod_version,
|
||||
mod_source:mod_source,
|
||||
mod_credits:mod_credits,
|
||||
mod_authors: mod_authors,
|
||||
mod_description: mod_description,
|
||||
mod_licence:mod_licence,
|
||||
group:maven_group]
|
||||
processResources {
|
||||
inputs.properties replaceProperties
|
||||
filesMatching(resourceTargets) {
|
||||
expand replaceProperties
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure Maven publishing.
|
||||
publishing {
|
||||
publications {
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import org.slf4j.LoggerFactory;
|
|||
public final class JsonEm {
|
||||
public static final String MOD_ID = "jsonem";
|
||||
public static final Logger LOG = LoggerFactory.getLogger(JsonEm.class);
|
||||
public static void init() {
|
||||
// Write common init code here.
|
||||
public static void commonSetUp() {
|
||||
Services.PLATFORM.getReloadListener().registerModelReloadListener();
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public static void registerModelLayer(ModelLayerLocation layer) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.leisuretimedock.jsonem.core;
|
||||
|
||||
import com.leisuretimedock.jsonem.JsonEm;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface IJsonEntityModelReloadListener {
|
||||
ResourceLocation ID = new ResourceLocation(JsonEm.MOD_ID, "json_model_reload");
|
||||
void registerModelReloadListener();
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package com.leisuretimedock.jsonem.mixin;
|
||||
|
||||
import com.leisuretimedock.jsonem.util.JsonEntityModelUtil;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(EntityModelSet.class)
|
||||
public class EntityModelLoaderMixin {
|
||||
@Shadow
|
||||
private Map<ModelLayerLocation, LayerDefinition> roots;
|
||||
|
||||
@Inject(method = "onResourceManagerReload", at = @At("TAIL"))
|
||||
private void jsonem$loadJsonEntityModels(ResourceManager manager, CallbackInfo ci) {
|
||||
this.roots = new HashMap<>(this.roots);
|
||||
JsonEntityModelUtil.loadModels(manager, this.roots);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.leisuretimedock.jsonem.mixin;
|
||||
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(EntityModelSet.class)
|
||||
public interface EntityModelSetAccess {
|
||||
@Accessor("roots")
|
||||
void setRoots(Map<ModelLayerLocation, LayerDefinition> roots);
|
||||
|
||||
@Accessor("roots")
|
||||
Map<ModelLayerLocation, LayerDefinition> getRoots();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.leisuretimedock.jsonem.platform;
|
||||
|
||||
import com.leisuretimedock.jsonem.core.IJsonEntityModelReloadListener;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -8,4 +9,5 @@ public interface IPlatFormHelper {
|
|||
boolean shouldDumpModels();
|
||||
Path getDumpModelsPath();
|
||||
void registerModelLayer(ModelLayerLocation layer);
|
||||
IJsonEntityModelReloadListener getReloadListener();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"DilationAccess",
|
||||
"EntityModelLoaderMixin",
|
||||
"EntityModelSetAccess",
|
||||
"EntityModelsMixin",
|
||||
"ModelCuboidDataAccess",
|
||||
"ModelPartDataAccess",
|
||||
|
|
|
|||
|
|
@ -44,4 +44,7 @@ shadowJar {
|
|||
|
||||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveBaseName.set "${rootProject.archives_base_name}-${project.name}"
|
||||
archiveClassifier.set null
|
||||
}
|
||||
|
|
|
|||
1
fabric/gradle.properties
Normal file
1
fabric/gradle.properties
Normal file
|
|
@ -0,0 +1 @@
|
|||
loom.platform=fabric
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.leisuretimedock.jsonem.fabric;
|
||||
|
||||
import com.leisuretimedock.jsonem.JsonEm;
|
||||
import com.leisuretimedock.jsonem.fabric.config.JsonEmConfig;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ public class JsonEmFabric implements ClientModInitializer {
|
|||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
JsonEm.commonSetUp();
|
||||
CONFIG.load();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.leisuretimedock.jsonem.fabric.core;
|
||||
|
||||
import com.leisuretimedock.jsonem.JsonEm;
|
||||
import com.leisuretimedock.jsonem.core.IJsonEntityModelReloadListener;
|
||||
import com.leisuretimedock.jsonem.mixin.EntityModelSetAccess;
|
||||
import com.leisuretimedock.jsonem.util.JsonEntityModelUtil;
|
||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class JsonEntityModelReloadListenerImp implements IJsonEntityModelReloadListener, IdentifiableResourceReloadListener {
|
||||
@Override
|
||||
public ResourceLocation getFabricId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Void> reload(@NotNull PreparationBarrier preparationBarrier, @NotNull ResourceManager resourceManager, @NotNull ProfilerFiller preparationsProfiler, @NotNull ProfilerFiller reloadProfiler, @NotNull Executor backgroundExecutor, @NotNull Executor gameExecutor) {
|
||||
return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(() -> {
|
||||
reloadProfiler.startTick();
|
||||
reloadProfiler.push("listener");
|
||||
try {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
EntityModelSet modelSet = minecraft.getEntityModels();
|
||||
|
||||
EntityModelSetAccess accessor = (EntityModelSetAccess) modelSet;
|
||||
Map<ModelLayerLocation, LayerDefinition> roots = new HashMap<>(accessor.getRoots());
|
||||
|
||||
JsonEntityModelUtil.loadModels(resourceManager, roots);
|
||||
|
||||
accessor.setRoots(roots);
|
||||
} catch (Exception e) {
|
||||
JsonEm.LOG.error(e.getMessage(), e);
|
||||
}
|
||||
reloadProfiler.pop();
|
||||
reloadProfiler.endTick();
|
||||
}, gameExecutor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModelReloadListener() {
|
||||
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES)
|
||||
.registerReloadListener(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.leisuretimedock.jsonem.fabric.platform;
|
||||
|
||||
import com.leisuretimedock.jsonem.core.IJsonEntityModelReloadListener;
|
||||
import com.leisuretimedock.jsonem.fabric.JsonEmFabric;
|
||||
import com.leisuretimedock.jsonem.fabric.core.JsonEntityModelReloadListenerImp;
|
||||
import com.leisuretimedock.jsonem.platform.IPlatFormHelper;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
|
@ -27,4 +29,9 @@ public class FabricPlatformHelper implements IPlatFormHelper {
|
|||
Objects.requireNonNull(layer);
|
||||
EntityModelLayerRegistry.registerModelLayer(layer, () -> LayerDefinition.create(new MeshDefinition(), 32, 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJsonEntityModelReloadListener getReloadListener() {
|
||||
return new JsonEntityModelReloadListenerImp();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,20 @@ architectury {
|
|||
|
||||
loom {
|
||||
forge {
|
||||
mixinConfig "${mod_id}.mixins.json"
|
||||
mixinConfig "${mod_id}.forge.mixins.json"
|
||||
mixinConfig "${mod_id}-common.mixins.json"
|
||||
mixinConfig "${mod_id}-forge.mixins.json"
|
||||
mixin {
|
||||
defaultRefmapName = "${mod_id}-forge.refmap.json"
|
||||
}
|
||||
}
|
||||
runs {
|
||||
client {
|
||||
ideConfigGenerated = true
|
||||
runDir = "run"
|
||||
|
||||
// 添加对 common 的依赖
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +51,7 @@ dependencies {
|
|||
|
||||
// modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version"
|
||||
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
|
||||
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
|
||||
shadowBundle(project(path: ':common', configuration: 'transformProductionNeoForge')) { transitive = false }
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -51,5 +63,22 @@ shadowJar {
|
|||
remapJar {
|
||||
input.set shadowJar.archiveFile
|
||||
dependsOn shadowJar
|
||||
archiveClassifier = null
|
||||
archiveBaseName.set "${rootProject.archives_base_name}-${project.name}"
|
||||
archiveClassifier.set null
|
||||
}
|
||||
jar {
|
||||
archiveClassifier.set("dev")
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
dependsOn commonSources
|
||||
from commonSources.archiveFile.map { zipTree(it) }
|
||||
}
|
||||
components.java {
|
||||
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|||
public final class JsonEmForge {
|
||||
public JsonEmForge(FMLJavaModLoadingContext context) {
|
||||
context.registerConfig(ModConfig.Type.CLIENT, JsonEmConfig.spec, "jsonem.toml");
|
||||
JsonEm.init();
|
||||
JsonEm.commonSetUp();
|
||||
context.getModEventBus().register(ForgePlatformHelper.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package com.leisuretimedock.jsonem.forge.core;
|
||||
|
||||
import com.leisuretimedock.jsonem.core.IJsonEntityModelReloadListener;
|
||||
import com.leisuretimedock.jsonem.mixin.EntityModelSetAccess;
|
||||
import com.leisuretimedock.jsonem.util.JsonEntityModelUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
||||
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonEntityModelReloadListenerImp implements IJsonEntityModelReloadListener, ResourceManagerReloadListener {
|
||||
|
||||
public static void registerReloadListeners(RegisterClientReloadListenersEvent event) {
|
||||
event.registerReloadListener(new JsonEntityModelReloadListenerImp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModelReloadListener() {
|
||||
MinecraftForge.EVENT_BUS.addListener(JsonEntityModelReloadListenerImp::registerReloadListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
EntityModelSet modelSet = mc.getEntityModels();
|
||||
|
||||
EntityModelSetAccess accessor = (EntityModelSetAccess) modelSet;
|
||||
Map<ModelLayerLocation, LayerDefinition> roots = new HashMap<>(accessor.getRoots());
|
||||
|
||||
// 注入自定义模型
|
||||
JsonEntityModelUtil.loadModels(resourceManager, roots);
|
||||
|
||||
accessor.setRoots(roots);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.leisuretimedock.jsonem.forge.platform;
|
||||
|
||||
import com.leisuretimedock.jsonem.core.IJsonEntityModelReloadListener;
|
||||
import com.leisuretimedock.jsonem.forge.config.JsonEmConfig;
|
||||
import com.leisuretimedock.jsonem.forge.core.JsonEntityModelReloadListenerImp;
|
||||
import com.leisuretimedock.jsonem.forge.mixin.EntityModelLayersAccessor;
|
||||
import com.leisuretimedock.jsonem.platform.IPlatFormHelper;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
|
|
@ -8,6 +10,7 @@ import net.minecraft.client.model.geom.builders.LayerDefinition;
|
|||
import net.minecraft.client.model.geom.builders.MeshDefinition;
|
||||
import net.minecraftforge.client.event.EntityRenderersEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -35,6 +38,12 @@ public class ForgePlatformHelper implements IPlatFormHelper {
|
|||
public void registerModelLayer(ModelLayerLocation layer) {
|
||||
DEFINITIONS.put(layer, () -> LayerDefinition.create(new MeshDefinition(), 32, 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJsonEntityModelReloadListener getReloadListener() {
|
||||
return new JsonEntityModelReloadListenerImp();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
|
||||
for (Map.Entry<ModelLayerLocation, Supplier<LayerDefinition>> modelLayerLocationSupplierEntry : DEFINITIONS.entrySet()) {
|
||||
|
|
@ -43,6 +52,4 @@ public class ForgePlatformHelper implements IPlatFormHelper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ mod_description=Migrate from Fabric 1.20.1
|
|||
mod_licence=MIT
|
||||
maven_group=com.leisuretimedock
|
||||
archives_name=jsonem_fabrge
|
||||
archives_base_name=jsonem_1.20.1_fabrge
|
||||
enabled_platforms=fabric,neoforge
|
||||
# Minecraft properties
|
||||
minecraft_version=1.20.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user