Skip to content

Commit

Permalink
1.21.3 -> 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 12, 2024
1 parent 827bb99 commit df6ee38
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 72 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
fabric_version=0.106.1+1.21.3
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.9
fabric_version=0.111.0+1.21.4

# Mod Properties
group=com.minelittlepony
Expand All @@ -15,9 +15,9 @@ org.gradle.daemon=false
description=Json-based entity models. Mson.

# Publishing
minecraft_version_range=>=1.21.2
minecraft_version_range=>=1.21.4
modrinth_loader_type=fabric
modrinth_project_id=POWgsZW2

# Dependencies
modmenu_version=12.0.0-beta.1
modmenu_version=13.0.0-beta.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.Nullable;

import com.google.gson.JsonElement;
import com.google.gson.Strictness;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonWriter;

Expand Down Expand Up @@ -47,7 +48,7 @@ private static class JsWriter extends JsonWriter {

public JsWriter(Writer out) {
super(out);
setLenient(true);
setStrictness(Strictness.LENIENT);
setIndent(currentIndent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModelLayer;

import org.jetbrains.annotations.Nullable;

import com.google.gson.JsonElement;
import com.minelittlepony.mson.api.parser.ModelLoader;
import com.minelittlepony.mson.impl.mixin.ModelListAccessor;
import com.minelittlepony.mson.impl.model.bbmodel.BBModelFormat;
import com.minelittlepony.mson.impl.model.json.MsonModelFormat;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;

public class VanillaModelSerializer extends ModelSerializer<TexturedModelData> {

Expand All @@ -29,7 +28,7 @@ public VanillaModelSerializer() {
}

public void exportAll(Path root) {
((ModelList)MinecraftClient.getInstance().getEntityModelLoader()).getModelParts().forEach((id, model) -> {
((ModelListAccessor)MinecraftClient.getInstance().getLoadedEntityModels()).getModelParts().forEach((id, model) -> {
try {
Path path = root.resolve(id.id().getNamespace()).resolve(id.id().getPath() + ".json");
writeToFile(path, model);
Expand Down Expand Up @@ -59,10 +58,6 @@ public JsonElement writeToJsonElement(TexturedModelData content) {
return JsonBuffer.INSTANCE.write(content);
}

public interface ModelList {
Map<EntityModelLayer, TexturedModelData> getModelParts();
}

@Override
public void close() throws Exception {
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/minelittlepony/mson/impl/MsonImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

Expand All @@ -24,6 +22,7 @@
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.api.Mson;
import com.minelittlepony.mson.impl.key.AbstractModelKeyImpl;
import com.minelittlepony.mson.impl.mixin.ModelListAccessor;
import com.minelittlepony.mson.impl.model.RootContext;
import com.minelittlepony.mson.impl.model.bbmodel.BBModelFormat;
import com.minelittlepony.mson.impl.model.json.MsonModelFormat;
Expand Down Expand Up @@ -70,10 +69,10 @@ public Stream<ModelFormat<?>> getHandlers(String extension) {
return handlersByExtension.getOrDefault(extension, Set.of()).stream();
}

public void registerVanillaModels(Map<EntityModelLayer, TexturedModelData> modelParts) {
public void registerVanillaModels() {
synchronized (vanillaModels) {
vanillaModels.clear();
modelParts.forEach((layer, vanilla) -> {
((ModelListAccessor)MinecraftClient.getInstance().getLoadedEntityModels()).getModelParts().forEach((layer, vanilla) -> {
Identifier id = layer.id().withPath(p -> String.format("mson/%s", p));
((MsonImpl.KeyHolder)vanilla).setKey(registeredModels.computeIfAbsent(id, VanillaKey::new));
vanillaModels.add(id);
Expand All @@ -85,13 +84,14 @@ public void registerVanillaModels(Map<EntityModelLayer, TexturedModelData> model
}
}

private CompletableFuture<Void> requireVanillaModels(ResourceManager sender, Executor prepareExecutor) {
private CompletableFuture<Void> requireVanillaModels(Synchronizer sync, ResourceManager sender, Executor prepareExecutor, Executor applyExecutor) {
boolean hasVanillaModels;
synchronized (vanillaModels) {
hasVanillaModels = !vanillaModels.isEmpty();
}
if (!hasVanillaModels) {
return CompletableFuture.runAsync(() -> MinecraftClient.getInstance().getEntityModelLoader().reload(sender), prepareExecutor);
LOGGER.info("Vanilla models are not ready, preparing them ourselves...");
return CompletableFuture.runAsync(() -> MinecraftClient.getInstance().getBakedModelManager().reload(sync, sender, prepareExecutor, applyExecutor), prepareExecutor);
}
return CompletableFuture.completedFuture(null);
}
Expand All @@ -100,7 +100,7 @@ private CompletableFuture<Void> requireVanillaModels(ResourceManager sender, Exe
public CompletableFuture<Void> reload(Synchronizer sync, ResourceManager sender, Executor prepareExecutor, Executor applyExecutor) {
ModelFoundry loadingFoundry = new ModelFoundry(this).setWorker(LoadWorker.async(prepareExecutor));

return requireVanillaModels(sender, prepareExecutor)
return requireVanillaModels(sync, sender, prepareExecutor, applyExecutor)
.thenComposeAsync(v -> loadingFoundry.load(), prepareExecutor)
.thenCompose(sync::whenPrepared)
.thenRunAsync(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.minelittlepony.mson.impl.mixin;

import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.util.profiler.Profiler;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.minelittlepony.mson.impl.MsonImpl;

@Mixin(BakedModelManager.class)
abstract class MixinBakedModelManager {
@Inject(method = "upload(Lnet/minecraft/client/render/model/BakedModelManager$BakingResult;Lnet/minecraft/util/profiler/Profiler;)V", at = @At("TAIL"))
private void upload(@Coerce Object bakingResult, Profiler profiler, CallbackInfo info) {
MsonImpl.INSTANCE.registerVanillaModels();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.item.ItemModelManager;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.model.EntityModelLoader;
import net.minecraft.client.render.entity.model.LoadedEntityModels;
import net.minecraft.client.render.item.ItemRenderer;

import org.spongepowered.asm.mixin.Final;
Expand All @@ -34,13 +35,15 @@ abstract class MixinBlockEntityRenderDispatcher implements EntityRendererRegistr
@Shadow
private @Final TextRenderer textRenderer;
@Shadow
private @Final EntityModelLoader entityModelLoader;
private @Final Supplier<LoadedEntityModels> entityModelsGetter;
@Shadow
private @Final Supplier<BlockRenderManager> blockRenderManager;
private @Final BlockRenderManager blockRenderManager;
@Shadow
private @Final Supplier<ItemRenderer> itemRenderer;
private @Final ItemModelManager itemModelManager;
@Shadow
private @Final Supplier<EntityRenderDispatcher> entityRenderDispatcher;
private @Final ItemRenderer itemRenderer;
@Shadow
private @Final EntityRenderDispatcher entityRenderDispatcher;

@Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("RETURN"))
private void onInit(CallbackInfo info) {
Expand All @@ -50,11 +53,14 @@ private void onInit(CallbackInfo info) {
@Override
public <P extends BlockEntity, R extends BlockEntityRenderer<?>> void registerBlockRenderer(BlockEntityType<P> type, Function<BlockEntityRendererFactory.Context, R> constructor) {
try {
BlockEntityRendererFactory.Context context = new BlockEntityRendererFactory.Context((BlockEntityRenderDispatcher)(Object)this,
blockRenderManager.get(),
itemRenderer.get(),
entityRenderDispatcher.get(),
entityModelLoader, textRenderer);
BlockEntityRendererFactory.Context context = new BlockEntityRendererFactory.Context(
(BlockEntityRenderDispatcher)(Object)this,
blockRenderManager,
itemModelManager,
itemRenderer,
entityRenderDispatcher,
entityModelsGetter.get(),
textRenderer);
if (renderers instanceof ImmutableMap) {
renderers = new HashMap<>(renderers);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.PlayerEntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory.Context;
import net.minecraft.client.render.entity.model.EntityModelLoader;
import net.minecraft.client.render.entity.equipment.EquipmentModelLoader;
import net.minecraft.client.render.entity.model.LoadedEntityModels;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.resource.ResourceManager;
Expand All @@ -29,6 +30,7 @@
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

@Mixin(EntityRenderDispatcher.class)
abstract class MixinEntityRenderDispatcher implements EntityRendererRegistry {
Expand All @@ -37,7 +39,9 @@ abstract class MixinEntityRenderDispatcher implements EntityRendererRegistry {
private Map<EntityType<?>, Map<Predicate<Entity>, EntityRenderer<? extends Entity, ?>>> customEntityRenderers;
private Map<Identifier, Map.Entry<Predicate<AbstractClientPlayerEntity>, PlayerEntityRenderer>> customModelRenderers;
@Shadow
private @Final EntityModelLoader modelLoader;
private @Final Supplier<LoadedEntityModels> entityModelsGetter;
@Shadow
private @Final EquipmentModelLoader equipmentModelLoader;

@Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("RETURN"))
private void onRegisterRenderers(ResourceManager manager, CallbackInfo info) {
Expand All @@ -49,14 +53,14 @@ private void onRegisterRenderers(ResourceManager manager, CallbackInfo info) {

private EntityRendererFactory.Context createContext() {
MinecraftClient mc = MinecraftClient.getInstance();
EntityRenderDispatcher self = (EntityRenderDispatcher)(Object)this;
return new EntityRendererFactory.Context(self,
mc.getItemRenderer(),
return new EntityRendererFactory.Context(
(EntityRenderDispatcher)(Object)this,
mc.getItemModelManager(),
mc.getMapRenderer(),
mc.getBlockRenderManager(),
mc.getResourceManager(),
modelLoader,
mc.getEquipmentModelLoader(),
entityModelsGetter.get(),
equipmentModelLoader,
mc.textRenderer
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.minelittlepony.mson.impl.mixin;

import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.LoadedEntityModels;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Map;

@Mixin(LoadedEntityModels.class)
public interface ModelListAccessor {
@Accessor("modelParts")
Map<EntityModelLayer, TexturedModelData> getModelParts();
}
5 changes: 3 additions & 2 deletions src/main/resources/mson.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"refmap": "mson.mixin.refmap.json",
"compatibilityLevel": "JAVA_17",
"client": [
"MixinBakedModelManager",
"MixinBlockEntityRenderDispatcher",
"MixinDilation",
"MixinEntityModelLoader",
"MixinEntityRenderDispatcher",
"MixinModel",
"MixinModelPart",
Expand All @@ -17,6 +17,7 @@
"MixinTextureDimensions",
"MixinTexturedModelData",
"MixinModelPartData",
"MixinModelCuboidData"
"MixinModelCuboidData",
"ModelListAccessor"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"parent": "mson:biped",
"data": {
"head": {
"pivot": [0, -6, -6],
"cubes": [
{ "from": [-4, -8, -4], "size": [ 8, 8, 8] }
],
"children": {
"hat": {
"texture": { "u": 0, "v": 16 },
"pivot": [0, -14, 0],
"cubes": [
{ "from": [-4, -8, -4], "size": [ 8, 8, 8], "dilate": [-0.5, -0.5, -0.5] }
]
Expand All @@ -24,7 +24,7 @@
},
"right_arm": {
"texture": { "u": 56, "v": 0 },
"pivot": [-3, -12, 0],
"pivot": [-5, -12, 0],
"cubes": [
{ "from": [-1, -2, -1], "size": [ 2, 30, 2] }
]
Expand Down

0 comments on commit df6ee38

Please sign in to comment.