aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java38
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBasic.java33
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBuiltin.java33
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ItemModelGeneratorJsonUnbakedModelCopy.java24
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java73
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java50
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/PatchJsonUnbakedModelDeserializer.java30
7 files changed, 281 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java
new file mode 100644
index 0000000..5a6e5fd
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ApplyHeadModelInItemRenderer.java
@@ -0,0 +1,38 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.BakedModelExtra;
+import net.minecraft.client.render.item.ItemRenderer;
+import net.minecraft.client.render.model.BakedModel;
+import net.minecraft.client.render.model.json.ModelTransformationMode;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(ItemRenderer.class)
+public class ApplyHeadModelInItemRenderer {
+ @WrapOperation(method = "renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/world/World;III)V",
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;"))
+ private BakedModel applyHeadModel(ItemRenderer instance, ItemStack stack, World world, LivingEntity entity, int seed, Operation<BakedModel> original,
+ @Local(argsOnly = true) ModelTransformationMode modelTransformationMode) {
+ var model = original.call(instance, stack, world, entity, seed);
+ if (modelTransformationMode == ModelTransformationMode.HEAD
+ && model instanceof BakedModelExtra extra) {
+ var headModel = extra.getHeadModel_firmament();
+ if (headModel != null) {
+ model = headModel;
+ }
+ }
+ return model;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBasic.java b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBasic.java
new file mode 100644
index 0000000..0c984ce
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBasic.java
@@ -0,0 +1,33 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import moe.nea.firmament.features.texturepack.BakedModelExtra;
+import net.minecraft.client.render.model.BakedModel;
+import net.minecraft.client.render.model.BasicBakedModel;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+@Mixin(BasicBakedModel.class)
+public class BakedModelDataHolderBasic implements BakedModelExtra {
+
+ @Unique
+ private BakedModel headModel;
+
+
+ @Nullable
+ @Override
+ public BakedModel getHeadModel_firmament() {
+ return headModel;
+ }
+
+ @Override
+ public void setHeadModel_firmament(@Nullable BakedModel headModel) {
+ this.headModel = headModel;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBuiltin.java b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBuiltin.java
new file mode 100644
index 0000000..b40e61b
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedModelDataHolderBuiltin.java
@@ -0,0 +1,33 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import moe.nea.firmament.features.texturepack.BakedModelExtra;
+import net.minecraft.client.render.model.BakedModel;
+import net.minecraft.client.render.model.BuiltinBakedModel;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+@Mixin(BuiltinBakedModel.class)
+public class BakedModelDataHolderBuiltin implements BakedModelExtra {
+
+ @Unique
+ private BakedModel headModel;
+
+
+ @Nullable
+ @Override
+ public BakedModel getHeadModel_firmament() {
+ return headModel;
+ }
+
+ @Override
+ public void setHeadModel_firmament(@Nullable BakedModel headModel) {
+ this.headModel = headModel;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ItemModelGeneratorJsonUnbakedModelCopy.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ItemModelGeneratorJsonUnbakedModelCopy.java
new file mode 100644
index 0000000..caf05de
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ItemModelGeneratorJsonUnbakedModelCopy.java
@@ -0,0 +1,24 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import com.llamalad7.mixinextras.injector.ModifyReturnValue;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.JsonUnbakedModelFirmExtra;
+import net.minecraft.client.render.model.json.ItemModelGenerator;
+import net.minecraft.client.render.model.json.JsonUnbakedModel;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(ItemModelGenerator.class)
+public class ItemModelGeneratorJsonUnbakedModelCopy {
+ @ModifyReturnValue(method = "create", at = @At("RETURN"))
+ private JsonUnbakedModel copyHeadModel(JsonUnbakedModel original, @Local(argsOnly = true) JsonUnbakedModel oldModel) {
+ ((JsonUnbakedModelFirmExtra) original).setHeadModel_firmament(((JsonUnbakedModelFirmExtra) oldModel).getHeadModel_firmament());
+ return original;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java b/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java
new file mode 100644
index 0000000..2ca34a3
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/JsonUnbakedModelDataHolder.java
@@ -0,0 +1,73 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import com.google.gson.annotations.SerializedName;
+import com.llamalad7.mixinextras.injector.ModifyReturnValue;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.BakedModelExtra;
+import moe.nea.firmament.features.texturepack.JsonUnbakedModelFirmExtra;
+import net.minecraft.client.render.model.BakedModel;
+import net.minecraft.client.render.model.Baker;
+import net.minecraft.client.render.model.ModelRotation;
+import net.minecraft.client.render.model.UnbakedModel;
+import net.minecraft.client.render.model.json.JsonUnbakedModel;
+import net.minecraft.util.Identifier;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.Unique;
+import org.spongepowered.asm.mixin.injection.At;
+
+import java.util.Collection;
+import java.util.Objects;
+
+@Mixin(JsonUnbakedModel.class)
+public class JsonUnbakedModelDataHolder implements JsonUnbakedModelFirmExtra {
+ @Shadow
+ @Nullable
+ protected JsonUnbakedModel parent;
+ @Unique
+ @Nullable
+ public Identifier headModel;
+
+ @Override
+ public void setHeadModel_firmament(@Nullable Identifier identifier) {
+ this.headModel = identifier;
+ }
+
+ @Override
+ public @Nullable Identifier getHeadModel_firmament() {
+ if (this.headModel != null) return this.headModel;
+ if (this.parent == null) return null;
+ return ((JsonUnbakedModelFirmExtra) this.parent).getHeadModel_firmament();
+ }
+
+ @ModifyReturnValue(method = "getModelDependencies", at = @At("RETURN"))
+ private Collection<Identifier> addDependencies(Collection<Identifier> original) {
+ var headModel = getHeadModel_firmament();
+ if (headModel != null) {
+ original.add(headModel);
+ }
+ return original;
+ }
+
+ @ModifyReturnValue(
+ method = "bake(Lnet/minecraft/client/render/model/Baker;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/function/Function;Lnet/minecraft/client/render/model/ModelBakeSettings;Z)Lnet/minecraft/client/render/model/BakedModel;",
+ at = @At(value = "RETURN"))
+ private BakedModel bakeExtraInfo(BakedModel original, @Local(argsOnly = true) Baker baker) {
+ var headModel = getHeadModel_firmament();
+ if (headModel != null && original instanceof BakedModelExtra extra) {
+ UnbakedModel unbakedModel = baker.getOrLoadModel(headModel);
+ extra.setHeadModel_firmament(
+ Objects.equals(unbakedModel, parent)
+ ? null
+ : baker.bake(headModel, ModelRotation.X0_Y0));
+ }
+ return original;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java
new file mode 100644
index 0000000..dca81b8
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchHeadFeatureRenderer.java
@@ -0,0 +1,50 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.BakedModelExtra;
+import net.minecraft.block.AbstractSkullBlock;
+import net.minecraft.block.Block;
+import net.minecraft.block.Blocks;
+import net.minecraft.client.render.entity.feature.HeadFeatureRenderer;
+import net.minecraft.client.render.entity.model.EntityModel;
+import net.minecraft.client.render.item.HeldItemRenderer;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.item.BlockItem;
+import net.minecraft.item.ItemStack;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(HeadFeatureRenderer.class)
+public class PatchHeadFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> {
+
+ @Shadow
+ @Final
+ private HeldItemRenderer heldItemRenderer;
+
+ @WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V",
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BlockItem;getBlock()Lnet/minecraft/block/Block;"))
+ private Block replaceSkull(BlockItem instance, Operation<Block> original, @Local ItemStack itemStack) {
+ var oldBlock = original.call(instance);
+ if (oldBlock instanceof AbstractSkullBlock) {
+ var bakedModel = this.heldItemRenderer.itemRenderer
+ .getModel(itemStack, null, null, 0);
+ if (bakedModel instanceof BakedModelExtra extra && extra.getHeadModel_firmament() != null)
+ return Blocks.ENCHANTING_TABLE; // Any non skull block. Let's choose the enchanting table because it is very distinct.
+ }
+ return oldBlock;
+ }
+
+
+
+
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchJsonUnbakedModelDeserializer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchJsonUnbakedModelDeserializer.java
new file mode 100644
index 0000000..3b85421
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchJsonUnbakedModelDeserializer.java
@@ -0,0 +1,30 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins.custommodels;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import com.llamalad7.mixinextras.injector.ModifyReturnValue;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.JsonUnbakedModelFirmExtra;
+import net.minecraft.client.render.model.json.JsonUnbakedModel;
+import net.minecraft.util.Identifier;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(JsonUnbakedModel.Deserializer.class)
+public class PatchJsonUnbakedModelDeserializer {
+ @ModifyReturnValue(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;",
+ at = @At("RETURN"))
+ private JsonUnbakedModel addHeadModel(JsonUnbakedModel original, @Local JsonObject jsonObject) {
+ var headModel = jsonObject.get("firmament:head_model");
+ if (headModel instanceof JsonPrimitive prim && prim.isString()) {
+ ((JsonUnbakedModelFirmExtra) original).setHeadModel_firmament(Identifier.of(prim.getAsString()));
+ }
+ return original;
+ }
+}