aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-22 00:30:05 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-26 15:37:12 +0100
commit602112724d8236c1ec6671e1893128862c9f5815 (patch)
treefd0695839af0b2a8296e8d3009432644212638ce /src/main/java/moe/nea/firmament/mixins
parent2e571210c948d90a7d0ea8b07184102ceb401962 (diff)
downloadfirmament-602112724d8236c1ec6671e1893128862c9f5815.tar.gz
firmament-602112724d8236c1ec6671e1893128862c9f5815.tar.bz2
firmament-602112724d8236c1ec6671e1893128862c9f5815.zip
Add custom model predicates
Add regex support Add and and or predicates
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/BakedOverrideDataHolder.java33
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ModelOverrideDataHolder.java33
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/PatchOverrideDeserializer.java55
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java52
4 files changed, 173 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/BakedOverrideDataHolder.java b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedOverrideDataHolder.java
new file mode 100644
index 0000000..5e5f863
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/BakedOverrideDataHolder.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.BakedOverrideData;
+import moe.nea.firmament.features.texturepack.FirmamentModelPredicate;
+import net.minecraft.client.render.model.json.ModelOverrideList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+@Mixin(ModelOverrideList.BakedOverride.class)
+public class BakedOverrideDataHolder implements BakedOverrideData {
+
+ @Unique
+ private FirmamentModelPredicate[] firmamentOverrides;
+
+ @Nullable
+ @Override
+ public FirmamentModelPredicate[] getFirmamentOverrides() {
+ return firmamentOverrides;
+ }
+
+ @Override
+ public void setFirmamentOverrides(@NotNull FirmamentModelPredicate[] overrides) {
+ this.firmamentOverrides = overrides;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ModelOverrideDataHolder.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ModelOverrideDataHolder.java
new file mode 100644
index 0000000..8a476db
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ModelOverrideDataHolder.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.FirmamentModelPredicate;
+import moe.nea.firmament.features.texturepack.ModelOverrideData;
+import net.minecraft.client.render.model.json.ModelOverride;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
+
+@Mixin(ModelOverride.class)
+public class ModelOverrideDataHolder implements ModelOverrideData {
+
+ @Unique
+ private FirmamentModelPredicate[] overrides;
+
+ @Nullable
+ @Override
+ public FirmamentModelPredicate[] getFirmamentOverrides() {
+ return overrides;
+ }
+
+ @Override
+ public void setFirmamentOverrides(@NotNull FirmamentModelPredicate[] overrides) {
+ this.overrides = overrides;
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchOverrideDeserializer.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchOverrideDeserializer.java
new file mode 100644
index 0000000..e85bff0
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchOverrideDeserializer.java
@@ -0,0 +1,55 @@
+/*
+ * 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.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
+import com.llamalad7.mixinextras.injector.ModifyReturnValue;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.CustomModelOverrideParser;
+import moe.nea.firmament.features.texturepack.ModelOverrideData;
+import net.minecraft.client.render.model.json.ModelOverride;
+import net.minecraft.util.Identifier;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+import java.util.List;
+import java.util.Map;
+
+@Mixin(ModelOverride.Deserializer.class)
+public class PatchOverrideDeserializer {
+
+ @ModifyReturnValue(
+ method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/ModelOverride;",
+ at = @At(value = "RETURN"))
+ private ModelOverride addCustomOverrides(ModelOverride original, @Local JsonObject jsonObject) {
+ var originalData = (ModelOverrideData) original;
+ originalData.setFirmamentOverrides(CustomModelOverrideParser.parseCustomModelOverrides(jsonObject));
+ return original;
+ }
+
+ @ModifyExpressionValue(
+ method = "deserializeMinPropertyValues(Lcom/google/gson/JsonObject;)Ljava/util/List;",
+ at = @At(value = "INVOKE", target = "Ljava/util/Map$Entry;getValue()Ljava/lang/Object;"))
+ private Object removeFirmamentPredicatesFromJsonIteration(Object original, @Local Map.Entry<String, JsonElement> entry) {
+ if (entry.getKey().startsWith("firmament:")) return new JsonPrimitive(0F);
+ return original;
+ }
+
+ @Inject(
+ method = "deserializeMinPropertyValues",
+ at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;")
+ )
+ private void whatever(JsonObject object, CallbackInfoReturnable<List<ModelOverride.Condition>> cir,
+ @Local Map<Identifier, Float> maps) {
+ maps.entrySet().removeIf(it -> it.getKey().getNamespace().equals("firmament"));
+ }
+}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
new file mode 100644
index 0000000..4db9fc0
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
@@ -0,0 +1,52 @@
+/*
+ * 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.ModifyExpressionValue;
+import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.features.texturepack.BakedOverrideData;
+import moe.nea.firmament.features.texturepack.FirmamentModelPredicate;
+import moe.nea.firmament.features.texturepack.ModelOverrideData;
+import net.minecraft.client.render.model.json.ModelOverride;
+import net.minecraft.client.render.model.json.ModelOverrideList;
+import net.minecraft.item.ItemStack;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyArg;
+
+@Mixin(ModelOverrideList.class)
+public class TestForFirmamentOverridePredicatesPatch {
+
+ @ModifyArg(method = "<init>(Lnet/minecraft/client/render/model/Baker;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/List;)V",
+ at = @At(
+ value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"
+ ))
+ public Object onInit(
+ Object element,
+ @Local ModelOverride modelOverride
+ ) {
+ var bakedOverride = (ModelOverrideList.BakedOverride) element;
+ ((BakedOverrideData) bakedOverride)
+ .setFirmamentOverrides(((ModelOverrideData) modelOverride).getFirmamentOverrides());
+ return element;
+ }
+
+ @ModifyExpressionValue(method = "apply", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/json/ModelOverrideList$BakedOverride;test([F)Z"))
+ public boolean testFirmamentOverrides(boolean originalValue,
+ @Local ModelOverrideList.BakedOverride bakedOverride,
+ @Local ItemStack stack) {
+ if (!originalValue) return false;
+ var overrideData = (BakedOverrideData) bakedOverride;
+ var overrides = overrideData.getFirmamentOverrides();
+ if (overrides == null) return true;
+ for (FirmamentModelPredicate firmamentOverride : overrides) {
+ if (!firmamentOverride.test(stack))
+ return false;
+ }
+ return true;
+ }
+}