From 6c9a5b7191666132e5b234704a9595498dc248b5 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 25 Jun 2022 16:14:56 -0500 Subject: [PATCH 01/11] Started :eyes: --- library/rendering/build.gradle | 7 +++ library/rendering/entity_models/build.gradle | 18 +++++++ .../rendering/entity_models/api/Codecs.java | 49 ++++++++++++++++++ .../entity_models/api/Interpolators.java | 36 +++++++++++++ .../assets/quilt_entity_models/icon.png | Bin 0 -> 261 bytes .../resources/quilt_entity_models.mixins.json | 10 ++++ .../src/testmod/resources/quilt.mod.json | 18 +++++++ .../src/testmod/resources/quilt.mod.json | 14 +++++ settings.gradle | 1 + 9 files changed, 153 insertions(+) create mode 100644 library/rendering/build.gradle create mode 100644 library/rendering/entity_models/build.gradle create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java create mode 100644 library/rendering/entity_models/src/main/resources/assets/quilt_entity_models/icon.png create mode 100644 library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json create mode 100644 library/rendering/entity_models/src/testmod/resources/quilt.mod.json create mode 100644 library/rendering/src/testmod/resources/quilt.mod.json diff --git a/library/rendering/build.gradle b/library/rendering/build.gradle new file mode 100644 index 0000000000..6b7d6c3ff1 --- /dev/null +++ b/library/rendering/build.gradle @@ -0,0 +1,7 @@ +plugins { + id("qsl.library") +} + +qslLibrary { + libraryName = "rendering" +} diff --git a/library/rendering/entity_models/build.gradle b/library/rendering/entity_models/build.gradle new file mode 100644 index 0000000000..93b5bae7ab --- /dev/null +++ b/library/rendering/entity_models/build.gradle @@ -0,0 +1,18 @@ +plugins { + id("qsl.module") +} + +qslModule { + name = "Quilt Entity Model API" + moduleName = "entity_models" + id = "quilt_entity_models" + description = "Adds data driven entity models and animations" + library = "rendering" + moduleDependencies { + core { + api("qsl_base") + impl("resource_loader") + } + } + clientOnly() +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java new file mode 100644 index 0000000000..95d2e5df5b --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -0,0 +1,49 @@ +package org.quiltmc.qsl.rendering.entity_models.api; + +import java.util.Arrays; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.client.render.animation.Animation; +import net.minecraft.client.render.animation.AnimationKeyframe; +import net.minecraft.client.render.animation.PartAnimation; +import net.minecraft.util.math.Vec3f; + +public class Codecs { + public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), + Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), + Codec.STRING.flatXmap( + s -> Interpolators.get(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), + i -> Interpolators.get(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) + ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) + ).apply(instance, AnimationKeyframe::new)); + + public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.flatXmap(s -> switch (s) { + case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); + case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); + case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); + default -> DataResult.error("Unknown transformation: " + s); + }, transformation -> { + if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { + return DataResult.success("TRANSLATE"); + } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { + return DataResult.success("ROTATE"); + } else if (transformation == PartAnimation.AnimationTargets.SCALE) { + return DataResult.success("SCALE"); + } else { + return DataResult.error("Unknown transformation"); + } + }).fieldOf("transformation").forGetter(PartAnimation::transformation), + Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) + ).apply(instance, PartAnimation::new)); + + public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), + Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), + Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) + ).apply(instance, Animation::new)); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java new file mode 100644 index 0000000000..5e5a490138 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java @@ -0,0 +1,36 @@ +package org.quiltmc.qsl.rendering.entity_models.api; + +import java.util.Map; +import java.util.Optional; + +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; + +import net.minecraft.client.render.animation.PartAnimation; + +public class Interpolators { + private static final Map INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); + private static final Map INVERSE_INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); + + static { + register("LINEAR", PartAnimation.Interpolators.LINEAR); + register("SPLINE", PartAnimation.Interpolators.SPLINE); + } + + public static void register(String name, PartAnimation.Interpolator interpolator) { + if (INTERPOLATORS.containsKey(name)) { + throw new IllegalArgumentException(name + " already used as name"); + } else if (INVERSE_INTERPOLATORS.containsKey(interpolator)) { + throw new IllegalArgumentException("Interpolator already assigned to " + INVERSE_INTERPOLATORS.get(interpolator)); + } + INTERPOLATORS.put(name, interpolator); + INVERSE_INTERPOLATORS.put(interpolator, name); + } + + public static Optional get(String name) { + return Optional.ofNullable(INTERPOLATORS.get(name)); + } + + public static Optional get(PartAnimation.Interpolator interpolator) { + return Optional.ofNullable(INVERSE_INTERPOLATORS.get(interpolator)); + } +} diff --git a/library/rendering/entity_models/src/main/resources/assets/quilt_entity_models/icon.png b/library/rendering/entity_models/src/main/resources/assets/quilt_entity_models/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8d54ad0021bbf0258acfe2ba452ccc0e6f36f566 GIT binary patch literal 261 zcmV+g0s8)lP)O|2F_@TM=AcYyV#WxOBw)fQtW(8;_SF|EJmfx^Vx~qyO1! z+uE1g+$r5#A>8-?004nWL_t(I%jJ{V3V Date: Mon, 27 Jun 2022 19:05:35 -0500 Subject: [PATCH 02/11] Animation Loading --- .../entity_models/api/AnimationManager.java | 95 +++++++++++++++++++ ...Interpolators.java => AnimationUtils.java} | 16 ++-- .../rendering/entity_models/api/Codecs.java | 4 +- .../api/HasAnimationManager.java | 14 +++ .../mixin/EntityRenderDispatcherMixin.java | 37 ++++++++ .../EntityRendererFactoryContextMixin.java | 39 ++++++++ .../resources/quilt_entity_models.mixins.json | 2 + 7 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java rename library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/{Interpolators.java => AnimationUtils.java} (62%) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java new file mode 100644 index 0000000000..6df0497c7b --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java @@ -0,0 +1,95 @@ +package org.quiltmc.qsl.rendering.entity_models.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.minecraft.client.render.animation.Animation; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.profiler.Profiler; + +public class AnimationManager implements SimpleResourceReloader { + private static final Logger LOGGER = LoggerFactory.getLogger("Quilt Animation Manager"); + private Map animations; + + public Animation getAnimation(Identifier id) { + return animations.get(id); + } + + @Override + public CompletableFuture load(ResourceManager manager, Profiler profiler, Executor executor) { + return CompletableFuture.supplyAsync(() -> new AnimationLoader(manager, profiler), executor); + } + + @Override + public CompletableFuture apply(AnimationLoader prepared, ResourceManager manager, Profiler profiler, Executor executor) { + this.animations = prepared.getAnimations(); + return CompletableFuture.runAsync(() -> { + }); + } + + @Override + public Identifier getQuiltId() { + return new Identifier("quilt_entity_models", "animation_reloader"); + } + + public static class AnimationLoader { + private final ResourceManager manager; + private final Profiler profiler; + private final Map animations = new HashMap<>(); + + public AnimationLoader(ResourceManager manager, Profiler profiler) { + this.manager = manager; + this.profiler = profiler; + loadAnimations(); + } + + private void loadAnimations() { + profiler.push("Load Animations"); + Map resources = manager.findResources("animations", id -> id.getPath().endsWith(".json")); + for (Map.Entry entry : resources.entrySet()) { + addAnimation(entry.getKey(), entry.getValue()); + } + profiler.pop(); + } + + private void addAnimation(Identifier id, Resource resource) { + BufferedReader reader; + try { + reader = resource.openBufferedReader(); + } catch (IOException e) { + LOGGER.error(String.format("Unable to open BufferedReader for id %s", id), e); + return; + } + + JsonObject json = JsonHelper.deserialize(reader); + DataResult> result = Codecs.ANIMATION.decode(JsonOps.INSTANCE, json); + + if (result.error().isPresent()) { + LOGGER.error(String.format("Unable to parse animation file %s.\nReason: %s", id, result.error().get().message())); + return; + } + + animations.put(new Identifier(id.getNamespace(), id.getPath().substring("animations/".length())), result.result().get().getFirst()); + } + + public Map getAnimations() { + return animations; + } + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java similarity index 62% rename from library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java rename to library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java index 5e5a490138..c3654adfd5 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Interpolators.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java @@ -5,32 +5,36 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; +import net.minecraft.client.render.animation.Animation; import net.minecraft.client.render.animation.PartAnimation; +import net.minecraft.resource.pack.ResourcePack; +import net.minecraft.util.Identifier; -public class Interpolators { +public class AnimationUtils { private static final Map INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); private static final Map INVERSE_INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); static { - register("LINEAR", PartAnimation.Interpolators.LINEAR); - register("SPLINE", PartAnimation.Interpolators.SPLINE); + registerInterpolation("LINEAR", PartAnimation.Interpolators.LINEAR); + registerInterpolation("SPLINE", PartAnimation.Interpolators.SPLINE); } - public static void register(String name, PartAnimation.Interpolator interpolator) { + public static void registerInterpolation(String name, PartAnimation.Interpolator interpolator) { if (INTERPOLATORS.containsKey(name)) { throw new IllegalArgumentException(name + " already used as name"); } else if (INVERSE_INTERPOLATORS.containsKey(interpolator)) { throw new IllegalArgumentException("Interpolator already assigned to " + INVERSE_INTERPOLATORS.get(interpolator)); } + INTERPOLATORS.put(name, interpolator); INVERSE_INTERPOLATORS.put(interpolator, name); } - public static Optional get(String name) { + public static Optional getInterpolatorFromName(String name) { return Optional.ofNullable(INTERPOLATORS.get(name)); } - public static Optional get(PartAnimation.Interpolator interpolator) { + public static Optional getNameForInterpolator(PartAnimation.Interpolator interpolator) { return Optional.ofNullable(INVERSE_INTERPOLATORS.get(interpolator)); } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 95d2e5df5b..b8426d9708 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -16,8 +16,8 @@ public class Codecs { Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), Codec.STRING.flatXmap( - s -> Interpolators.get(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), - i -> Interpolators.get(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) + s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), + i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) ).apply(instance, AnimationKeyframe::new)); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java new file mode 100644 index 0000000000..2b3e5f16a0 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java @@ -0,0 +1,14 @@ +package org.quiltmc.qsl.rendering.entity_models.api; + +import org.quiltmc.qsl.base.api.util.InjectedInterface; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRendererFactory; + +@InjectedInterface(value = { + EntityRenderDispatcher.class, + EntityRendererFactory.Context.class +}) +public interface HasAnimationManager { + AnimationManager getAnimationManager(); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java new file mode 100644 index 0000000000..c2225fd4bd --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java @@ -0,0 +1,37 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.option.GameOptions; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.resource.ResourceType; + +@Mixin(EntityRenderDispatcher.class) +public class EntityRenderDispatcherMixin implements HasAnimationManager { + @Unique + private AnimationManager animationManager; + + @Inject(method = "", at = @At("TAIL")) + private void createAnimationManager(MinecraftClient minecraftClient, TextureManager textureManager, ItemRenderer itemRenderer, BlockRenderManager blockRenderManager, TextRenderer textRenderer, GameOptions gameOptions, EntityModelLoader entityModelLoader, CallbackInfo ci) { + this.animationManager = new AnimationManager(); + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(this.animationManager); + } + + @Override + public AnimationManager getAnimationManager() { + return animationManager; + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java new file mode 100644 index 0000000000..0d6d4b3679 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java @@ -0,0 +1,39 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.option.GameOptions; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.item.HeldItemRenderer; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.texture.TextureManager; +import net.minecraft.resource.ResourceManager; +import net.minecraft.resource.ResourceType; + +@Mixin(EntityRendererFactory.Context.class) +public class EntityRendererFactoryContextMixin implements HasAnimationManager { + @Unique + private AnimationManager animationManager; + + @Inject(method = "", at = @At("TAIL")) + private void createAnimationManager(EntityRenderDispatcher entityRenderDispatcher, ItemRenderer itemRenderer, BlockRenderManager blockRenderManager, HeldItemRenderer heldItemRenderer, ResourceManager resourceManager, EntityModelLoader entityModelLoader, TextRenderer textRenderer, CallbackInfo ci) { + this.animationManager = entityRenderDispatcher.getAnimationManager(); + } + + @Override + public AnimationManager getAnimationManager() { + return animationManager; + } +} diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index 567cfeb573..d6b3430269 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -3,6 +3,8 @@ "package": "org.quiltmc.qsl.rendering.entity_models.mixin", "compatibilityLevel": "JAVA_17", "client": [ + "EntityRenderDispatcherMixin", + "EntityRendererFactoryContextMixin" ], "injectors": { "defaultRequire": 1 From 8e5a39cee5f0ea8604fa06aa4b0cbb9ee30c388a Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Thu, 30 Jun 2022 16:06:30 -0700 Subject: [PATCH 03/11] Animation Loading works + Model Codec start --- library/rendering/entity_models/build.gradle | 11 ++ .../entity_models/api/AnimationManager.java | 2 +- .../rendering/entity_models/api/Codecs.java | 158 ++++++++++++++---- .../QuiltEntityModelsClientInitializer.java | 10 ++ .../entity_models/mixin/DilationAccessor.java | 18 ++ .../mixin/ModelCuboidDataAccessor.java | 41 +++++ .../mixin/ModelPartDataAccessor.java | 28 ++++ .../mixin/TextureDimensionsAccessor.java | 14 ++ .../mixin/TexturedModelDataAccessor.java | 22 +++ .../entity_models/mixin/Vector2fMixin.java | 23 +++ .../resources/quilt_entity_models.mixins.json | 8 +- 11 files changed, 299 insertions(+), 36 deletions(-) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java diff --git a/library/rendering/entity_models/build.gradle b/library/rendering/entity_models/build.gradle index 93b5bae7ab..7b182150de 100644 --- a/library/rendering/entity_models/build.gradle +++ b/library/rendering/entity_models/build.gradle @@ -14,5 +14,16 @@ qslModule { impl("resource_loader") } } + entrypoints { + client_init { + values = ["org.quiltmc.qsl.rendering.entity_models.impl.QuiltEntityModelsClientInitializer"] + } + } + injectedInterface("net/minecraft/class_898") { + values = ["org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager"] + } + injectedInterface("net/minecraft/class_5617\$class_5618") { + values = ["org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager"] + } clientOnly() } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java index 6df0497c7b..2ff6ece844 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java @@ -78,7 +78,7 @@ private void addAnimation(Identifier id, Resource resource) { } JsonObject json = JsonHelper.deserialize(reader); - DataResult> result = Codecs.ANIMATION.decode(JsonOps.INSTANCE, json); + DataResult> result = Codecs.Animations.ANIMATION.decode(JsonOps.INSTANCE, json); if (result.error().isPresent()) { LOGGER.error(String.format("Unable to parse animation file %s.\nReason: %s", id, result.error().get().message())); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index b8426d9708..e01b0eb899 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -1,49 +1,139 @@ package org.quiltmc.qsl.rendering.entity_models.api; import java.util.Arrays; +import java.util.HashMap; +import java.util.Optional; +import com.google.common.collect.ImmutableList; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TextureDimensionsAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TexturedModelDataAccessor; +import net.minecraft.client.model.Dilation; +import net.minecraft.client.model.ModelCuboidData; +import net.minecraft.client.model.ModelData; +import net.minecraft.client.model.ModelPartData; +import net.minecraft.client.model.ModelTransform; +import net.minecraft.client.model.TextureDimensions; +import net.minecraft.client.model.TexturedModelData; import net.minecraft.client.render.animation.Animation; import net.minecraft.client.render.animation.AnimationKeyframe; import net.minecraft.client.render.animation.PartAnimation; +import net.minecraft.client.util.math.Vector2f; +import net.minecraft.util.Util; import net.minecraft.util.math.Vec3f; public class Codecs { - public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), - Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), - Codec.STRING.flatXmap( - s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), - i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) - ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) - ).apply(instance, AnimationKeyframe::new)); - - public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> instance.group( - Codec.STRING.flatXmap(s -> switch (s) { - case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); - case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); - case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); - default -> DataResult.error("Unknown transformation: " + s); - }, transformation -> { - if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { - return DataResult.success("TRANSLATE"); - } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { - return DataResult.success("ROTATE"); - } else if (transformation == PartAnimation.AnimationTargets.SCALE) { - return DataResult.success("SCALE"); - } else { - return DataResult.error("Unknown transformation"); - } - }).fieldOf("transformation").forGetter(PartAnimation::transformation), - Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) - ).apply(instance, PartAnimation::new)); - - public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), - Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), - Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) - ).apply(instance, Animation::new)); + public static final class Animations { + public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), + Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), + Codec.STRING.flatXmap( + s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), + i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) + ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) + ).apply(instance, AnimationKeyframe::new)); + + public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.flatXmap(s -> switch (s) { + case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); + case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); + case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); + default -> DataResult.error("Unknown transformation: " + s); + }, transformation -> { + if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { + return DataResult.success("TRANSLATE"); + } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { + return DataResult.success("ROTATE"); + } else if (transformation == PartAnimation.AnimationTargets.SCALE) { + return DataResult.success("SCALE"); + } else { + return DataResult.error("Unknown transformation"); + } + }).fieldOf("transformation").forGetter(PartAnimation::transformation), + Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) + ).apply(instance, PartAnimation::new)); + + public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), + Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), + Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) + ).apply(instance, Animation::new)); + } + + public static final class Model { + public static final Codec TEXTURE_DIMENSIONS = RecordCodecBuilder.create((instance) -> + instance.group( + Codec.INT.fieldOf("width").forGetter(obj -> ((TextureDimensionsAccessor) obj).width()), + Codec.INT.fieldOf("height").forGetter(obj -> ((TextureDimensionsAccessor) obj).height()) + ).apply(instance, TextureDimensions::new) + ); + + public static final Codec MODEL_TRANSFORM = RecordCodecBuilder.create((instance) -> + instance.group( + Vec3f.CODEC.optionalFieldOf("origin", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pivotX, obj.pivotY, obj.pivotZ)), + Vec3f.CODEC.optionalFieldOf("rotation", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pitch, obj.yaw, obj.roll)) + ).apply(instance, (origin, rot) -> ModelTransform.of(origin.getX(), origin.getY(), origin.getZ(), rot.getX(), rot.getY(), rot.getZ())) + ); + + public static final Codec DILATION = Vec3f.CODEC.xmap( + vec -> new Dilation(vec.getX(), vec.getY(), vec.getZ()), + dil -> new Vec3f( + ((DilationAccessor) dil).radiusX(), + ((DilationAccessor) dil).radiusY(), + ((DilationAccessor) dil).radiusZ()) + ); + + public static final Codec VECTOR2F = Codec.FLOAT.listOf().comapFlatMap((vec) -> + Util.fixedSizeList(vec, 2).map((arr) -> new Vector2f(arr.get(0), arr.get(1))), + (vec) -> ImmutableList.of(vec.getX(), vec.getY()) + ); + + private static ModelCuboidData createCuboidData(Optional name, Vec3f offset, Vec3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize) { + return ModelCuboidDataAccessor.create(name.orElse(null), uv.getX(), uv.getY(), offset.getX(), offset.getY(), offset.getZ(), dimensions.getX(), dimensions.getY(), dimensions.getZ(), dilation, mirror, uvSize.getX(), uvSize.getY()); + } + + private static final Vector2f DEFAULT_UV_SCALE = new Vector2f(1.0f, 1.0f); + + public static final Codec MODEL_CUBOID_DATA = RecordCodecBuilder.create((instance) -> + instance.group( + Codec.STRING.optionalFieldOf("name").forGetter(obj -> Optional.ofNullable(((ModelCuboidDataAccessor) (Object) obj).name())), + Vec3f.CODEC.fieldOf("offset").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).offset()), + Vec3f.CODEC.fieldOf("dimensions").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dimensions()), + DILATION.optionalFieldOf("dilation", Dilation.NONE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dilation()), + Codec.BOOL.optionalFieldOf("mirror", false).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).mirror()), + VECTOR2F.fieldOf("uv").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uv()), + VECTOR2F.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uvScale()) + ).apply(instance, Model::createCuboidData) + ); + + public static final Codec MODEL_PART_DATA = RecordCodecBuilder.create((instance) -> + instance.group( + MODEL_TRANSFORM.optionalFieldOf("transform", ModelTransform.NONE).forGetter(obj -> ((ModelPartDataAccessor) obj).transform()), + Codec.list(MODEL_CUBOID_DATA).fieldOf("cuboids").forGetter(obj -> ((ModelPartDataAccessor) obj).cuboids()), + Codec.unboundedMap(Codec.STRING, Model.MODEL_PART_DATA).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((ModelPartDataAccessor) obj).children()) + ).apply(instance, (transform, cuboids, children) -> { + var data = ModelPartDataAccessor.create(cuboids, transform); + ((ModelPartDataAccessor) data).children().putAll(children); + return data; + }) + ); + ; + + public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create((instance) -> + instance.group( + TEXTURE_DIMENSIONS.fieldOf("texture").forGetter(obj -> ((TexturedModelDataAccessor) obj).texture()), + Codec.unboundedMap(Codec.STRING, MODEL_PART_DATA).fieldOf("bones").forGetter(obj -> ((ModelPartDataAccessor) ((TexturedModelDataAccessor) obj).root().getRoot()).children()) + ).apply(instance, (texture, bones) -> { + var data = new ModelData(); + ((ModelPartDataAccessor) data.getRoot()).children().putAll(bones); + return TexturedModelDataAccessor.create(data, texture); + }) + ); + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java new file mode 100644 index 0000000000..245b5854f7 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java @@ -0,0 +1,10 @@ +package org.quiltmc.qsl.rendering.entity_models.impl; + +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; + +public class QuiltEntityModelsClientInitializer implements ClientModInitializer { + @Override + public void onInitializeClient(ModContainer mod) { + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java new file mode 100644 index 0000000000..4049d1d237 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java @@ -0,0 +1,18 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.model.Dilation; + +@Mixin(Dilation.class) +public interface DilationAccessor { + @Accessor("radiusX") + float radiusX(); + + @Accessor("radiusY") + float radiusY(); + + @Accessor("radiusZ") + float radiusZ(); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java new file mode 100644 index 0000000000..e3e9e8956f --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -0,0 +1,41 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.client.model.Dilation; +import net.minecraft.client.model.ModelCuboidData; +import net.minecraft.client.util.math.Vector2f; +import net.minecraft.util.math.Vec3f; + +@Mixin(ModelCuboidData.class) +public interface ModelCuboidDataAccessor { + + @Accessor("name") + String name(); + + @Accessor("offset") + Vec3f offset(); + + @Accessor("dimensions") + Vec3f dimensions(); + + @Accessor("extraSize") + Dilation dilation(); + + @Accessor("mirror") + boolean mirror(); + + @Accessor("textureUV") + Vector2f uv(); + + @Accessor("textureScale") + Vector2f uvScale(); + + @Invoker("") + static ModelCuboidData create(@Nullable String string, float f, float g, float h, float i, float j, float k, float l, float m, Dilation dilation, boolean bl, float n, float o){ + throw new AssertionError("Unreachable"); + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java new file mode 100644 index 0000000000..f29141ddc1 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -0,0 +1,28 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import net.minecraft.client.model.ModelCuboidData; +import net.minecraft.client.model.ModelPartData; +import net.minecraft.client.model.ModelTransform; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.List; +import java.util.Map; + +@Mixin(ModelPartData.class) +public interface ModelPartDataAccessor { + @Accessor("cuboidData") + List cuboids(); + + @Accessor("rotationData") + ModelTransform transform(); + + @Accessor("children") + Map children(); + + @Invoker("") + static ModelPartData create(List cuboids, ModelTransform rotation) { + throw new AssertionError("mixin broke"); + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java new file mode 100644 index 0000000000..e1df28f04f --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java @@ -0,0 +1,14 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import net.minecraft.client.model.TextureDimensions; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(TextureDimensions.class) +public interface TextureDimensionsAccessor { + @Accessor("width") + int width(); + + @Accessor("height") + int height(); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java new file mode 100644 index 0000000000..6ce7bfb9b3 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -0,0 +1,22 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import net.minecraft.client.model.ModelData; +import net.minecraft.client.model.TextureDimensions; +import net.minecraft.client.model.TexturedModelData; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(TexturedModelData.class) +public interface TexturedModelDataAccessor { + @Accessor("data") + ModelData root(); + + @Accessor("dimensions") + TextureDimensions texture(); + + @Invoker("") + static TexturedModelData create(ModelData data, TextureDimensions dimensions) { + throw new AssertionError("mixin broke"); + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java new file mode 100644 index 0000000000..fd4373f24b --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java @@ -0,0 +1,23 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.client.util.math.Vector2f; + +@Mixin(Vector2f.class) +public abstract class Vector2fMixin { + @Shadow + public abstract float getX(); + + @Shadow + public abstract float getY(); + + @Override + public boolean equals(Object o) { + if (o instanceof Vector2f vec) { + return this.getX() == vec.getX() && this.getY() == vec.getY(); + } + return super.equals(o); + } +} diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index d6b3430269..6d224649c2 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -3,8 +3,14 @@ "package": "org.quiltmc.qsl.rendering.entity_models.mixin", "compatibilityLevel": "JAVA_17", "client": [ + "DilationAccessor", "EntityRenderDispatcherMixin", - "EntityRendererFactoryContextMixin" + "EntityRendererFactoryContextMixin", + "ModelCuboidDataAccessor", + "ModelPartDataAccessor", + "TextureDimensionsAccessor", + "TexturedModelDataAccessor", + "Vector2fMixin" ], "injectors": { "defaultRequire": 1 From 4de9e95dfe2bf75f262c37e9c9bc6da45e93e241 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 30 Jul 2022 01:18:50 -0700 Subject: [PATCH 04/11] Finish Models + Get ready for review --- .../entity_models/api/AnimationManager.java | 16 +++ .../entity_models/api/AnimationUtils.java | 16 +++ .../rendering/entity_models/api/Codecs.java | 16 +++ .../api/HasAnimationManager.java | 16 +++ .../impl/DynamicEntityModelLoader.java | 127 ++++++++++++++++++ .../QuiltEntityModelsClientInitializer.java | 16 +++ .../entity_models/mixin/DilationAccessor.java | 16 +++ .../mixin/EntityModelLoaderMixin.java | 53 ++++++++ .../mixin/EntityRenderDispatcherMixin.java | 25 +++- .../EntityRendererFactoryContextMixin.java | 27 ++-- .../mixin/ModelCuboidDataAccessor.java | 16 +++ .../mixin/ModelPartDataAccessor.java | 16 +++ .../mixin/TextureDimensionsAccessor.java | 16 +++ .../mixin/TexturedModelDataAccessor.java | 16 +++ .../entity_models/mixin/Vector2fMixin.java | 16 +++ .../resources/quilt_entity_models.mixins.json | 1 + 16 files changed, 397 insertions(+), 12 deletions(-) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java index 2ff6ece844..c828a02a8c 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api; import java.io.BufferedReader; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java index c3654adfd5..31538199c6 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api; import java.util.Map; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index e01b0eb899..86b758b69a 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api; import java.util.Arrays; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java index 2b3e5f16a0..ae46b84ebc 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api; import org.quiltmc.qsl.base.api.util.InjectedInterface; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java new file mode 100644 index 0000000000..a12433b694 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -0,0 +1,127 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.rendering.entity_models.impl; + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import org.quiltmc.qsl.rendering.entity_models.api.Codecs; +import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.profiler.Profiler; + +public class DynamicEntityModelLoader implements SimpleResourceReloader { + private static final Logger LOGGER = LoggerFactory.getLogger("Quilt Entity Model Manager"); + private Map modelData; + + public TexturedModelData getModelData(EntityModelLayer layer) { + return modelData.get(layer); + } + + @Override + public CompletableFuture load(ResourceManager manager, Profiler profiler, Executor executor) { + return CompletableFuture.supplyAsync(() -> new ModelLoader(manager, profiler), executor); + } + + @Override + public CompletableFuture apply(ModelLoader prepared, ResourceManager manager, Profiler profiler, Executor executor) { + this.modelData = prepared.getModelData(); + return CompletableFuture.runAsync(() -> { + }); + } + + @Override + public Identifier getQuiltId() { + return new Identifier("quilt_entity_models", "entity_model_reloader"); + } + + public static class ModelLoader { + private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("entity/model/(\\w*)/(\\w*)\\.json"); + + private final ResourceManager manager; + private final Profiler profiler; + private final Map modelData = new HashMap<>(); + + public ModelLoader(ResourceManager manager, Profiler profiler) { + this.manager = manager; + this.profiler = profiler; + loadAnimations(); + } + + private void loadAnimations() { + profiler.push("Load Entity Models"); + Map resources = manager.findResources("model/entity", id -> id.getPath().endsWith(".json")); + for (Map.Entry entry : resources.entrySet()) { + addModel(entry.getKey(), entry.getValue()); + } + profiler.pop(); + } + + private void addModel(Identifier id, Resource resource) { + BufferedReader reader; + try { + reader = resource.openBufferedReader(); + } catch (IOException e) { + LOGGER.error(String.format("Unable to open BufferedReader for id %s", id), e); + return; + } + + JsonObject json = JsonHelper.deserialize(reader); + DataResult> result = Codecs.Model.TEXTURED_MODEL_DATA.decode(JsonOps.INSTANCE, json); + + if (result.error().isPresent()) { + LOGGER.error(String.format("Unable to parse entity model file %s.\nReason: %s", id, result.error().get().message())); + return; + } + + Matcher matcher = PATH_AND_NAME_PATTERN.matcher(id.getPath()); + if (!matcher.find()) { + LOGGER.error(String.format("Unable create model layer for entity model file %s.", id)); + return; + } + + String path = matcher.group(1); + String name = matcher.group(2); + + Identifier modelID = new Identifier(id.getNamespace(), path); + modelData.put(new EntityModelLayer(modelID, name), result.result().get().getFirst()); + } + + public Map getModelData() { + return modelData; + } + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java index 245b5854f7..85748ef25f 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.impl; import org.quiltmc.loader.api.ModContainer; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java index 4049d1d237..1da1511cde 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.spongepowered.asm.mixin.Mixin; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java new file mode 100644 index 0000000000..7aca7be359 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.client.model.ModelPart; +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.resource.ResourceType; + +@Mixin(EntityModelLoader.class) +public class EntityModelLoaderMixin { + @Unique + private DynamicEntityModelLoader quilt$dynamicEntityModelLoader; + + @Inject(method = "", at = @At("TAIL")) + private void createAnimationManager(CallbackInfo ci) { + this.quilt$dynamicEntityModelLoader = new DynamicEntityModelLoader(); + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(this.quilt$dynamicEntityModelLoader); + } + + @Inject(method = "getModelPart", at = @At("HEAD"), cancellable = true) + public void returnDynamicModel(EntityModelLayer layer, CallbackInfoReturnable cir) { + TexturedModelData modelData = quilt$dynamicEntityModelLoader.getModelData(layer); + if (modelData != null) { + cir.setReturnValue(modelData.createModel()); + } + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java index c2225fd4bd..35b1383bbe 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java @@ -1,7 +1,24 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; +import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -22,16 +39,16 @@ @Mixin(EntityRenderDispatcher.class) public class EntityRenderDispatcherMixin implements HasAnimationManager { @Unique - private AnimationManager animationManager; + private AnimationManager quilt$animationManager; @Inject(method = "", at = @At("TAIL")) private void createAnimationManager(MinecraftClient minecraftClient, TextureManager textureManager, ItemRenderer itemRenderer, BlockRenderManager blockRenderManager, TextRenderer textRenderer, GameOptions gameOptions, EntityModelLoader entityModelLoader, CallbackInfo ci) { - this.animationManager = new AnimationManager(); - ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(this.animationManager); + this.quilt$animationManager = new AnimationManager(); + ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(this.quilt$animationManager); } @Override public AnimationManager getAnimationManager() { - return animationManager; + return quilt$animationManager; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java index 0d6d4b3679..e591f4458f 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java @@ -1,39 +1,50 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; -import org.quiltmc.qsl.resource.loader.api.ResourceLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.option.GameOptions; import net.minecraft.client.render.block.BlockRenderManager; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.model.EntityModelLoader; import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.texture.TextureManager; import net.minecraft.resource.ResourceManager; -import net.minecraft.resource.ResourceType; @Mixin(EntityRendererFactory.Context.class) public class EntityRendererFactoryContextMixin implements HasAnimationManager { @Unique - private AnimationManager animationManager; + private AnimationManager quilt$animationManager; @Inject(method = "", at = @At("TAIL")) private void createAnimationManager(EntityRenderDispatcher entityRenderDispatcher, ItemRenderer itemRenderer, BlockRenderManager blockRenderManager, HeldItemRenderer heldItemRenderer, ResourceManager resourceManager, EntityModelLoader entityModelLoader, TextRenderer textRenderer, CallbackInfo ci) { - this.animationManager = entityRenderDispatcher.getAnimationManager(); + this.quilt$animationManager = ((HasAnimationManager) entityRenderDispatcher).getAnimationManager(); } @Override public AnimationManager getAnimationManager() { - return animationManager; + return quilt$animationManager; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index e3e9e8956f..a339bcbc0a 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.jetbrains.annotations.Nullable; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java index f29141ddc1..d5860e5549 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import net.minecraft.client.model.ModelCuboidData; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java index e1df28f04f..53a4f7bcbe 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import net.minecraft.client.model.TextureDimensions; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java index 6ce7bfb9b3..3c3a1fd60d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import net.minecraft.client.model.ModelData; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java index fd4373f24b..7f6b91b2ad 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.spongepowered.asm.mixin.Mixin; diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index 6d224649c2..73d1054847 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_17", "client": [ "DilationAccessor", + "EntityModelLoaderMixin", "EntityRenderDispatcherMixin", "EntityRendererFactoryContextMixin", "ModelCuboidDataAccessor", From d9a6923354f5c8c313eb9ebbf91392b466bad3ad Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Fri, 5 Aug 2022 20:55:30 -0700 Subject: [PATCH 05/11] Entity Models load correctly + license properly --- build-logic/src/main/groovy/qsl.module.gradle | 1 + .../extension/QslModuleExtensionImpl.java | 1 + codeformat/FOUNDATION_GAMES_MODIFIED_HEADER | 26 +++++++ library/rendering/entity_models/build.gradle | 7 +- .../rendering/entity_models/api/Codecs.java | 13 +++- .../impl/DynamicEntityModelLoader.java | 2 +- .../impl/LazyTypeUnboundedMapCodec.java | 76 +++++++++++++++++++ .../QuiltEntityModelsClientInitializer.java | 26 ------- .../entity_models/mixin/DilationAccessor.java | 9 +++ .../mixin/EntityModelLoaderMixin.java | 5 +- .../mixin/ModelCuboidDataAccessor.java | 9 +++ .../mixin/ModelPartDataAccessor.java | 9 +++ .../mixin/TextureDimensionsAccessor.java | 9 +++ .../mixin/TexturedModelDataAccessor.java | 9 +++ .../resources/quilt_entity_models.mixins.json | 1 + .../minecraft/model/entity/elytra/main.json | 53 +++++++++++++ 16 files changed, 220 insertions(+), 36 deletions(-) create mode 100644 codeformat/FOUNDATION_GAMES_MODIFIED_HEADER create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java delete mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java create mode 100644 library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json diff --git a/build-logic/src/main/groovy/qsl.module.gradle b/build-logic/src/main/groovy/qsl.module.gradle index 8fc8b970e8..97600a0be7 100644 --- a/build-logic/src/main/groovy/qsl.module.gradle +++ b/build-logic/src/main/groovy/qsl.module.gradle @@ -192,6 +192,7 @@ javadoc { license { rule rootProject.file("codeformat/COLONEL_MODIFIED_HEADER") rule rootProject.file("codeformat/FABRIC_MODIFIED_HEADER") + rule rootProject.file("codeformat/FOUNDATION_GAMES_MODIFIED_HEADER") rule rootProject.file("codeformat/HEADER") include "**/*.java" diff --git a/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java b/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java index bd1220fe7c..46ae35b5f4 100644 --- a/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java +++ b/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java @@ -132,6 +132,7 @@ public void entrypoints(Action> c @Override public void injectedInterface(String minecraftClass, Action action) { action.execute(this.injectedInterfaces.create(minecraftClass)); + this.allowGenTasks(); } @Nested diff --git a/codeformat/FOUNDATION_GAMES_MODIFIED_HEADER b/codeformat/FOUNDATION_GAMES_MODIFIED_HEADER new file mode 100644 index 0000000000..000623e5d4 --- /dev/null +++ b/codeformat/FOUNDATION_GAMES_MODIFIED_HEADER @@ -0,0 +1,26 @@ +Copyright 2021 FoundationGames + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +Copyright ${YEAR} QuiltMC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +;;match_from: \/\*\r?\n \* Copyright 2021 FoundationGames +;;match_from: \/\/\/ F[Oo][Uu][Nn][Dd][Aa][Tt][Ii][Oo][Nn] +;;year_display: lenient_range \ No newline at end of file diff --git a/library/rendering/entity_models/build.gradle b/library/rendering/entity_models/build.gradle index 7b182150de..d0780d55bc 100644 --- a/library/rendering/entity_models/build.gradle +++ b/library/rendering/entity_models/build.gradle @@ -6,7 +6,7 @@ qslModule { name = "Quilt Entity Model API" moduleName = "entity_models" id = "quilt_entity_models" - description = "Adds data driven entity models and animations" + description = "Adds data driven entity models and animations." library = "rendering" moduleDependencies { core { @@ -14,11 +14,6 @@ qslModule { impl("resource_loader") } } - entrypoints { - client_init { - values = ["org.quiltmc.qsl.rendering.entity_models.impl.QuiltEntityModelsClientInitializer"] - } - } injectedInterface("net/minecraft/class_898") { values = ["org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager"] } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 86b758b69a..c9a96fc363 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,6 +33,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.quiltmc.qsl.rendering.entity_models.impl.LazyTypeUnboundedMapCodec; import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; @@ -132,14 +142,13 @@ private static ModelCuboidData createCuboidData(Optional name, Vec3f off instance.group( MODEL_TRANSFORM.optionalFieldOf("transform", ModelTransform.NONE).forGetter(obj -> ((ModelPartDataAccessor) obj).transform()), Codec.list(MODEL_CUBOID_DATA).fieldOf("cuboids").forGetter(obj -> ((ModelPartDataAccessor) obj).cuboids()), - Codec.unboundedMap(Codec.STRING, Model.MODEL_PART_DATA).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((ModelPartDataAccessor) obj).children()) + LazyTypeUnboundedMapCodec.of(Codec.STRING, () -> Model.MODEL_PART_DATA).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((ModelPartDataAccessor) obj).children()) ).apply(instance, (transform, cuboids, children) -> { var data = ModelPartDataAccessor.create(cuboids, transform); ((ModelPartDataAccessor) data).children().putAll(children); return data; }) ); - ; public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create((instance) -> instance.group( diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index a12433b694..bd34fc2a64 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -69,7 +69,7 @@ public Identifier getQuiltId() { } public static class ModelLoader { - private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("entity/model/(\\w*)/(\\w*)\\.json"); + private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("model/entity/(\\w*)/(\\w*)\\.json"); private final ResourceManager manager; private final Profiler profiler; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java new file mode 100644 index 0000000000..b436bb29db --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java @@ -0,0 +1,76 @@ +/* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.rendering.entity_models.impl; + +import java.util.Map; +import java.util.function.Supplier; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.Lifecycle; +import com.mojang.serialization.codecs.BaseMapCodec; + +public class LazyTypeUnboundedMapCodec implements BaseMapCodec, Codec> { + private final Codec keyCodec; + private final Supplier> elementCodecProvider; + + private Codec elementCodec; + + public LazyTypeUnboundedMapCodec(Codec keyCodec, Supplier> elementCodecProvider) { + this.keyCodec = keyCodec; + this.elementCodecProvider = elementCodecProvider; + } + + public static LazyTypeUnboundedMapCodec of(Codec keyCodec, Supplier> elementCodecProvider) { + return new LazyTypeUnboundedMapCodec<>(keyCodec, elementCodecProvider); + } + + @Override + public DataResult, T>> decode(DynamicOps ops, T input) { + return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> decode(ops, map)).map(r -> Pair.of(r, input)); + } + + @Override + public DataResult encode(Map input, DynamicOps ops, T prefix) { + return encode(input, ops, ops.mapBuilder()).build(prefix); + } + + @Override + public Codec keyCodec() { + return keyCodec; + } + + @Override + public Codec elementCodec() { + if (elementCodec == null) { + elementCodec = elementCodecProvider.get(); + } + + return elementCodec; + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java deleted file mode 100644 index 85748ef25f..0000000000 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/QuiltEntityModelsClientInitializer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2022 QuiltMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.quiltmc.qsl.rendering.entity_models.impl; - -import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; - -public class QuiltEntityModelsClientInitializer implements ClientModInitializer { - @Override - public void onInitializeClient(ModContainer mod) { - } -} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java index 1da1511cde..900d93c44b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java index 7aca7be359..a2d02e207d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java @@ -19,6 +19,7 @@ import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; +import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +41,9 @@ public class EntityModelLoaderMixin { @Inject(method = "", at = @At("TAIL")) private void createAnimationManager(CallbackInfo ci) { this.quilt$dynamicEntityModelLoader = new DynamicEntityModelLoader(); - ResourceLoader.get(ResourceType.CLIENT_RESOURCES).registerReloader(this.quilt$dynamicEntityModelLoader); + ResourceLoader resourceLoader = ResourceLoader.get(ResourceType.CLIENT_RESOURCES); + resourceLoader.registerReloader(this.quilt$dynamicEntityModelLoader); + resourceLoader.addReloaderOrdering(this.quilt$dynamicEntityModelLoader.getQuiltId(), ResourceReloaderKeys.Client.ENTITY_MODELS); } @Inject(method = "getModelPart", at = @At("HEAD"), cancellable = true) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index a339bcbc0a..3df2add07c 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java index d5860e5549..6ab0f55dc0 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java index 53a4f7bcbe..f4b826360d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java index 3c3a1fd60d..f3094e258b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -1,4 +1,13 @@ /* + * Copyright 2021 FoundationGames + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * * Copyright 2022 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index 73d1054847..7649fff6cb 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -2,6 +2,7 @@ "required": true, "package": "org.quiltmc.qsl.rendering.entity_models.mixin", "compatibilityLevel": "JAVA_17", + "mixins": [], "client": [ "DilationAccessor", "EntityModelLoaderMixin", diff --git a/library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json b/library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json new file mode 100644 index 0000000000..d830c32b2e --- /dev/null +++ b/library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json @@ -0,0 +1,53 @@ +{ + "texture": { + "width": 64, + "height": 32 + }, + "bones": { + "right_wing": { + "transform": { + "origin": [-5.0, 0.0, 0.0], + "rotation": [0.2617994, 0.0, 0.2617994] + }, + "cuboids": [ + { + "dilation": [1.0, 1.0, 1.0], + "mirror": true, + "uv": [22.0, 0.0], + "offset": [0.0, 0.0, 0.0], + "dimensions": [10.0, 20.0, 2.0] + } + ] + }, + "left_wing": { + "transform": { + "origin": [5.0, 0.0, 0.0], + "rotation": [0.2617994, 0.0, -0.2617994] + }, + "cuboids": [ + { + "dilation": [1.0, 1.0, 1.0], + "uv": [22.0, 0.0], + "offset": [-10.0, 0.0, 0.0], + "dimensions": [10.0, 20.0, 2.0] + } + ], + "children" : { + "extra_cube" : { + "transform": { + "origin": [6.0, 1.0, 1.0], + "rotation": [0.2617994, 0.0, -0.2617994] + }, + "cuboids" : [ + { + "dilation": [1.0, 1.0, 1.0], + "uv": [22.0, 0.0], + "offset": [-10.0, 0.0, 0.0], + "dimensions": [10.0, 20.0, 2.0] + } + ] + } + } + } + } +} \ No newline at end of file From 7600a62d68c4317fd88a3f2a6d7f0536e54509e5 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Fri, 23 Sep 2022 12:12:41 -0700 Subject: [PATCH 06/11] Documentation + Cleanup --- .../entity_models/api/AnimationManager.java | 17 ++++++++++++++-- .../entity_models/api/AnimationUtils.java | 20 +++++++++---------- .../rendering/entity_models/api/Codecs.java | 3 +++ .../api/HasAnimationManager.java | 10 +++++++++- .../entity_models/api/package-info.java | 9 +++++++++ .../impl/DynamicEntityModelLoader.java | 4 ++-- .../mixin/ModelCuboidDataAccessor.java | 2 +- .../mixin/ModelPartDataAccessor.java | 2 +- .../mixin/TexturedModelDataAccessor.java | 2 +- .../{model => models}/entity/elytra/main.json | 0 10 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java rename library/rendering/entity_models/src/testmod/resources/assets/minecraft/{model => models}/entity/elytra/main.json (100%) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java index c828a02a8c..19b0f7833a 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java @@ -28,22 +28,35 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.minecraft.client.render.animation.Animation; +import net.minecraft.client.render.entity.model.EntityModelLayer; import net.minecraft.resource.Resource; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.profiler.Profiler; +/** + * A class that loads and holds {@link Animation}s. + * + * See {@link net.minecraft.client.render.entity.model.EntityModelLoader#getModelPart(EntityModelLayer)} for a similar usage. + */ public class AnimationManager implements SimpleResourceReloader { private static final Logger LOGGER = LoggerFactory.getLogger("Quilt Animation Manager"); private Map animations; - public Animation getAnimation(Identifier id) { + /** + * + * @param id The animation ID + * @return An animation if found, or null otherwise + */ + public @Nullable Animation getAnimation(Identifier id) { return animations.get(id); } @@ -60,7 +73,7 @@ public CompletableFuture apply(AnimationLoader prepared, ResourceManager m } @Override - public Identifier getQuiltId() { + public @NotNull Identifier getQuiltId() { return new Identifier("quilt_entity_models", "animation_reloader"); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java index 31538199c6..a31ac7a200 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java @@ -16,19 +16,18 @@ package org.quiltmc.qsl.rendering.entity_models.api; -import java.util.Map; import java.util.Optional; -import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; -import net.minecraft.client.render.animation.Animation; import net.minecraft.client.render.animation.PartAnimation; -import net.minecraft.resource.pack.ResourcePack; -import net.minecraft.util.Identifier; +/** + * A class that stores a {@link BiMap} of strings to {@link PartAnimation.Interpolator}s + */ public class AnimationUtils { - private static final Map INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); - private static final Map INVERSE_INTERPOLATORS = new Object2ObjectLinkedOpenHashMap<>(); + private static final BiMap INTERPOLATORS = HashBiMap.create(); static { registerInterpolation("LINEAR", PartAnimation.Interpolators.LINEAR); @@ -38,12 +37,11 @@ public class AnimationUtils { public static void registerInterpolation(String name, PartAnimation.Interpolator interpolator) { if (INTERPOLATORS.containsKey(name)) { throw new IllegalArgumentException(name + " already used as name"); - } else if (INVERSE_INTERPOLATORS.containsKey(interpolator)) { - throw new IllegalArgumentException("Interpolator already assigned to " + INVERSE_INTERPOLATORS.get(interpolator)); + } else if (INTERPOLATORS.containsValue(interpolator)) { + throw new IllegalArgumentException("Interpolator already assigned to " + INTERPOLATORS.inverse().get(interpolator)); } INTERPOLATORS.put(name, interpolator); - INVERSE_INTERPOLATORS.put(interpolator, name); } public static Optional getInterpolatorFromName(String name) { @@ -51,6 +49,6 @@ public static Optional getInterpolatorFromName(Strin } public static Optional getNameForInterpolator(PartAnimation.Interpolator interpolator) { - return Optional.ofNullable(INVERSE_INTERPOLATORS.get(interpolator)); + return Optional.ofNullable(INTERPOLATORS.inverse().get(interpolator)); } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index c9a96fc363..53fdb0efa1 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -54,6 +54,9 @@ import net.minecraft.util.Util; import net.minecraft.util.math.Vec3f; +/** + * Codecs for loading {@link Animation}s and {@link net.minecraft.client.render.entity.model.TexturedModelData}s. + */ public class Codecs { public static final class Animations { public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> instance.group( diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java index ae46b84ebc..edfa562bc3 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java @@ -16,15 +16,23 @@ package org.quiltmc.qsl.rendering.entity_models.api; +import org.jetbrains.annotations.NotNull; import org.quiltmc.qsl.base.api.util.InjectedInterface; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRendererFactory; + +/** + * An injected interface for classes that have an {@link AnimationManager} + */ @InjectedInterface(value = { EntityRenderDispatcher.class, EntityRendererFactory.Context.class }) public interface HasAnimationManager { - AnimationManager getAnimationManager(); + /** + * @return The animation manager for this instance + */ + @NotNull AnimationManager getAnimationManager(); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java new file mode 100644 index 0000000000..1311db13cb --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java @@ -0,0 +1,9 @@ +/** + * This API is responsible for loading {@link net.minecraft.client.render.animation.Animation Animations} and {@link net.minecraft.client.model.TexturedModelData Models} from assets. + * + *

Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.AnimationManager AnimationManager} with an identifier. + * + *

Models are loaded from {@code assets/[namespace]/models/entity/[path]/[layer_name].json}. Models can be automatically retrieved from the {@link net.minecraft.client.render.entity.model.EntityModelLoader EntityModelLoader} with the proper {@link net.minecraft.client.render.entity.model.EntityModelLayer EntityModelLayer}. + */ + +package org.quiltmc.qsl.rendering.entity_models.api; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index bd34fc2a64..94b2e9e003 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -69,7 +69,7 @@ public Identifier getQuiltId() { } public static class ModelLoader { - private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("model/entity/(\\w*)/(\\w*)\\.json"); + private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("models\\/entity\\/((\\w|\\/)*)\\/(\\w*)\\.json"); private final ResourceManager manager; private final Profiler profiler; @@ -83,7 +83,7 @@ public ModelLoader(ResourceManager manager, Profiler profiler) { private void loadAnimations() { profiler.push("Load Entity Models"); - Map resources = manager.findResources("model/entity", id -> id.getPath().endsWith(".json")); + Map resources = manager.findResources("models/entity", id -> id.getPath().endsWith(".json")); for (Map.Entry entry : resources.entrySet()) { addModel(entry.getKey(), entry.getValue()); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index 3df2add07c..b01421f4ab 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -61,6 +61,6 @@ public interface ModelCuboidDataAccessor { @Invoker("") static ModelCuboidData create(@Nullable String string, float f, float g, float h, float i, float j, float k, float l, float m, Dilation dilation, boolean bl, float n, float o){ - throw new AssertionError("Unreachable"); + throw new AssertionError("Mixin injection failed."); } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java index 6ab0f55dc0..d3a8b6dd36 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -48,6 +48,6 @@ public interface ModelPartDataAccessor { @Invoker("") static ModelPartData create(List cuboids, ModelTransform rotation) { - throw new AssertionError("mixin broke"); + throw new AssertionError("Mixin injection failed."); } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java index f3094e258b..f34f067502 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -42,6 +42,6 @@ public interface TexturedModelDataAccessor { @Invoker("") static TexturedModelData create(ModelData data, TextureDimensions dimensions) { - throw new AssertionError("mixin broke"); + throw new AssertionError("Mixin injection failed."); } } diff --git a/library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json b/library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json similarity index 100% rename from library/rendering/entity_models/src/testmod/resources/assets/minecraft/model/entity/elytra/main.json rename to library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json From 38f44a0e3d78415b13ad44692c046320bafe5a5c Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Wed, 28 Sep 2022 14:14:52 -0700 Subject: [PATCH 07/11] Fix some issues --- .../entity_models/api/AnimationManager.java | 7 +- .../rendering/entity_models/api/Codecs.java | 99 +++++++++++-------- .../api/HasAnimationManager.java | 2 +- .../impl/DynamicEntityModelLoader.java | 9 +- 4 files changed, 65 insertions(+), 52 deletions(-) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java index 19b0f7833a..ba566f960e 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java @@ -85,14 +85,14 @@ public static class AnimationLoader { public AnimationLoader(ResourceManager manager, Profiler profiler) { this.manager = manager; this.profiler = profiler; - loadAnimations(); + this.loadAnimations(); } private void loadAnimations() { profiler.push("Load Animations"); Map resources = manager.findResources("animations", id -> id.getPath().endsWith(".json")); for (Map.Entry entry : resources.entrySet()) { - addAnimation(entry.getKey(), entry.getValue()); + this.addAnimation(entry.getKey(), entry.getValue()); } profiler.pop(); } @@ -114,7 +114,8 @@ private void addAnimation(Identifier id, Resource resource) { return; } - animations.put(new Identifier(id.getNamespace(), id.getPath().substring("animations/".length())), result.result().get().getFirst()); + Identifier animationId = new Identifier(id.getNamespace(), id.getPath().substring("animations/".length())); + animations.put(animationId, result.result().get().getFirst()); } public Map getAnimations() { diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 53fdb0efa1..74f550cd13 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -59,51 +59,57 @@ */ public class Codecs { public static final class Animations { - public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), - Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), - Codec.STRING.flatXmap( - s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), - i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) - ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) - ).apply(instance, AnimationKeyframe::new)); - - public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> instance.group( - Codec.STRING.flatXmap(s -> switch (s) { - case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); - case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); - case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); - default -> DataResult.error("Unknown transformation: " + s); - }, transformation -> { - if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { - return DataResult.success("TRANSLATE"); - } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { - return DataResult.success("ROTATE"); - } else if (transformation == PartAnimation.AnimationTargets.SCALE) { - return DataResult.success("SCALE"); - } else { - return DataResult.error("Unknown transformation"); - } - }).fieldOf("transformation").forGetter(PartAnimation::transformation), - Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) - ).apply(instance, PartAnimation::new)); - - public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), - Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), - Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) - ).apply(instance, Animation::new)); + public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> + instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), + Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), + Codec.STRING.flatXmap( + s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), + i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) + ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) + ).apply(instance, AnimationKeyframe::new) + ); + + public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> + instance.group( + Codec.STRING.flatXmap(s -> switch (s) { + case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); + case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); + case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); + default -> DataResult.error("Unknown transformation: " + s); + }, transformation -> { + if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { + return DataResult.success("TRANSLATE"); + } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { + return DataResult.success("ROTATE"); + } else if (transformation == PartAnimation.AnimationTargets.SCALE) { + return DataResult.success("SCALE"); + } else { + return DataResult.error("Unknown transformation"); + } + }).fieldOf("transformation").forGetter(PartAnimation::transformation), + Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) + ).apply(instance, PartAnimation::new) + ); + + public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> + instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), + Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), + Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) + ).apply(instance, Animation::new) + ); } public static final class Model { - public static final Codec TEXTURE_DIMENSIONS = RecordCodecBuilder.create((instance) -> + public static final Codec TEXTURE_DIMENSIONS = RecordCodecBuilder.create(instance -> instance.group( Codec.INT.fieldOf("width").forGetter(obj -> ((TextureDimensionsAccessor) obj).width()), Codec.INT.fieldOf("height").forGetter(obj -> ((TextureDimensionsAccessor) obj).height()) ).apply(instance, TextureDimensions::new) ); - public static final Codec MODEL_TRANSFORM = RecordCodecBuilder.create((instance) -> + public static final Codec MODEL_TRANSFORM = RecordCodecBuilder.create(instance -> instance.group( Vec3f.CODEC.optionalFieldOf("origin", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pivotX, obj.pivotY, obj.pivotZ)), Vec3f.CODEC.optionalFieldOf("rotation", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pitch, obj.yaw, obj.roll)) @@ -118,18 +124,25 @@ public static final class Model { ((DilationAccessor) dil).radiusZ()) ); - public static final Codec VECTOR2F = Codec.FLOAT.listOf().comapFlatMap((vec) -> - Util.fixedSizeList(vec, 2).map((arr) -> new Vector2f(arr.get(0), arr.get(1))), - (vec) -> ImmutableList.of(vec.getX(), vec.getY()) + public static final Codec VECTOR2F = Codec.FLOAT.listOf().comapFlatMap(vec -> + Util.fixedSizeList(vec, 2).map((arr) -> new Vector2f(arr.get(0), arr.get(1))), + vec -> ImmutableList.of(vec.getX(), vec.getY()) ); private static ModelCuboidData createCuboidData(Optional name, Vec3f offset, Vec3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize) { - return ModelCuboidDataAccessor.create(name.orElse(null), uv.getX(), uv.getY(), offset.getX(), offset.getY(), offset.getZ(), dimensions.getX(), dimensions.getY(), dimensions.getZ(), dilation, mirror, uvSize.getX(), uvSize.getY()); + return ModelCuboidDataAccessor.create( + name.orElse(null), + uv.getX(), uv.getY(), + offset.getX(), offset.getY(), offset.getZ(), + dimensions.getX(), dimensions.getY(), dimensions.getZ(), + dilation, + mirror, + uvSize.getX(), uvSize.getY()); } private static final Vector2f DEFAULT_UV_SCALE = new Vector2f(1.0f, 1.0f); - public static final Codec MODEL_CUBOID_DATA = RecordCodecBuilder.create((instance) -> + public static final Codec MODEL_CUBOID_DATA = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.optionalFieldOf("name").forGetter(obj -> Optional.ofNullable(((ModelCuboidDataAccessor) (Object) obj).name())), Vec3f.CODEC.fieldOf("offset").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).offset()), @@ -141,7 +154,7 @@ private static ModelCuboidData createCuboidData(Optional name, Vec3f off ).apply(instance, Model::createCuboidData) ); - public static final Codec MODEL_PART_DATA = RecordCodecBuilder.create((instance) -> + public static final Codec MODEL_PART_DATA = RecordCodecBuilder.create(instance -> instance.group( MODEL_TRANSFORM.optionalFieldOf("transform", ModelTransform.NONE).forGetter(obj -> ((ModelPartDataAccessor) obj).transform()), Codec.list(MODEL_CUBOID_DATA).fieldOf("cuboids").forGetter(obj -> ((ModelPartDataAccessor) obj).cuboids()), @@ -153,7 +166,7 @@ private static ModelCuboidData createCuboidData(Optional name, Vec3f off }) ); - public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create((instance) -> + public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create(instance -> instance.group( TEXTURE_DIMENSIONS.fieldOf("texture").forGetter(obj -> ((TexturedModelDataAccessor) obj).texture()), Codec.unboundedMap(Codec.STRING, MODEL_PART_DATA).fieldOf("bones").forGetter(obj -> ((ModelPartDataAccessor) ((TexturedModelDataAccessor) obj).root().getRoot()).children()) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java index edfa562bc3..fda8c16c64 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java @@ -32,7 +32,7 @@ }) public interface HasAnimationManager { /** - * @return The animation manager for this instance + * @return The {@link AnimationManager animation manager} for this instance */ @NotNull AnimationManager getAnimationManager(); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index 94b2e9e003..e767eb0081 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -59,8 +59,7 @@ public CompletableFuture load(ResourceManager manager, Profiler pro @Override public CompletableFuture apply(ModelLoader prepared, ResourceManager manager, Profiler profiler, Executor executor) { this.modelData = prepared.getModelData(); - return CompletableFuture.runAsync(() -> { - }); + return CompletableFuture.runAsync(() -> {}); } @Override @@ -78,14 +77,14 @@ public static class ModelLoader { public ModelLoader(ResourceManager manager, Profiler profiler) { this.manager = manager; this.profiler = profiler; - loadAnimations(); + this.loadModels(); } - private void loadAnimations() { + private void loadModels() { profiler.push("Load Entity Models"); Map resources = manager.findResources("models/entity", id -> id.getPath().endsWith(".json")); for (Map.Entry entry : resources.entrySet()) { - addModel(entry.getKey(), entry.getValue()); + this.addModel(entry.getKey(), entry.getValue()); } profiler.pop(); } From cf1552c622ad071269050b0ed0a4d1ce499c0f94 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 17 Dec 2022 13:43:35 -0800 Subject: [PATCH 08/11] Apply suggestions from code review Co-authored-by: Ennui Langeweile <85590273+EnnuiL@users.noreply.github.com> --- .../qsl/rendering/entity_models/api/package-info.java | 8 ++++---- .../src/main/resources/quilt_entity_models.mixins.json | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java index 1311db13cb..c08cd03f4f 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java @@ -1,9 +1,9 @@ /** * This API is responsible for loading {@link net.minecraft.client.render.animation.Animation Animations} and {@link net.minecraft.client.model.TexturedModelData Models} from assets. - * - *

Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.AnimationManager AnimationManager} with an identifier. - * - *

Models are loaded from {@code assets/[namespace]/models/entity/[path]/[layer_name].json}. Models can be automatically retrieved from the {@link net.minecraft.client.render.entity.model.EntityModelLoader EntityModelLoader} with the proper {@link net.minecraft.client.render.entity.model.EntityModelLayer EntityModelLayer}. + *

+ * Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.AnimationManager AnimationManager} with an identifier. + *

+ * Models are loaded from {@code assets/[namespace]/models/entity/[path]/[layer_name].json}. Models can be automatically retrieved from the {@link net.minecraft.client.render.entity.model.EntityModelLoader EntityModelLoader} with the proper {@link net.minecraft.client.render.entity.model.EntityModelLayer EntityModelLayer}. */ package org.quiltmc.qsl.rendering.entity_models.api; diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index 7649fff6cb..73d1054847 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -2,7 +2,6 @@ "required": true, "package": "org.quiltmc.qsl.rendering.entity_models.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [], "client": [ "DilationAccessor", "EntityModelLoaderMixin", From 96a6aab35311197ff58dd7cfc2ef68dc92115311 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 17 Dec 2022 15:41:12 -0800 Subject: [PATCH 09/11] Refactor system to allow multiple loaders --- build-logic/src/main/groovy/qsl.module.gradle | 2 +- ...HEADER => FOUNDATIONGAMES_MODIFIED_HEADER} | 0 library/rendering/entity_models/build.gradle | 10 +- .../entity_models/api/AnimationUtils.java | 54 ------- .../rendering/entity_models/api/Codecs.java | 152 +----------------- .../api/animation/AnimationCodecs.java | 39 +++++ .../animation/AnimationInterpolations.java | 59 +++++++ .../api/{ => animation}/AnimationManager.java | 4 +- .../AnimationManagerContainer.java} | 4 +- .../animation/AnimationTransformations.java | 60 +++++++ .../api/animation/AnimationType.java | 13 ++ .../api/animation/AnimationTypes.java | 38 +++++ .../api/animation/TypedAnimation.java | 15 ++ .../entity_models/api/model/ModelCodecs.java | 106 ++++++++++++ .../entity_models/api/model/ModelType.java | 13 ++ .../entity_models/api/model/ModelTypes.java | 37 +++++ .../entity_models/api/model/TypedModel.java | 15 ++ .../entity_models/api/package-info.java | 2 +- .../impl/DynamicEntityModelLoader.java | 5 +- .../entity_models/mixin/AnimationMixin.java | 25 +++ .../mixin/EntityModelLoaderMixin.java | 1 - .../mixin/EntityRenderDispatcherMixin.java | 9 +- .../EntityRendererFactoryContextMixin.java | 10 +- .../mixin/ModelCuboidDataAccessor.java | 6 +- .../mixin/TexturedModelDataMixin.java | 25 +++ .../resources/quilt_entity_models.mixins.json | 2 + .../minecraft/models/entity/elytra/main.json | 3 +- 27 files changed, 486 insertions(+), 223 deletions(-) rename codeformat/{FOUNDATION_GAMES_MODIFIED_HEADER => FOUNDATIONGAMES_MODIFIED_HEADER} (100%) delete mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java rename library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/{ => animation}/AnimationManager.java (96%) rename library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/{HasAnimationManager.java => animation/AnimationManagerContainer.java} (91%) create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java create mode 100644 library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java diff --git a/build-logic/src/main/groovy/qsl.module.gradle b/build-logic/src/main/groovy/qsl.module.gradle index 0813f39662..2124c65251 100644 --- a/build-logic/src/main/groovy/qsl.module.gradle +++ b/build-logic/src/main/groovy/qsl.module.gradle @@ -184,7 +184,7 @@ javadoc { license { rule rootProject.file("codeformat/COLONEL_MODIFIED_HEADER") rule rootProject.file("codeformat/FABRIC_MODIFIED_HEADER") - rule rootProject.file("codeformat/FOUNDATION_GAMES_MODIFIED_HEADER") + rule rootProject.file("codeformat/FOUNDATIONGAMES_MODIFIED_HEADER") rule rootProject.file("codeformat/HEADER") include "**/*.java" diff --git a/codeformat/FOUNDATION_GAMES_MODIFIED_HEADER b/codeformat/FOUNDATIONGAMES_MODIFIED_HEADER similarity index 100% rename from codeformat/FOUNDATION_GAMES_MODIFIED_HEADER rename to codeformat/FOUNDATIONGAMES_MODIFIED_HEADER diff --git a/library/rendering/entity_models/build.gradle b/library/rendering/entity_models/build.gradle index d0780d55bc..2f31925254 100644 --- a/library/rendering/entity_models/build.gradle +++ b/library/rendering/entity_models/build.gradle @@ -15,10 +15,16 @@ qslModule { } } injectedInterface("net/minecraft/class_898") { - values = ["org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager"] + values = ["org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer"] } injectedInterface("net/minecraft/class_5617\$class_5618") { - values = ["org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager"] + values = ["org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer"] + } + injectedInterface("net/minecraft/class_7184"){ + values = ["org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation"] + } + injectedInterface("net/minecraft/class_5607"){ + values = ["org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel"] } clientOnly() } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java deleted file mode 100644 index a31ac7a200..0000000000 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2022 QuiltMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.quiltmc.qsl.rendering.entity_models.api; - -import java.util.Optional; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import net.minecraft.client.render.animation.PartAnimation; - -/** - * A class that stores a {@link BiMap} of strings to {@link PartAnimation.Interpolator}s - */ -public class AnimationUtils { - private static final BiMap INTERPOLATORS = HashBiMap.create(); - - static { - registerInterpolation("LINEAR", PartAnimation.Interpolators.LINEAR); - registerInterpolation("SPLINE", PartAnimation.Interpolators.SPLINE); - } - - public static void registerInterpolation(String name, PartAnimation.Interpolator interpolator) { - if (INTERPOLATORS.containsKey(name)) { - throw new IllegalArgumentException(name + " already used as name"); - } else if (INTERPOLATORS.containsValue(interpolator)) { - throw new IllegalArgumentException("Interpolator already assigned to " + INTERPOLATORS.inverse().get(interpolator)); - } - - INTERPOLATORS.put(name, interpolator); - } - - public static Optional getInterpolatorFromName(String name) { - return Optional.ofNullable(INTERPOLATORS.get(name)); - } - - public static Optional getNameForInterpolator(PartAnimation.Interpolator interpolator) { - return Optional.ofNullable(INTERPOLATORS.inverse().get(interpolator)); - } -} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 74f550cd13..6b242ac236 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -25,156 +25,16 @@ package org.quiltmc.qsl.rendering.entity_models.api; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Optional; +import java.util.List; -import com.google.common.collect.ImmutableList; import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import org.quiltmc.qsl.rendering.entity_models.impl.LazyTypeUnboundedMapCodec; -import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.TextureDimensionsAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.TexturedModelDataAccessor; +import org.joml.Vector3f; -import net.minecraft.client.model.Dilation; -import net.minecraft.client.model.ModelCuboidData; -import net.minecraft.client.model.ModelData; -import net.minecraft.client.model.ModelPartData; -import net.minecraft.client.model.ModelTransform; -import net.minecraft.client.model.TextureDimensions; -import net.minecraft.client.model.TexturedModelData; -import net.minecraft.client.render.animation.Animation; -import net.minecraft.client.render.animation.AnimationKeyframe; -import net.minecraft.client.render.animation.PartAnimation; -import net.minecraft.client.util.math.Vector2f; import net.minecraft.util.Util; -import net.minecraft.util.math.Vec3f; -/** - * Codecs for loading {@link Animation}s and {@link net.minecraft.client.render.entity.model.TexturedModelData}s. - */ -public class Codecs { - public static final class Animations { - public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> - instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), - Vec3f.CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), - Codec.STRING.flatXmap( - s -> AnimationUtils.getInterpolatorFromName(s).map(DataResult::success).orElseGet(() -> DataResult.error("Unknown interpolator: " + s)), - i -> AnimationUtils.getNameForInterpolator(i).map(DataResult::success).orElse(DataResult.error("Unknown interpolator")) - ).fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) - ).apply(instance, AnimationKeyframe::new) - ); - - public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> - instance.group( - Codec.STRING.flatXmap(s -> switch (s) { - case "TRANSLATE" -> DataResult.success(PartAnimation.AnimationTargets.TRANSLATE); - case "ROTATE" -> DataResult.success(PartAnimation.AnimationTargets.ROTATE); - case "SCALE" -> DataResult.success(PartAnimation.AnimationTargets.SCALE); - default -> DataResult.error("Unknown transformation: " + s); - }, transformation -> { - if (transformation == PartAnimation.AnimationTargets.TRANSLATE) { - return DataResult.success("TRANSLATE"); - } else if (transformation == PartAnimation.AnimationTargets.ROTATE) { - return DataResult.success("ROTATE"); - } else if (transformation == PartAnimation.AnimationTargets.SCALE) { - return DataResult.success("SCALE"); - } else { - return DataResult.error("Unknown transformation"); - } - }).fieldOf("transformation").forGetter(PartAnimation::transformation), - Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) - ).apply(instance, PartAnimation::new) - ); - - public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> - instance.group( - Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), - Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), - Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) - ).apply(instance, Animation::new) - ); - } - - public static final class Model { - public static final Codec TEXTURE_DIMENSIONS = RecordCodecBuilder.create(instance -> - instance.group( - Codec.INT.fieldOf("width").forGetter(obj -> ((TextureDimensionsAccessor) obj).width()), - Codec.INT.fieldOf("height").forGetter(obj -> ((TextureDimensionsAccessor) obj).height()) - ).apply(instance, TextureDimensions::new) - ); - - public static final Codec MODEL_TRANSFORM = RecordCodecBuilder.create(instance -> - instance.group( - Vec3f.CODEC.optionalFieldOf("origin", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pivotX, obj.pivotY, obj.pivotZ)), - Vec3f.CODEC.optionalFieldOf("rotation", Vec3f.ZERO).forGetter(obj -> new Vec3f(obj.pitch, obj.yaw, obj.roll)) - ).apply(instance, (origin, rot) -> ModelTransform.of(origin.getX(), origin.getY(), origin.getZ(), rot.getX(), rot.getY(), rot.getZ())) - ); - - public static final Codec DILATION = Vec3f.CODEC.xmap( - vec -> new Dilation(vec.getX(), vec.getY(), vec.getZ()), - dil -> new Vec3f( - ((DilationAccessor) dil).radiusX(), - ((DilationAccessor) dil).radiusY(), - ((DilationAccessor) dil).radiusZ()) - ); - public static final Codec VECTOR2F = Codec.FLOAT.listOf().comapFlatMap(vec -> - Util.fixedSizeList(vec, 2).map((arr) -> new Vector2f(arr.get(0), arr.get(1))), - vec -> ImmutableList.of(vec.getX(), vec.getY()) - ); - - private static ModelCuboidData createCuboidData(Optional name, Vec3f offset, Vec3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize) { - return ModelCuboidDataAccessor.create( - name.orElse(null), - uv.getX(), uv.getY(), - offset.getX(), offset.getY(), offset.getZ(), - dimensions.getX(), dimensions.getY(), dimensions.getZ(), - dilation, - mirror, - uvSize.getX(), uvSize.getY()); - } - - private static final Vector2f DEFAULT_UV_SCALE = new Vector2f(1.0f, 1.0f); - - public static final Codec MODEL_CUBOID_DATA = RecordCodecBuilder.create(instance -> - instance.group( - Codec.STRING.optionalFieldOf("name").forGetter(obj -> Optional.ofNullable(((ModelCuboidDataAccessor) (Object) obj).name())), - Vec3f.CODEC.fieldOf("offset").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).offset()), - Vec3f.CODEC.fieldOf("dimensions").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dimensions()), - DILATION.optionalFieldOf("dilation", Dilation.NONE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dilation()), - Codec.BOOL.optionalFieldOf("mirror", false).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).mirror()), - VECTOR2F.fieldOf("uv").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uv()), - VECTOR2F.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uvScale()) - ).apply(instance, Model::createCuboidData) - ); - - public static final Codec MODEL_PART_DATA = RecordCodecBuilder.create(instance -> - instance.group( - MODEL_TRANSFORM.optionalFieldOf("transform", ModelTransform.NONE).forGetter(obj -> ((ModelPartDataAccessor) obj).transform()), - Codec.list(MODEL_CUBOID_DATA).fieldOf("cuboids").forGetter(obj -> ((ModelPartDataAccessor) obj).cuboids()), - LazyTypeUnboundedMapCodec.of(Codec.STRING, () -> Model.MODEL_PART_DATA).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((ModelPartDataAccessor) obj).children()) - ).apply(instance, (transform, cuboids, children) -> { - var data = ModelPartDataAccessor.create(cuboids, transform); - ((ModelPartDataAccessor) data).children().putAll(children); - return data; - }) - ); - - public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create(instance -> - instance.group( - TEXTURE_DIMENSIONS.fieldOf("texture").forGetter(obj -> ((TexturedModelDataAccessor) obj).texture()), - Codec.unboundedMap(Codec.STRING, MODEL_PART_DATA).fieldOf("bones").forGetter(obj -> ((ModelPartDataAccessor) ((TexturedModelDataAccessor) obj).root().getRoot()).children()) - ).apply(instance, (texture, bones) -> { - var data = new ModelData(); - ((ModelPartDataAccessor) data.getRoot()).children().putAll(bones); - return TexturedModelDataAccessor.create(data, texture); - }) - ); - } +public class Codecs { + public static final Codec VECTOR_3F_CODEC = Codec.list(Codec.FLOAT).comapFlatMap( + list -> Util.fixedSizeList(list, 3).map(listx -> new Vector3f(listx.get(0), listx.get(1), listx.get(2))), + vec3d -> List.of(vec3d.x(), vec3d.y(), vec3d.z())); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java new file mode 100644 index 0000000000..e0544cddd3 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java @@ -0,0 +1,39 @@ +package org.quiltmc.qsl.rendering.entity_models.api.animation; + +import java.util.Arrays; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.quiltmc.qsl.rendering.entity_models.api.Codecs; + +import net.minecraft.client.render.animation.Animation; +import net.minecraft.client.render.animation.AnimationKeyframe; +import net.minecraft.client.render.animation.PartAnimation; + +/** + * Codecs for animation loading + */ +public final class AnimationCodecs { + public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> + instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("timestamp").forGetter(AnimationKeyframe::timestamp), + Codecs.VECTOR_3F_CODEC.fieldOf("transformation").forGetter(AnimationKeyframe::transformation), + AnimationInterpolations.CODEC.fieldOf("interpolator").forGetter(AnimationKeyframe::interpolator) + ).apply(instance, AnimationKeyframe::new) + ); + + public static final Codec PART_ANIMATION = RecordCodecBuilder.create(instance -> + instance.group( + AnimationTransformations.CODEC.fieldOf("transformation").forGetter(PartAnimation::transformation), + Codec.list(KEYFRAME).xmap(list -> list.toArray(AnimationKeyframe[]::new), Arrays::asList).fieldOf("keyframes").forGetter(PartAnimation::keyframes) + ).apply(instance, PartAnimation::new) + ); + + public static final Codec ANIMATION = RecordCodecBuilder.create(instance -> + instance.group( + Codec.floatRange(0, Float.MAX_VALUE).fieldOf("length").forGetter(Animation::length), + Codec.BOOL.fieldOf("looping").forGetter(Animation::looping), + Codec.unboundedMap(Codec.STRING, Codec.list(PART_ANIMATION)).fieldOf("animations").forGetter(Animation::animations) + ).apply(instance, Animation::new) + ); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java new file mode 100644 index 0000000000..dfaff2cfec --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.rendering.entity_models.api.animation; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; + +import net.minecraft.client.render.animation.PartAnimation; +import net.minecraft.util.Identifier; + +/** + * A class for registering different {@link net.minecraft.client.render.animation.PartAnimation.Interpolator}s to + */ +public class AnimationInterpolations { + private static final BiMap INTERPOLATORS = HashBiMap.create(); + + public static final Codec CODEC = Identifier.CODEC.flatXmap(identifier -> { + PartAnimation.Interpolator type = INTERPOLATORS.get(identifier); + return type != null ? DataResult.success(type) : DataResult.error("Unknown interpolator: " + identifier); + }, type -> { + Identifier id = INTERPOLATORS.inverse().get(type); + return id != null ? DataResult.success(id) : DataResult.error("Unknown interpolator."); + }); + + static { + register("linear", PartAnimation.Interpolators.LINEAR); + register("spline", PartAnimation.Interpolators.SPLINE); + } + + public static void register(String name, PartAnimation.Interpolator interpolator) { + register(new Identifier(name), interpolator); + } + + public static void register(Identifier id, PartAnimation.Interpolator interpolator) { + if (INTERPOLATORS.containsKey(id)) { + throw new IllegalArgumentException(id + " already used as name"); + } else if (INTERPOLATORS.containsValue(interpolator)) { + throw new IllegalArgumentException("Interpolator already assigned to " + INTERPOLATORS.inverse().get(interpolator)); + } + + INTERPOLATORS.put(id, interpolator); + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java similarity index 96% rename from library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java rename to library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java index ba566f960e..c858e6a37d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.quiltmc.qsl.rendering.entity_models.api; +package org.quiltmc.qsl.rendering.entity_models.api.animation; import java.io.BufferedReader; import java.io.IOException; @@ -107,7 +107,7 @@ private void addAnimation(Identifier id, Resource resource) { } JsonObject json = JsonHelper.deserialize(reader); - DataResult> result = Codecs.Animations.ANIMATION.decode(JsonOps.INSTANCE, json); + DataResult> result = AnimationTypes.CODEC.decode(JsonOps.INSTANCE, json); if (result.error().isPresent()) { LOGGER.error(String.format("Unable to parse animation file %s.\nReason: %s", id, result.error().get().message())); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java similarity index 91% rename from library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java rename to library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java index fda8c16c64..ffd91c2709 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/HasAnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.quiltmc.qsl.rendering.entity_models.api; +package org.quiltmc.qsl.rendering.entity_models.api.animation; import org.jetbrains.annotations.NotNull; import org.quiltmc.qsl.base.api.util.InjectedInterface; @@ -30,7 +30,7 @@ EntityRenderDispatcher.class, EntityRendererFactory.Context.class }) -public interface HasAnimationManager { +public interface AnimationManagerContainer { /** * @return The {@link AnimationManager animation manager} for this instance */ diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java new file mode 100644 index 0000000000..24e0654a59 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.quiltmc.qsl.rendering.entity_models.api.animation; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; + +import net.minecraft.client.render.animation.PartAnimation; +import net.minecraft.util.Identifier; + +/** + * A for registering different {@link net.minecraft.client.render.animation.PartAnimation.Transformation}s to. + */ +public class AnimationTransformations { + private static final BiMap TRANSFORMATIONS = HashBiMap.create(); + + public static final Codec CODEC = Identifier.CODEC.flatXmap(identifier -> { + PartAnimation.Transformation type = TRANSFORMATIONS.get(identifier); + return type != null ? DataResult.success(type) : DataResult.error("Unknown transformation: " + identifier); + }, type -> { + Identifier id = TRANSFORMATIONS.inverse().get(type); + return id != null ? DataResult.success(id) : DataResult.error("Unknown transformation."); + }); + + static { + register("translate", PartAnimation.AnimationTargets.TRANSLATE); + register("rotate", PartAnimation.AnimationTargets.ROTATE); + register("scale", PartAnimation.AnimationTargets.SCALE); + } + + public static void register(String name, PartAnimation.Transformation transformation) { + register(new Identifier(name), transformation); + } + + public static void register(Identifier id, PartAnimation.Transformation transformation) { + if (TRANSFORMATIONS.containsKey(id)) { + throw new IllegalArgumentException(id + " already used as name"); + } else if (TRANSFORMATIONS.containsValue(transformation)) { + throw new IllegalArgumentException("Transformation already assigned to " + TRANSFORMATIONS.inverse().get(transformation)); + } + + TRANSFORMATIONS.put(id, transformation); + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java new file mode 100644 index 0000000000..670eb31dec --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java @@ -0,0 +1,13 @@ +package org.quiltmc.qsl.rendering.entity_models.api.animation; + +import com.mojang.serialization.Codec; + +import net.minecraft.client.render.animation.Animation; + +/** + * A type parameter that allows animations to be loaded in different ways. + * + * @param codec The codec to load an animation + */ +public record AnimationType(Codec codec) { +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java new file mode 100644 index 0000000000..7a287d02bc --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java @@ -0,0 +1,38 @@ +package org.quiltmc.qsl.rendering.entity_models.api.animation; + + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; + +import net.minecraft.client.render.animation.Animation; +import net.minecraft.util.Identifier; + +public class AnimationTypes { + private static final BiMap TYPES = HashBiMap.create(); + + public static final AnimationType QUILT_ANIMATION = register("quilt:animation", AnimationCodecs.ANIMATION); + + public static final Codec TYPE_CODEC = Identifier.CODEC.flatXmap(identifier -> { + AnimationType type = TYPES.get(identifier); + return type != null ? DataResult.success(type) : DataResult.error("Unknown animation type: " + identifier); + }, animationType -> { + Identifier id = TYPES.inverse().get(animationType); + return id != null ? DataResult.success(id) : DataResult.error("Unknown animation type."); + }); + public static Codec CODEC = TYPE_CODEC.dispatch(animation -> ((TypedAnimation) (Object) animation).getType(), AnimationType::codec); + + public static AnimationType register(String name, Codec codec) { + return register(new Identifier(name), codec); + } + public static AnimationType register(Identifier id, Codec codec) { + AnimationType type = new AnimationType(codec); + AnimationType old = TYPES.putIfAbsent(id, type); + if (old != null) { + throw new IllegalStateException("Duplicate registration for " + id); + } + + return type; + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java new file mode 100644 index 0000000000..bbd6b0f712 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java @@ -0,0 +1,15 @@ +package org.quiltmc.qsl.rendering.entity_models.api.animation; + +import org.quiltmc.qsl.base.api.util.InjectedInterface; + +import net.minecraft.client.render.animation.Animation; + +/** + * An injected interface on {@link net.minecraft.client.render.animation.Animation} to specify its type. + * Defaults to {@link org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationTypes#QUILT_ANIMATION}. + */ +@InjectedInterface(Animation.class) +public interface TypedAnimation { + AnimationType getType(); + void setType(AnimationType type); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java new file mode 100644 index 0000000000..8c0109242c --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java @@ -0,0 +1,106 @@ +package org.quiltmc.qsl.rendering.entity_models.api.model; + +import java.util.HashMap; +import java.util.Optional; + +import com.google.common.collect.ImmutableList; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.joml.Vector3f; +import org.quiltmc.qsl.rendering.entity_models.api.Codecs; +import org.quiltmc.qsl.rendering.entity_models.impl.LazyTypeUnboundedMapCodec; +import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TextureDimensionsAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TexturedModelDataAccessor; + +import net.minecraft.client.model.Dilation; +import net.minecraft.client.model.ModelCuboidData; +import net.minecraft.client.model.ModelData; +import net.minecraft.client.model.ModelPartData; +import net.minecraft.client.model.ModelTransform; +import net.minecraft.client.model.TextureDimensions; +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.client.util.math.Vector2f; +import net.minecraft.util.Util; + +/** + * Codecs for model loading. + */ +public final class ModelCodecs { + public static final Codec TEXTURE_DIMENSIONS = RecordCodecBuilder.create(instance -> + instance.group( + Codec.INT.fieldOf("width").forGetter(obj -> ((TextureDimensionsAccessor) obj).width()), + Codec.INT.fieldOf("height").forGetter(obj -> ((TextureDimensionsAccessor) obj).height()) + ).apply(instance, TextureDimensions::new) + ); + + public static final Codec MODEL_TRANSFORM = RecordCodecBuilder.create(instance -> + instance.group( + Codecs.VECTOR_3F_CODEC.optionalFieldOf("origin", new Vector3f()).forGetter(obj -> new Vector3f(obj.pivotX, obj.pivotY, obj.pivotZ)), + Codecs.VECTOR_3F_CODEC.optionalFieldOf("rotation", new Vector3f()).forGetter(obj -> new Vector3f(obj.pitch, obj.yaw, obj.roll)) + ).apply(instance, (origin, rot) -> ModelTransform.of(origin.x(), origin.y(), origin.z(), rot.x(), rot.y(), rot.z())) + ); + + public static final Codec DILATION = Codecs.VECTOR_3F_CODEC.xmap( + vec -> new Dilation(vec.x(), vec.y(), vec.z()), + dil -> new Vector3f( + ((DilationAccessor) dil).radiusX(), + ((DilationAccessor) dil).radiusY(), + ((DilationAccessor) dil).radiusZ()) + ); + + public static final Codec VECTOR2F = Codec.FLOAT.listOf().comapFlatMap(vec -> + Util.fixedSizeList(vec, 2).map((arr) -> new Vector2f(arr.get(0), arr.get(1))), + vec -> ImmutableList.of(vec.getX(), vec.getY()) + ); + + private static ModelCuboidData createCuboidData(Optional name, Vector3f offset, Vector3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize) { + return ModelCuboidDataAccessor.create( + name.orElse(null), + uv.getX(), uv.getY(), + offset.x(), offset.y(), offset.z(), + dimensions.x(), dimensions.y(), dimensions.z(), + dilation, + mirror, + uvSize.getX(), uvSize.getY()); + } + + private static final Vector2f DEFAULT_UV_SCALE = new Vector2f(1.0f, 1.0f); + + public static final Codec MODEL_CUBOID_DATA = RecordCodecBuilder.create(instance -> + instance.group( + Codec.STRING.optionalFieldOf("name").forGetter(obj -> Optional.ofNullable(((ModelCuboidDataAccessor) (Object) obj).name())), + Codecs.VECTOR_3F_CODEC.fieldOf("offset").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).offset()), + Codecs.VECTOR_3F_CODEC.fieldOf("dimensions").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dimensions()), + DILATION.optionalFieldOf("dilation", Dilation.NONE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dilation()), + Codec.BOOL.optionalFieldOf("mirror", false).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).mirror()), + VECTOR2F.fieldOf("uv").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uv()), + VECTOR2F.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uvScale()) + ).apply(instance, ModelCodecs::createCuboidData) + ); + + public static final Codec MODEL_PART_DATA = RecordCodecBuilder.create(instance -> + instance.group( + MODEL_TRANSFORM.optionalFieldOf("transform", ModelTransform.NONE).forGetter(obj -> ((ModelPartDataAccessor) obj).transform()), + Codec.list(MODEL_CUBOID_DATA).fieldOf("cuboids").forGetter(obj -> ((ModelPartDataAccessor) obj).cuboids()), + LazyTypeUnboundedMapCodec.of(Codec.STRING, () -> ModelCodecs.MODEL_PART_DATA).optionalFieldOf("children", new HashMap<>()).forGetter(obj -> ((ModelPartDataAccessor) obj).children()) + ).apply(instance, (transform, cuboids, children) -> { + var data = ModelPartDataAccessor.create(cuboids, transform); + ((ModelPartDataAccessor) data).children().putAll(children); + return data; + }) + ); + + public static final Codec TEXTURED_MODEL_DATA = RecordCodecBuilder.create(instance -> + instance.group( + TEXTURE_DIMENSIONS.fieldOf("texture").forGetter(obj -> ((TexturedModelDataAccessor) obj).texture()), + Codec.unboundedMap(Codec.STRING, MODEL_PART_DATA).fieldOf("bones").forGetter(obj -> ((ModelPartDataAccessor) ((TexturedModelDataAccessor) obj).root().getRoot()).children()) + ).apply(instance, (texture, bones) -> { + var data = new ModelData(); + ((ModelPartDataAccessor) data.getRoot()).children().putAll(bones); + return TexturedModelDataAccessor.create(data, texture); + }) + ); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java new file mode 100644 index 0000000000..cc3328226b --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java @@ -0,0 +1,13 @@ +package org.quiltmc.qsl.rendering.entity_models.api.model; + +import com.mojang.serialization.Codec; + +import net.minecraft.client.model.TexturedModelData; + +/** + * A type parameter that allows models to be loaded in different ways. + * + * @param codec The codec to load a model + */ +public record ModelType(Codec codec) { +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java new file mode 100644 index 0000000000..6ba6e0e0e6 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java @@ -0,0 +1,37 @@ +package org.quiltmc.qsl.rendering.entity_models.api.model; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; + +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.util.Identifier; + +public class ModelTypes { + private static final BiMap TYPES = HashBiMap.create(); + + public static final ModelType QUILT_MODEL = register("quilt:model", ModelCodecs.TEXTURED_MODEL_DATA); + + public static final Codec TYPE_CODEC = Identifier.CODEC.flatXmap(identifier -> { + ModelType type = TYPES.get(identifier); + return type != null ? DataResult.success(type) : DataResult.error("Unknown model type: " + identifier); + }, model -> { + Identifier id = TYPES.inverse().get(model); + return id != null ? DataResult.success(id) : DataResult.error("Unknown model type."); + }); + public static Codec CODEC = TYPE_CODEC.dispatch(model -> ((TypedModel) (Object) model).getType(), ModelType::codec); + + public static ModelType register(String name, Codec codec) { + return register(new Identifier(name), codec); + } + public static ModelType register(Identifier id, Codec codec) { + ModelType type = new ModelType(codec); + ModelType old = TYPES.putIfAbsent(id, type); + if (old != null) { + throw new IllegalStateException("Duplicate registration for " + id); + } + + return type; + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java new file mode 100644 index 0000000000..93a6a74fb1 --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java @@ -0,0 +1,15 @@ +package org.quiltmc.qsl.rendering.entity_models.api.model; + +import org.quiltmc.qsl.base.api.util.InjectedInterface; + +import net.minecraft.client.model.TexturedModelData; + +/** + * An injected interface on {@link net.minecraft.client.model.TexturedModelData} to specify its type. + * Defaults to {@link ModelTypes#QUILT_MODEL}. + */ +@InjectedInterface(TexturedModelData.class) +public interface TypedModel { + ModelType getType(); + void setType(ModelType type); +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java index c08cd03f4f..115451cc3d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java @@ -1,7 +1,7 @@ /** * This API is responsible for loading {@link net.minecraft.client.render.animation.Animation Animations} and {@link net.minecraft.client.model.TexturedModelData Models} from assets. *

- * Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.AnimationManager AnimationManager} with an identifier. + * Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager AnimationManager} with an identifier. *

* Models are loaded from {@code assets/[namespace]/models/entity/[path]/[layer_name].json}. Models can be automatically retrieved from the {@link net.minecraft.client.render.entity.model.EntityModelLoader EntityModelLoader} with the proper {@link net.minecraft.client.render.entity.model.EntityModelLayer EntityModelLayer}. */ diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index e767eb0081..a0a510bcb5 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -30,7 +30,8 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; -import org.quiltmc.qsl.rendering.entity_models.api.Codecs; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelCodecs; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +100,7 @@ private void addModel(Identifier id, Resource resource) { } JsonObject json = JsonHelper.deserialize(reader); - DataResult> result = Codecs.Model.TEXTURED_MODEL_DATA.decode(JsonOps.INSTANCE, json); + DataResult> result = ModelTypes.CODEC.decode(JsonOps.INSTANCE, json); if (result.error().isPresent()) { LOGGER.error(String.format("Unable to parse entity model file %s.\nReason: %s", id, result.error().get().message())); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java new file mode 100644 index 0000000000..66a8512a0b --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java @@ -0,0 +1,25 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationType; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationTypes; +import org.quiltmc.qsl.rendering.entity_models.api.animation.TypedAnimation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.client.render.animation.Animation; + +@Mixin(Animation.class) +public class AnimationMixin implements TypedAnimation { + @Unique + private AnimationType quilt$animationType = AnimationTypes.QUILT_ANIMATION; + + @Override + public AnimationType getType() { + return quilt$animationType; + } + + @Override + public void setType(AnimationType type) { + quilt$animationType = type; + } +} diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java index a2d02e207d..9512c9a3f9 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java @@ -16,7 +16,6 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java index 35b1383bbe..13b76eb5bd 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java @@ -16,9 +16,9 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; -import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; -import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; +import org.jetbrains.annotations.NotNull; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; import org.quiltmc.qsl.resource.loader.api.ResourceLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -37,7 +37,7 @@ import net.minecraft.resource.ResourceType; @Mixin(EntityRenderDispatcher.class) -public class EntityRenderDispatcherMixin implements HasAnimationManager { +public class EntityRenderDispatcherMixin implements AnimationManagerContainer { @Unique private AnimationManager quilt$animationManager; @@ -48,6 +48,7 @@ private void createAnimationManager(MinecraftClient minecraftClient, TextureMana } @Override + @NotNull public AnimationManager getAnimationManager() { return quilt$animationManager; } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java index e591f4458f..051acaca0c 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java @@ -16,8 +16,9 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.api.AnimationManager; -import org.quiltmc.qsl.rendering.entity_models.api.HasAnimationManager; +import org.jetbrains.annotations.NotNull; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,15 +35,16 @@ import net.minecraft.resource.ResourceManager; @Mixin(EntityRendererFactory.Context.class) -public class EntityRendererFactoryContextMixin implements HasAnimationManager { +public class EntityRendererFactoryContextMixin implements AnimationManagerContainer { @Unique private AnimationManager quilt$animationManager; @Inject(method = "", at = @At("TAIL")) private void createAnimationManager(EntityRenderDispatcher entityRenderDispatcher, ItemRenderer itemRenderer, BlockRenderManager blockRenderManager, HeldItemRenderer heldItemRenderer, ResourceManager resourceManager, EntityModelLoader entityModelLoader, TextRenderer textRenderer, CallbackInfo ci) { - this.quilt$animationManager = ((HasAnimationManager) entityRenderDispatcher).getAnimationManager(); + this.quilt$animationManager = ((AnimationManagerContainer) entityRenderDispatcher).getAnimationManager(); } + @NotNull @Override public AnimationManager getAnimationManager() { return quilt$animationManager; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index b01421f4ab..42743cc516 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -26,6 +26,7 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; @@ -33,7 +34,6 @@ import net.minecraft.client.model.Dilation; import net.minecraft.client.model.ModelCuboidData; import net.minecraft.client.util.math.Vector2f; -import net.minecraft.util.math.Vec3f; @Mixin(ModelCuboidData.class) public interface ModelCuboidDataAccessor { @@ -42,10 +42,10 @@ public interface ModelCuboidDataAccessor { String name(); @Accessor("offset") - Vec3f offset(); + Vector3f offset(); @Accessor("dimensions") - Vec3f dimensions(); + Vector3f dimensions(); @Accessor("extraSize") Dilation dilation(); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java new file mode 100644 index 0000000000..3cec022c8f --- /dev/null +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java @@ -0,0 +1,25 @@ +package org.quiltmc.qsl.rendering.entity_models.mixin; + +import org.quiltmc.qsl.rendering.entity_models.api.model.TypedModel; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelType; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +import net.minecraft.client.model.TexturedModelData; + +@Mixin(TexturedModelData.class) +public class TexturedModelDataMixin implements TypedModel { + @Unique + private ModelType quilt$modelType = ModelTypes.QUILT_MODEL; + + @Override + public ModelType getType() { + return quilt$modelType; + } + + @Override + public void setType(ModelType type) { + quilt$modelType = type; + } +} diff --git a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json index 73d1054847..046c264214 100644 --- a/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json +++ b/library/rendering/entity_models/src/main/resources/quilt_entity_models.mixins.json @@ -3,6 +3,7 @@ "package": "org.quiltmc.qsl.rendering.entity_models.mixin", "compatibilityLevel": "JAVA_17", "client": [ + "AnimationMixin", "DilationAccessor", "EntityModelLoaderMixin", "EntityRenderDispatcherMixin", @@ -11,6 +12,7 @@ "ModelPartDataAccessor", "TextureDimensionsAccessor", "TexturedModelDataAccessor", + "TexturedModelDataMixin", "Vector2fMixin" ], "injectors": { diff --git a/library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json b/library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json index d830c32b2e..0567c9303a 100644 --- a/library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json +++ b/library/rendering/entity_models/src/testmod/resources/assets/minecraft/models/entity/elytra/main.json @@ -1,4 +1,5 @@ { + "type": "quilt:model", "texture": { "width": 64, "height": 32 @@ -50,4 +51,4 @@ } } } -} \ No newline at end of file +} From 03903b9105538f2a732220c663c1f0644e5851b7 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Mon, 2 Jan 2023 19:05:27 -0800 Subject: [PATCH 10/11] maybe working? --- .../qsl/rendering/entity_models/api/Codecs.java | 2 +- .../api/animation/AnimationCodecs.java | 16 ++++++++++++++++ .../api/animation/AnimationInterpolations.java | 2 +- .../api/animation/AnimationManager.java | 2 +- .../api/animation/AnimationManagerContainer.java | 2 +- .../api/animation/AnimationTransformations.java | 2 +- .../api/animation/AnimationType.java | 16 ++++++++++++++++ .../api/animation/AnimationTypes.java | 16 ++++++++++++++++ .../api/animation/TypedAnimation.java | 16 ++++++++++++++++ .../entity_models/api/model/ModelCodecs.java | 16 ++++++++++++++++ .../entity_models/api/model/ModelType.java | 16 ++++++++++++++++ .../entity_models/api/model/ModelTypes.java | 16 ++++++++++++++++ .../entity_models/api/model/TypedModel.java | 16 ++++++++++++++++ .../impl/DynamicEntityModelLoader.java | 2 +- .../impl/LazyTypeUnboundedMapCodec.java | 2 +- .../entity_models/mixin/AnimationMixin.java | 16 ++++++++++++++++ .../entity_models/mixin/DilationAccessor.java | 2 +- .../mixin/EntityModelLoaderMixin.java | 2 +- .../mixin/EntityRenderDispatcherMixin.java | 2 +- .../mixin/EntityRendererFactoryContextMixin.java | 2 +- .../mixin/ModelCuboidDataAccessor.java | 2 +- .../mixin/ModelPartDataAccessor.java | 2 +- .../mixin/TextureDimensionsAccessor.java | 2 +- .../mixin/TexturedModelDataAccessor.java | 2 +- .../mixin/TexturedModelDataMixin.java | 16 ++++++++++++++++ .../entity_models/mixin/Vector2fMixin.java | 2 +- 26 files changed, 176 insertions(+), 16 deletions(-) diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 6b242ac236..8712e071e5 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java index e0544cddd3..708cb42ece 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.animation; import java.util.Arrays; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java index dfaff2cfec..d3eb25429b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java index c858e6a37d..db41c22772 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java index ffd91c2709..fa9c69baa0 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java index 24e0654a59..c4eea9436b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java index 670eb31dec..c252a29af1 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationType.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.animation; import com.mojang.serialization.Codec; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java index 7a287d02bc..d18bc84679 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.animation; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java index bbd6b0f712..f9c168679c 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.animation; import org.quiltmc.qsl.base.api.util.InjectedInterface; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java index 8c0109242c..e6ef68bcf7 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.model; import java.util.HashMap; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java index cc3328226b..bee3cb9a5b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelType.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.model; import com.mojang.serialization.Codec; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java index 6ba6e0e0e6..1438cbcb10 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.model; import com.google.common.collect.BiMap; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java index 93a6a74fb1..c67831550f 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.api.model; import org.quiltmc.qsl.base.api.util.InjectedInterface; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index a0a510bcb5..c0cae952e9 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java index b436bb29db..bdda66b6fe 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java index 66a8512a0b..c4188055a1 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationType; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java index 900d93c44b..38fae21f47 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java index 9512c9a3f9..99cb3cfd36 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java index 13b76eb5bd..e36b877bd0 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java index 051acaca0c..0768ece2d8 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index 42743cc516..c136cbd796 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java index d3a8b6dd36..e2b5f2a2c2 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java index f4b826360d..1c4381709d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java index f34f067502..d2a250a856 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -8,7 +8,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java index 3cec022c8f..9abe513c9a 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.quiltmc.qsl.rendering.entity_models.mixin; import org.quiltmc.qsl.rendering.entity_models.api.model.TypedModel; diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java index 7f6b91b2ad..377acb4d85 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 QuiltMC + * Copyright 2023 QuiltMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 7e43a07fcb702c185f83ab0898cc9a019b555cba Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Thu, 8 Jun 2023 16:22:24 -0700 Subject: [PATCH 11/11] Update to 1.20 --- .../extension/QslModuleExtensionImpl.java | 1 - library/rendering/entity_models/build.gradle | 1 - .../rendering/entity_models/api/Codecs.java | 1 - .../api/animation/AnimationCodecs.java | 5 +- .../animation/AnimationInterpolations.java | 6 +- .../api/animation/AnimationManager.java | 17 +++--- .../animation/AnimationManagerContainer.java | 4 +- .../animation/AnimationTransformations.java | 4 +- .../api/animation/AnimationTypes.java | 6 +- .../api/animation/TypedAnimation.java | 4 +- .../entity_models/api/model/ModelCodecs.java | 26 +++++---- .../entity_models/api/model/ModelTypes.java | 5 +- .../entity_models/api/model/TypedModel.java | 4 +- .../entity_models/api/package-info.java | 2 + .../impl/DynamicEntityModelLoader.java | 21 +++---- .../impl/LazyTypeUnboundedMapCodec.java | 58 +++++++++---------- .../entity_models/mixin/AnimationMixin.java | 11 ++-- .../entity_models/mixin/DilationAccessor.java | 12 ++-- .../mixin/EntityModelLoaderMixin.java | 39 +++++++------ .../mixin/EntityRenderDispatcherMixin.java | 9 +-- .../EntityRendererFactoryContextMixin.java | 7 ++- .../mixin/ModelCuboidDataAccessor.java | 39 +++++++------ .../mixin/ModelPartDataAccessor.java | 31 +++++----- .../mixin/TextureDimensionsAccessor.java | 11 ++-- .../mixin/TexturedModelDataAccessor.java | 23 ++++---- .../mixin/TexturedModelDataMixin.java | 11 ++-- .../entity_models/mixin/Vector2fMixin.java | 23 ++++---- 27 files changed, 202 insertions(+), 179 deletions(-) diff --git a/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java b/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java index da21e1f4da..cc010ee74e 100644 --- a/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java +++ b/build-logic/src/main/java/qsl/internal/extension/QslModuleExtensionImpl.java @@ -144,7 +144,6 @@ public void entrypoints(Action> c @Override public void injectedInterface(String minecraftClass, Action action) { action.execute(this.injectedInterfaces.create(minecraftClass)); - this.allowGenTasks(); } @Nested diff --git a/library/rendering/entity_models/build.gradle b/library/rendering/entity_models/build.gradle index 2f31925254..7c9b60de9a 100644 --- a/library/rendering/entity_models/build.gradle +++ b/library/rendering/entity_models/build.gradle @@ -7,7 +7,6 @@ qslModule { moduleName = "entity_models" id = "quilt_entity_models" description = "Adds data driven entity models and animations." - library = "rendering" moduleDependencies { core { api("qsl_base") diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java index 8712e071e5..817bf5f1d2 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/Codecs.java @@ -32,7 +32,6 @@ import net.minecraft.util.Util; - public class Codecs { public static final Codec VECTOR_3F_CODEC = Codec.list(Codec.FLOAT).comapFlatMap( list -> Util.fixedSizeList(list, 3).map(listx -> new Vector3f(listx.get(0), listx.get(1), listx.get(2))), diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java index 708cb42ece..d3394d7c0b 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationCodecs.java @@ -20,14 +20,15 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import org.quiltmc.qsl.rendering.entity_models.api.Codecs; import net.minecraft.client.render.animation.Animation; import net.minecraft.client.render.animation.AnimationKeyframe; import net.minecraft.client.render.animation.PartAnimation; +import org.quiltmc.qsl.rendering.entity_models.api.Codecs; + /** - * Codecs for animation loading + * Codecs for animation loading. */ public final class AnimationCodecs { public static final Codec KEYFRAME = RecordCodecBuilder.create(instance -> diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java index d3eb25429b..383f329887 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationInterpolations.java @@ -25,17 +25,17 @@ import net.minecraft.util.Identifier; /** - * A class for registering different {@link net.minecraft.client.render.animation.PartAnimation.Interpolator}s to + * A class for registering different {@link net.minecraft.client.render.animation.PartAnimation.Interpolator}s. */ public class AnimationInterpolations { private static final BiMap INTERPOLATORS = HashBiMap.create(); public static final Codec CODEC = Identifier.CODEC.flatXmap(identifier -> { PartAnimation.Interpolator type = INTERPOLATORS.get(identifier); - return type != null ? DataResult.success(type) : DataResult.error("Unknown interpolator: " + identifier); + return type != null ? DataResult.success(type) : DataResult.error(() -> "Unknown interpolator: " + identifier); }, type -> { Identifier id = INTERPOLATORS.inverse().get(type); - return id != null ? DataResult.success(id) : DataResult.error("Unknown interpolator."); + return id != null ? DataResult.success(id) : DataResult.error(() -> "Unknown interpolator."); }); static { diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java index db41c22772..713001f795 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManager.java @@ -30,7 +30,6 @@ import com.mojang.serialization.JsonOps; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,9 +41,10 @@ import net.minecraft.util.JsonHelper; import net.minecraft.util.profiler.Profiler; +import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; + /** * A class that loads and holds {@link Animation}s. - * * See {@link net.minecraft.client.render.entity.model.EntityModelLoader#getModelPart(EntityModelLayer)} for a similar usage. */ public class AnimationManager implements SimpleResourceReloader { @@ -57,7 +57,7 @@ public class AnimationManager implements SimpleResourceReloader resources = manager.findResources("animations", id -> id.getPath().endsWith(".json")); + this.profiler.push("Load Animations"); + Map resources = this.manager.findResources("animations", id -> id.getPath().endsWith(".json")); for (Map.Entry entry : resources.entrySet()) { this.addAnimation(entry.getKey(), entry.getValue()); } - profiler.pop(); + + this.profiler.pop(); } private void addAnimation(Identifier id, Resource resource) { @@ -115,11 +116,11 @@ private void addAnimation(Identifier id, Resource resource) { } Identifier animationId = new Identifier(id.getNamespace(), id.getPath().substring("animations/".length())); - animations.put(animationId, result.result().get().getFirst()); + this.animations.put(animationId, result.result().get().getFirst()); } public Map getAnimations() { - return animations; + return this.animations; } } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java index fa9c69baa0..6734cc410d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationManagerContainer.java @@ -17,14 +17,14 @@ package org.quiltmc.qsl.rendering.entity_models.api.animation; import org.jetbrains.annotations.NotNull; -import org.quiltmc.qsl.base.api.util.InjectedInterface; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRendererFactory; +import org.quiltmc.qsl.base.api.util.InjectedInterface; /** - * An injected interface for classes that have an {@link AnimationManager} + * An injected interface for classes that have an {@link AnimationManager}. */ @InjectedInterface(value = { EntityRenderDispatcher.class, diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java index c4eea9436b..3255cbdbbd 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTransformations.java @@ -32,10 +32,10 @@ public class AnimationTransformations { public static final Codec CODEC = Identifier.CODEC.flatXmap(identifier -> { PartAnimation.Transformation type = TRANSFORMATIONS.get(identifier); - return type != null ? DataResult.success(type) : DataResult.error("Unknown transformation: " + identifier); + return type != null ? DataResult.success(type) : DataResult.error(() -> "Unknown transformation: " + identifier); }, type -> { Identifier id = TRANSFORMATIONS.inverse().get(type); - return id != null ? DataResult.success(id) : DataResult.error("Unknown transformation."); + return id != null ? DataResult.success(id) : DataResult.error(() -> "Unknown transformation."); }); static { diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java index d18bc84679..0dd827ea4d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/AnimationTypes.java @@ -16,7 +16,6 @@ package org.quiltmc.qsl.rendering.entity_models.api.animation; - import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.mojang.serialization.Codec; @@ -32,16 +31,17 @@ public class AnimationTypes { public static final Codec TYPE_CODEC = Identifier.CODEC.flatXmap(identifier -> { AnimationType type = TYPES.get(identifier); - return type != null ? DataResult.success(type) : DataResult.error("Unknown animation type: " + identifier); + return type != null ? DataResult.success(type) : DataResult.error(() -> "Unknown animation type: " + identifier); }, animationType -> { Identifier id = TYPES.inverse().get(animationType); - return id != null ? DataResult.success(id) : DataResult.error("Unknown animation type."); + return id != null ? DataResult.success(id) : DataResult.error(() -> "Unknown animation type."); }); public static Codec CODEC = TYPE_CODEC.dispatch(animation -> ((TypedAnimation) (Object) animation).getType(), AnimationType::codec); public static AnimationType register(String name, Codec codec) { return register(new Identifier(name), codec); } + public static AnimationType register(Identifier id, Codec codec) { AnimationType type = new AnimationType(codec); AnimationType old = TYPES.putIfAbsent(id, type); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java index f9c168679c..3993d212e8 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/animation/TypedAnimation.java @@ -16,10 +16,10 @@ package org.quiltmc.qsl.rendering.entity_models.api.animation; -import org.quiltmc.qsl.base.api.util.InjectedInterface; - import net.minecraft.client.render.animation.Animation; +import org.quiltmc.qsl.base.api.util.InjectedInterface; + /** * An injected interface on {@link net.minecraft.client.render.animation.Animation} to specify its type. * Defaults to {@link org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationTypes#QUILT_ANIMATION}. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java index e6ef68bcf7..b25e92c6cd 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelCodecs.java @@ -17,19 +17,14 @@ package org.quiltmc.qsl.rendering.entity_models.api.model; import java.util.HashMap; +import java.util.List; import java.util.Optional; +import java.util.Set; import com.google.common.collect.ImmutableList; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import org.joml.Vector3f; -import org.quiltmc.qsl.rendering.entity_models.api.Codecs; -import org.quiltmc.qsl.rendering.entity_models.impl.LazyTypeUnboundedMapCodec; -import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.TextureDimensionsAccessor; -import org.quiltmc.qsl.rendering.entity_models.mixin.TexturedModelDataAccessor; import net.minecraft.client.model.Dilation; import net.minecraft.client.model.ModelCuboidData; @@ -40,6 +35,15 @@ import net.minecraft.client.model.TexturedModelData; import net.minecraft.client.util.math.Vector2f; import net.minecraft.util.Util; +import net.minecraft.util.math.Direction; + +import org.quiltmc.qsl.rendering.entity_models.api.Codecs; +import org.quiltmc.qsl.rendering.entity_models.impl.LazyTypeUnboundedMapCodec; +import org.quiltmc.qsl.rendering.entity_models.mixin.DilationAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelCuboidDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.ModelPartDataAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TextureDimensionsAccessor; +import org.quiltmc.qsl.rendering.entity_models.mixin.TexturedModelDataAccessor; /** * Codecs for model loading. @@ -72,7 +76,7 @@ public final class ModelCodecs { vec -> ImmutableList.of(vec.getX(), vec.getY()) ); - private static ModelCuboidData createCuboidData(Optional name, Vector3f offset, Vector3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize) { + private static ModelCuboidData createCuboidData(Optional name, Vector3f offset, Vector3f dimensions, Dilation dilation, boolean mirror, Vector2f uv, Vector2f uvSize, List directions) { return ModelCuboidDataAccessor.create( name.orElse(null), uv.getX(), uv.getY(), @@ -80,7 +84,8 @@ private static ModelCuboidData createCuboidData(Optional name, Vector3f dimensions.x(), dimensions.y(), dimensions.z(), dilation, mirror, - uvSize.getX(), uvSize.getY()); + uvSize.getX(), uvSize.getY(), + Set.copyOf(directions)); } private static final Vector2f DEFAULT_UV_SCALE = new Vector2f(1.0f, 1.0f); @@ -93,7 +98,8 @@ private static ModelCuboidData createCuboidData(Optional name, Vector3f DILATION.optionalFieldOf("dilation", Dilation.NONE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).dilation()), Codec.BOOL.optionalFieldOf("mirror", false).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).mirror()), VECTOR2F.fieldOf("uv").forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uv()), - VECTOR2F.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uvScale()) + VECTOR2F.optionalFieldOf("uv_scale", DEFAULT_UV_SCALE).forGetter(obj -> ((ModelCuboidDataAccessor) (Object) obj).uvScale()), + Direction.CODEC.listOf().optionalFieldOf("directions", List.of(Direction.values())).forGetter(obj -> List.copyOf(((ModelCuboidDataAccessor) (Object) obj).directions())) ).apply(instance, ModelCodecs::createCuboidData) ); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java index 1438cbcb10..4b6592dc82 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/ModelTypes.java @@ -31,16 +31,17 @@ public class ModelTypes { public static final Codec TYPE_CODEC = Identifier.CODEC.flatXmap(identifier -> { ModelType type = TYPES.get(identifier); - return type != null ? DataResult.success(type) : DataResult.error("Unknown model type: " + identifier); + return type != null ? DataResult.success(type) : DataResult.error(() -> "Unknown model type: " + identifier); }, model -> { Identifier id = TYPES.inverse().get(model); - return id != null ? DataResult.success(id) : DataResult.error("Unknown model type."); + return id != null ? DataResult.success(id) : DataResult.error(() -> "Unknown model type."); }); public static Codec CODEC = TYPE_CODEC.dispatch(model -> ((TypedModel) (Object) model).getType(), ModelType::codec); public static ModelType register(String name, Codec codec) { return register(new Identifier(name), codec); } + public static ModelType register(Identifier id, Codec codec) { ModelType type = new ModelType(codec); ModelType old = TYPES.putIfAbsent(id, type); diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java index c67831550f..67c6114e51 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/model/TypedModel.java @@ -16,10 +16,10 @@ package org.quiltmc.qsl.rendering.entity_models.api.model; -import org.quiltmc.qsl.base.api.util.InjectedInterface; - import net.minecraft.client.model.TexturedModelData; +import org.quiltmc.qsl.base.api.util.InjectedInterface; + /** * An injected interface on {@link net.minecraft.client.model.TexturedModelData} to specify its type. * Defaults to {@link ModelTypes#QUILT_MODEL}. diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java index 115451cc3d..3d4cd8deb8 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/api/package-info.java @@ -1,7 +1,9 @@ /** * This API is responsible for loading {@link net.minecraft.client.render.animation.Animation Animations} and {@link net.minecraft.client.model.TexturedModelData Models} from assets. + * *

* Animations are expected to be at {@code assets/[namespace]/animations/[path].json}, and are retrievable from an {@link org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager AnimationManager} with an identifier. + * *

* Models are loaded from {@code assets/[namespace]/models/entity/[path]/[layer_name].json}. Models can be automatically retrieved from the {@link net.minecraft.client.render.entity.model.EntityModelLoader EntityModelLoader} with the proper {@link net.minecraft.client.render.entity.model.EntityModelLayer EntityModelLayer}. */ diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java index c0cae952e9..8250f62cb6 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/DynamicEntityModelLoader.java @@ -30,9 +30,6 @@ import com.mojang.datafixers.util.Pair; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; -import org.quiltmc.qsl.rendering.entity_models.api.model.ModelCodecs; -import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; -import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,12 +41,15 @@ import net.minecraft.util.JsonHelper; import net.minecraft.util.profiler.Profiler; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; +import org.quiltmc.qsl.resource.loader.api.reloader.SimpleResourceReloader; + public class DynamicEntityModelLoader implements SimpleResourceReloader { private static final Logger LOGGER = LoggerFactory.getLogger("Quilt Entity Model Manager"); private Map modelData; public TexturedModelData getModelData(EntityModelLayer layer) { - return modelData.get(layer); + return this.modelData.get(layer); } @Override @@ -69,7 +69,7 @@ public Identifier getQuiltId() { } public static class ModelLoader { - private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("models\\/entity\\/((\\w|\\/)*)\\/(\\w*)\\.json"); + private static final Pattern PATH_AND_NAME_PATTERN = Pattern.compile("models/entity/([\\w/]*)/(\\w*)\\.json"); private final ResourceManager manager; private final Profiler profiler; @@ -82,12 +82,13 @@ public ModelLoader(ResourceManager manager, Profiler profiler) { } private void loadModels() { - profiler.push("Load Entity Models"); - Map resources = manager.findResources("models/entity", id -> id.getPath().endsWith(".json")); + this.profiler.push("Load Entity Models"); + Map resources = this.manager.findResources("models/entity", id -> id.getPath().endsWith(".json")); for (Map.Entry entry : resources.entrySet()) { this.addModel(entry.getKey(), entry.getValue()); } - profiler.pop(); + + this.profiler.pop(); } private void addModel(Identifier id, Resource resource) { @@ -117,11 +118,11 @@ private void addModel(Identifier id, Resource resource) { String name = matcher.group(2); Identifier modelID = new Identifier(id.getNamespace(), path); - modelData.put(new EntityModelLayer(modelID, name), result.result().get().getFirst()); + this.modelData.put(new EntityModelLayer(modelID, name), result.result().get().getFirst()); } public Map getModelData() { - return modelData; + return this.modelData; } } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java index bdda66b6fe..1eda52c49e 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/impl/LazyTypeUnboundedMapCodec.java @@ -36,41 +36,41 @@ import com.mojang.serialization.codecs.BaseMapCodec; public class LazyTypeUnboundedMapCodec implements BaseMapCodec, Codec> { - private final Codec keyCodec; - private final Supplier> elementCodecProvider; + private final Codec keyCodec; + private final Supplier> elementCodecProvider; - private Codec elementCodec; + private Codec elementCodec; - public LazyTypeUnboundedMapCodec(Codec keyCodec, Supplier> elementCodecProvider) { - this.keyCodec = keyCodec; - this.elementCodecProvider = elementCodecProvider; - } + public LazyTypeUnboundedMapCodec(Codec keyCodec, Supplier> elementCodecProvider) { + this.keyCodec = keyCodec; + this.elementCodecProvider = elementCodecProvider; + } - public static LazyTypeUnboundedMapCodec of(Codec keyCodec, Supplier> elementCodecProvider) { - return new LazyTypeUnboundedMapCodec<>(keyCodec, elementCodecProvider); - } + public static LazyTypeUnboundedMapCodec of(Codec keyCodec, Supplier> elementCodecProvider) { + return new LazyTypeUnboundedMapCodec<>(keyCodec, elementCodecProvider); + } - @Override - public DataResult, T>> decode(DynamicOps ops, T input) { - return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> decode(ops, map)).map(r -> Pair.of(r, input)); - } + @Override + public DataResult, T>> decode(DynamicOps ops, T input) { + return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> this.decode(ops, map)).map(r -> Pair.of(r, input)); + } - @Override - public DataResult encode(Map input, DynamicOps ops, T prefix) { - return encode(input, ops, ops.mapBuilder()).build(prefix); - } + @Override + public DataResult encode(Map input, DynamicOps ops, T prefix) { + return this.encode(input, ops, ops.mapBuilder()).build(prefix); + } - @Override - public Codec keyCodec() { - return keyCodec; - } + @Override + public Codec keyCodec() { + return this.keyCodec; + } - @Override - public Codec elementCodec() { - if (elementCodec == null) { - elementCodec = elementCodecProvider.get(); - } + @Override + public Codec elementCodec() { + if (this.elementCodec == null) { + this.elementCodec = this.elementCodecProvider.get(); + } - return elementCodec; - } + return this.elementCodec; + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java index c4188055a1..ffd5ade4bf 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/AnimationMixin.java @@ -16,14 +16,15 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationType; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationTypes; -import org.quiltmc.qsl.rendering.entity_models.api.animation.TypedAnimation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import net.minecraft.client.render.animation.Animation; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationType; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationTypes; +import org.quiltmc.qsl.rendering.entity_models.api.animation.TypedAnimation; + @Mixin(Animation.class) public class AnimationMixin implements TypedAnimation { @Unique @@ -31,11 +32,11 @@ public class AnimationMixin implements TypedAnimation { @Override public AnimationType getType() { - return quilt$animationType; + return this.quilt$animationType; } @Override public void setType(AnimationType type) { - quilt$animationType = type; + this.quilt$animationType = type; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java index 38fae21f47..0b32098d99 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/DilationAccessor.java @@ -32,12 +32,12 @@ @Mixin(Dilation.class) public interface DilationAccessor { - @Accessor("radiusX") - float radiusX(); + @Accessor("radiusX") + float radiusX(); - @Accessor("radiusY") - float radiusY(); + @Accessor("radiusY") + float radiusY(); - @Accessor("radiusZ") - float radiusZ(); + @Accessor("radiusZ") + float radiusZ(); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java index 99cb3cfd36..a4fff2a375 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityModelLoaderMixin.java @@ -16,9 +16,6 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; -import org.quiltmc.qsl.resource.loader.api.ResourceLoader; -import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -32,24 +29,28 @@ import net.minecraft.client.render.entity.model.EntityModelLoader; import net.minecraft.resource.ResourceType; +import org.quiltmc.qsl.rendering.entity_models.impl.DynamicEntityModelLoader; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; +import org.quiltmc.qsl.resource.loader.api.reloader.ResourceReloaderKeys; + @Mixin(EntityModelLoader.class) public class EntityModelLoaderMixin { - @Unique - private DynamicEntityModelLoader quilt$dynamicEntityModelLoader; + @Unique + private DynamicEntityModelLoader quilt$dynamicEntityModelLoader; - @Inject(method = "", at = @At("TAIL")) - private void createAnimationManager(CallbackInfo ci) { - this.quilt$dynamicEntityModelLoader = new DynamicEntityModelLoader(); - ResourceLoader resourceLoader = ResourceLoader.get(ResourceType.CLIENT_RESOURCES); - resourceLoader.registerReloader(this.quilt$dynamicEntityModelLoader); - resourceLoader.addReloaderOrdering(this.quilt$dynamicEntityModelLoader.getQuiltId(), ResourceReloaderKeys.Client.ENTITY_MODELS); - } + @Inject(method = "", at = @At("TAIL")) + private void createAnimationManager(CallbackInfo ci) { + this.quilt$dynamicEntityModelLoader = new DynamicEntityModelLoader(); + ResourceLoader resourceLoader = ResourceLoader.get(ResourceType.CLIENT_RESOURCES); + resourceLoader.registerReloader(this.quilt$dynamicEntityModelLoader); + resourceLoader.addReloaderOrdering(this.quilt$dynamicEntityModelLoader.getQuiltId(), ResourceReloaderKeys.Client.ENTITY_MODELS); + } - @Inject(method = "getModelPart", at = @At("HEAD"), cancellable = true) - public void returnDynamicModel(EntityModelLayer layer, CallbackInfoReturnable cir) { - TexturedModelData modelData = quilt$dynamicEntityModelLoader.getModelData(layer); - if (modelData != null) { - cir.setReturnValue(modelData.createModel()); - } - } + @Inject(method = "getModelPart", at = @At("HEAD"), cancellable = true) + public void returnDynamicModel(EntityModelLayer layer, CallbackInfoReturnable cir) { + TexturedModelData modelData = this.quilt$dynamicEntityModelLoader.getModelData(layer); + if (modelData != null) { + cir.setReturnValue(modelData.createModel()); + } + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java index e36b877bd0..e0c6fdac5d 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRenderDispatcherMixin.java @@ -17,9 +17,6 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; import org.jetbrains.annotations.NotNull; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; -import org.quiltmc.qsl.resource.loader.api.ResourceLoader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -36,6 +33,10 @@ import net.minecraft.client.texture.TextureManager; import net.minecraft.resource.ResourceType; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; +import org.quiltmc.qsl.resource.loader.api.ResourceLoader; + @Mixin(EntityRenderDispatcher.class) public class EntityRenderDispatcherMixin implements AnimationManagerContainer { @Unique @@ -50,6 +51,6 @@ private void createAnimationManager(MinecraftClient minecraftClient, TextureMana @Override @NotNull public AnimationManager getAnimationManager() { - return quilt$animationManager; + return this.quilt$animationManager; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java index 0768ece2d8..61208d8c24 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/EntityRendererFactoryContextMixin.java @@ -17,8 +17,6 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; import org.jetbrains.annotations.NotNull; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; -import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,6 +32,9 @@ import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.resource.ResourceManager; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManager; +import org.quiltmc.qsl.rendering.entity_models.api.animation.AnimationManagerContainer; + @Mixin(EntityRendererFactory.Context.class) public class EntityRendererFactoryContextMixin implements AnimationManagerContainer { @Unique @@ -47,6 +48,6 @@ private void createAnimationManager(EntityRenderDispatcher entityRenderDispatche @NotNull @Override public AnimationManager getAnimationManager() { - return quilt$animationManager; + return this.quilt$animationManager; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java index c136cbd796..c62f07686e 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelCuboidDataAccessor.java @@ -25,6 +25,8 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; +import java.util.Set; + import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; import org.spongepowered.asm.mixin.Mixin; @@ -34,33 +36,36 @@ import net.minecraft.client.model.Dilation; import net.minecraft.client.model.ModelCuboidData; import net.minecraft.client.util.math.Vector2f; +import net.minecraft.util.math.Direction; @Mixin(ModelCuboidData.class) public interface ModelCuboidDataAccessor { + @Accessor("name") + String name(); - @Accessor("name") - String name(); - - @Accessor("offset") + @Accessor("offset") Vector3f offset(); - @Accessor("dimensions") + @Accessor("dimensions") Vector3f dimensions(); - @Accessor("extraSize") - Dilation dilation(); + @Accessor("extraSize") + Dilation dilation(); + + @Accessor("mirror") + boolean mirror(); - @Accessor("mirror") - boolean mirror(); + @Accessor("textureUV") + Vector2f uv(); - @Accessor("textureUV") - Vector2f uv(); + @Accessor("textureScale") + Vector2f uvScale(); - @Accessor("textureScale") - Vector2f uvScale(); + @Accessor("directions") + Set directions(); - @Invoker("") - static ModelCuboidData create(@Nullable String string, float f, float g, float h, float i, float j, float k, float l, float m, Dilation dilation, boolean bl, float n, float o){ - throw new AssertionError("Mixin injection failed."); - } + @Invoker("") + static ModelCuboidData create(@Nullable String string, float f, float g, float h, float i, float j, float k, float l, float m, Dilation dilation, boolean bl, float n, float o, Set directions) { + throw new AssertionError("Mixin injection failed."); + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java index e2b5f2a2c2..2ddee409ff 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/ModelPartDataAccessor.java @@ -25,29 +25,30 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import net.minecraft.client.model.ModelCuboidData; -import net.minecraft.client.model.ModelPartData; -import net.minecraft.client.model.ModelTransform; +import java.util.List; +import java.util.Map; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; -import java.util.List; -import java.util.Map; +import net.minecraft.client.model.ModelCuboidData; +import net.minecraft.client.model.ModelPartData; +import net.minecraft.client.model.ModelTransform; @Mixin(ModelPartData.class) public interface ModelPartDataAccessor { - @Accessor("cuboidData") - List cuboids(); + @Accessor("cuboidData") + List cuboids(); - @Accessor("rotationData") - ModelTransform transform(); + @Accessor("rotationData") + ModelTransform transform(); - @Accessor("children") - Map children(); + @Accessor("children") + Map children(); - @Invoker("") - static ModelPartData create(List cuboids, ModelTransform rotation) { - throw new AssertionError("Mixin injection failed."); - } + @Invoker("") + static ModelPartData create(List cuboids, ModelTransform rotation) { + throw new AssertionError("Mixin injection failed."); + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java index 1c4381709d..fc276643ec 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TextureDimensionsAccessor.java @@ -25,15 +25,16 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import net.minecraft.client.model.TextureDimensions; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import net.minecraft.client.model.TextureDimensions; + @Mixin(TextureDimensions.class) public interface TextureDimensionsAccessor { - @Accessor("width") - int width(); + @Accessor("width") + int width(); - @Accessor("height") - int height(); + @Accessor("height") + int height(); } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java index d2a250a856..8c6c2aa460 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataAccessor.java @@ -25,23 +25,24 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import net.minecraft.client.model.ModelData; -import net.minecraft.client.model.TextureDimensions; -import net.minecraft.client.model.TexturedModelData; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; +import net.minecraft.client.model.ModelData; +import net.minecraft.client.model.TextureDimensions; +import net.minecraft.client.model.TexturedModelData; + @Mixin(TexturedModelData.class) public interface TexturedModelDataAccessor { - @Accessor("data") - ModelData root(); + @Accessor("data") + ModelData root(); - @Accessor("dimensions") - TextureDimensions texture(); + @Accessor("dimensions") + TextureDimensions texture(); - @Invoker("") - static TexturedModelData create(ModelData data, TextureDimensions dimensions) { - throw new AssertionError("Mixin injection failed."); - } + @Invoker("") + static TexturedModelData create(ModelData data, TextureDimensions dimensions) { + throw new AssertionError("Mixin injection failed."); + } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java index 9abe513c9a..da40398ac4 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/TexturedModelDataMixin.java @@ -16,14 +16,15 @@ package org.quiltmc.qsl.rendering.entity_models.mixin; -import org.quiltmc.qsl.rendering.entity_models.api.model.TypedModel; -import org.quiltmc.qsl.rendering.entity_models.api.model.ModelType; -import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import net.minecraft.client.model.TexturedModelData; +import org.quiltmc.qsl.rendering.entity_models.api.model.TypedModel; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelType; +import org.quiltmc.qsl.rendering.entity_models.api.model.ModelTypes; + @Mixin(TexturedModelData.class) public class TexturedModelDataMixin implements TypedModel { @Unique @@ -31,11 +32,11 @@ public class TexturedModelDataMixin implements TypedModel { @Override public ModelType getType() { - return quilt$modelType; + return this.quilt$modelType; } @Override public void setType(ModelType type) { - quilt$modelType = type; + this.quilt$modelType = type; } } diff --git a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java index 377acb4d85..e9f688a4b9 100644 --- a/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java +++ b/library/rendering/entity_models/src/main/java/org/quiltmc/qsl/rendering/entity_models/mixin/Vector2fMixin.java @@ -23,17 +23,18 @@ @Mixin(Vector2f.class) public abstract class Vector2fMixin { - @Shadow - public abstract float getX(); + @Shadow + public abstract float getX(); - @Shadow - public abstract float getY(); + @Shadow + public abstract float getY(); - @Override - public boolean equals(Object o) { - if (o instanceof Vector2f vec) { - return this.getX() == vec.getX() && this.getY() == vec.getY(); - } - return super.equals(o); - } + @Override + public boolean equals(Object o) { + if (o instanceof Vector2f vec) { + return this.getX() == vec.getX() && this.getY() == vec.getY(); + } + + return super.equals(o); + } }