aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-17 19:41:18 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-17 19:41:18 +0100
commit86cbf9d4221e85dec14300c11393abb325bffcef (patch)
treedc86b43ae33e92a7f7ad553e6a03b6853d6b0ded
parent6045077025629cabc1831a281fec532faa7781dd (diff)
downloadFirmament-86cbf9d4221e85dec14300c11393abb325bffcef.tar.gz
Firmament-86cbf9d4221e85dec14300c11393abb325bffcef.tar.bz2
Firmament-86cbf9d4221e85dec14300c11393abb325bffcef.zip
fix: Item predicates not applying unless a vanilla predicate is present
-rw-r--r--src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java11
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java31
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java23
-rw-r--r--src/main/kotlin/features/texturepack/BakedOverrideData.kt8
-rw-r--r--src/main/kotlin/features/texturepack/CustomGlobalTextures.kt252
-rw-r--r--src/main/kotlin/features/texturepack/ModelOverrideData.kt14
-rw-r--r--src/main/kotlin/repo/HypixelStaticData.kt2
-rw-r--r--src/main/resources/firmament.accesswidener1
8 files changed, 176 insertions, 166 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java
index e7207f4..e0a7544 100644
--- a/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java
+++ b/src/main/java/moe/nea/firmament/mixins/CustomModelEventPatch.java
@@ -3,9 +3,11 @@
package moe.nea.firmament.mixins;
import moe.nea.firmament.events.CustomItemModelEvent;
+import moe.nea.firmament.features.texturepack.CustomGlobalTextures;
import net.minecraft.client.render.item.ItemModels;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
@@ -22,8 +24,13 @@ public class CustomModelEventPatch {
@Inject(method = "getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true)
public void onGetModel(ItemStack stack, CallbackInfoReturnable<BakedModel> cir) {
- var model = CustomItemModelEvent.getModel(stack, (ItemModels) (Object) this);
- if (model != null)
+ var $this = (ItemModels) (Object) this;
+ var model = CustomItemModelEvent.getModel(stack, $this);
+ if (model == null) {
+ model = CustomGlobalTextures.replaceGlobalModel($this, stack);
+ }
+ if (model != null) {
cir.setReturnValue(model);
+ }
}
}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java
deleted file mode 100644
index c708862..0000000
--- a/src/main/java/moe/nea/firmament/mixins/custommodels/GlobalModelOverridePatch.java
+++ /dev/null
@@ -1,31 +0,0 @@
-
-package moe.nea.firmament.mixins.custommodels;
-
-import moe.nea.firmament.features.texturepack.CustomGlobalTextures;
-import net.minecraft.client.render.item.ItemModels;
-import net.minecraft.client.render.item.ItemRenderer;
-import net.minecraft.client.render.model.BakedModel;
-import net.minecraft.entity.LivingEntity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.world.World;
-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;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
-
-@Mixin(ItemRenderer.class)
-public abstract class GlobalModelOverridePatch {
-
- @Shadow
- @Final
- private ItemModels models;
-
- @Inject(method = "getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true)
- private void overrideGlobalModel(
- ItemStack stack, World world, LivingEntity entity,
- int seed, CallbackInfoReturnable<BakedModel> cir) {
- CustomGlobalTextures.replaceGlobalModel(this.models, stack, cir);
- }
-}
diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
index 81ae3b8..63f3cf0 100644
--- a/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
+++ b/src/main/java/moe/nea/firmament/mixins/custommodels/TestForFirmamentOverridePredicatesPatch.java
@@ -2,7 +2,10 @@
package moe.nea.firmament.mixins.custommodels;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
+import moe.nea.firmament.Firmament;
import moe.nea.firmament.features.texturepack.BakedOverrideData;
import moe.nea.firmament.features.texturepack.CustomSkyBlockTextures;
import moe.nea.firmament.features.texturepack.FirmamentModelPredicate;
@@ -10,13 +13,23 @@ 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 net.minecraft.util.Identifier;
+import org.objectweb.asm.Opcodes;
+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;
import org.spongepowered.asm.mixin.injection.ModifyArg;
+import java.util.List;
+import java.util.Objects;
+
@Mixin(ModelOverrideList.class)
public class TestForFirmamentOverridePredicatesPatch {
+ @Shadow
+ private Identifier[] conditionTypes;
+
@ModifyArg(method = "<init>(Lnet/minecraft/client/render/model/Baker;Ljava/util/List;)V",
at = @At(
value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"
@@ -26,8 +39,14 @@ public class TestForFirmamentOverridePredicatesPatch {
@Local ModelOverride modelOverride
) {
var bakedOverride = (ModelOverrideList.BakedOverride) element;
- ((BakedOverrideData) (Object) bakedOverride)
- .setFirmamentOverrides(((ModelOverrideData) (Object) modelOverride).getFirmamentOverrides());
+ var modelOverrideData = ModelOverrideData.cast(modelOverride);
+ BakedOverrideData.cast(bakedOverride)
+ .setFirmamentOverrides(modelOverrideData.getFirmamentOverrides());
+ if (conditionTypes.length == 0 &&
+ modelOverrideData.getFirmamentOverrides() != null &&
+ modelOverrideData.getFirmamentOverrides().length > 0) {
+ conditionTypes = new Identifier[]{Firmament.INSTANCE.identifier("sentinel/enforce_model_override_evaluation")};
+ }
return element;
}
diff --git a/src/main/kotlin/features/texturepack/BakedOverrideData.kt b/src/main/kotlin/features/texturepack/BakedOverrideData.kt
index c012883..e9391f1 100644
--- a/src/main/kotlin/features/texturepack/BakedOverrideData.kt
+++ b/src/main/kotlin/features/texturepack/BakedOverrideData.kt
@@ -1,8 +1,14 @@
package moe.nea.firmament.features.texturepack
+import net.minecraft.client.render.model.json.ModelOverrideList
+
interface BakedOverrideData {
fun getFirmamentOverrides(): Array<FirmamentModelPredicate>?
fun setFirmamentOverrides(overrides: Array<FirmamentModelPredicate>?)
-
+ companion object{
+ @Suppress("CAST_NEVER_SUCCEEDS")
+ @JvmStatic
+ fun cast(bakedOverride: ModelOverrideList.BakedOverride): BakedOverrideData = bakedOverride as BakedOverrideData
+ }
}
diff --git a/src/main/kotlin/features/texturepack/CustomGlobalTextures.kt b/src/main/kotlin/features/texturepack/CustomGlobalTextures.kt
index a1203df..9ad8bc1 100644
--- a/src/main/kotlin/features/texturepack/CustomGlobalTextures.kt
+++ b/src/main/kotlin/features/texturepack/CustomGlobalTextures.kt
@@ -6,7 +6,6 @@ package moe.nea.firmament.features.texturepack
import java.util.Optional
import java.util.concurrent.CompletableFuture
import org.slf4j.LoggerFactory
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlin.jvm.optionals.getOrNull
@@ -35,132 +34,131 @@ import moe.nea.firmament.util.json.SingletonSerializableList
import moe.nea.firmament.util.runNull
object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalTextures.CustomGuiTextureOverride>(),
- SubscriptionOwner {
- override val delegateFeature: FirmamentFeature
- get() = CustomSkyBlockTextures
-
- class CustomGuiTextureOverride(
- val classes: List<ItemOverrideCollection>
- )
-
- @Serializable
- data class GlobalItemOverride(
- val screen: @Serializable(SingletonSerializableList::class) List<Identifier>,
- val model: Identifier,
- val predicate: FirmamentModelPredicate,
- )
-
- @Serializable
- data class ScreenFilter(
- val title: StringMatcher,
- )
-
- data class ItemOverrideCollection(
- val screenFilter: ScreenFilter,
- val overrides: List<GlobalItemOverride>,
- )
-
- @Subscribe
- fun onStart(event: FinalizeResourceManagerEvent) {
- MC.resourceManager.registerReloader(this)
- }
-
- @Subscribe
- fun onEarlyReload(event: EarlyResourceReloadEvent) {
- preparationFuture = CompletableFuture
- .supplyAsync(
- {
- prepare(event.resourceManager)
- }, event.preparationExecutor)
- }
-
- @Subscribe
- fun onBakeModels(event: BakeExtraModelsEvent) {
- for (guiClassOverride in preparationFuture.join().classes) {
- for (override in guiClassOverride.overrides) {
- event.addItemModel(ModelIdentifier(override.model, "inventory"))
- }
- }
- }
-
- @Volatile
- var preparationFuture: CompletableFuture<CustomGuiTextureOverride> = CompletableFuture.completedFuture(
- CustomGuiTextureOverride(listOf()))
-
- override fun prepare(manager: ResourceManager?, profiler: Profiler?): CustomGuiTextureOverride {
- return preparationFuture.join()
- }
-
- override fun apply(prepared: CustomGuiTextureOverride, manager: ResourceManager?, profiler: Profiler?) {
- this.guiClassOverrides = prepared
- }
-
- val logger = LoggerFactory.getLogger(CustomGlobalTextures::class.java)
- fun prepare(manager: ResourceManager): CustomGuiTextureOverride {
- val overrideResources =
- manager.findResources("overrides/item") { it.namespace == "firmskyblock" && it.path.endsWith(".json") }
- .mapNotNull {
- Firmament.tryDecodeJsonFromStream<GlobalItemOverride>(it.value.inputStream).getOrElse { ex ->
- logger.error("Failed to load global item override at ${it.key}", ex)
- null
- }
- }
-
- val byGuiClass = overrideResources.flatMap { override -> override.screen.toSet().map { it to override } }
- .groupBy { it.first }
- val guiClasses = byGuiClass.entries
- .mapNotNull {
- val key = it.key
- val guiClassResource =
- manager.getResource(Identifier.of(key.namespace, "filters/screen/${key.path}.json"))
- .getOrNull()
- ?: return@mapNotNull runNull {
- logger.error("Failed to locate screen filter at $key")
- }
- val screenFilter =
- Firmament.tryDecodeJsonFromStream<ScreenFilter>(guiClassResource.inputStream)
- .getOrElse { ex ->
- logger.error("Failed to load screen filter at $key", ex)
- return@mapNotNull null
- }
- ItemOverrideCollection(screenFilter, it.value.map { it.second })
- }
- logger.info("Loaded ${overrideResources.size} global item overrides")
- return CustomGuiTextureOverride(guiClasses)
- }
-
- var guiClassOverrides = CustomGuiTextureOverride(listOf())
-
- var matchingOverrides: Set<ItemOverrideCollection> = setOf()
-
- @Subscribe
- fun onOpenGui(event: ScreenChangeEvent) {
- val newTitle = event.new?.title ?: Text.empty()
- matchingOverrides = guiClassOverrides.classes
- .filterTo(mutableSetOf()) { it.screenFilter.title.matches(newTitle) }
- }
-
- val overrideCache = WeakCache.memoize<ItemStack, ItemModels, Optional<BakedModel>>("CustomGlobalTextureModelOverrides") { stack, models ->
- matchingOverrides
- .firstNotNullOfOrNull {
- it.overrides
- .asSequence()
- .filter { it.predicate.test(stack) }
- .map { models.getModel(it.model) }
- .firstOrNull()
- }
- .intoOptional()
- }
-
- @JvmStatic
- fun replaceGlobalModel(
- models: ItemModels,
- stack: ItemStack,
- cir: CallbackInfoReturnable<BakedModel>
- ) {
- overrideCache.invoke(stack, models)
- .ifPresent(cir::setReturnValue)
- }
+ SubscriptionOwner {
+ override val delegateFeature: FirmamentFeature
+ get() = CustomSkyBlockTextures
+
+ class CustomGuiTextureOverride(
+ val classes: List<ItemOverrideCollection>
+ )
+
+ @Serializable
+ data class GlobalItemOverride(
+ val screen: @Serializable(SingletonSerializableList::class) List<Identifier>,
+ val model: Identifier,
+ val predicate: FirmamentModelPredicate,
+ )
+
+ @Serializable
+ data class ScreenFilter(
+ val title: StringMatcher,
+ )
+
+ data class ItemOverrideCollection(
+ val screenFilter: ScreenFilter,
+ val overrides: List<GlobalItemOverride>,
+ )
+
+ @Subscribe
+ fun onStart(event: FinalizeResourceManagerEvent) {
+ MC.resourceManager.registerReloader(this)
+ }
+
+ @Subscribe
+ fun onEarlyReload(event: EarlyResourceReloadEvent) {
+ preparationFuture = CompletableFuture
+ .supplyAsync(
+ {
+ prepare(event.resourceManager)
+ }, event.preparationExecutor)
+ }
+
+ @Subscribe
+ fun onBakeModels(event: BakeExtraModelsEvent) {
+ for (guiClassOverride in preparationFuture.join().classes) {
+ for (override in guiClassOverride.overrides) {
+ event.addItemModel(ModelIdentifier(override.model, "inventory"))
+ }
+ }
+ }
+
+ @Volatile
+ var preparationFuture: CompletableFuture<CustomGuiTextureOverride> = CompletableFuture.completedFuture(
+ CustomGuiTextureOverride(listOf()))
+
+ override fun prepare(manager: ResourceManager?, profiler: Profiler?): CustomGuiTextureOverride {
+ return preparationFuture.join()
+ }
+
+ override fun apply(prepared: CustomGuiTextureOverride, manager: ResourceManager?, profiler: Profiler?) {
+ this.guiClassOverrides = prepared
+ }
+
+ val logger = LoggerFactory.getLogger(CustomGlobalTextures::class.java)
+ fun prepare(manager: ResourceManager): CustomGuiTextureOverride {
+ val overrideResources =
+ manager.findResources("overrides/item") { it.namespace == "firmskyblock" && it.path.endsWith(".json") }
+ .mapNotNull {
+ Firmament.tryDecodeJsonFromStream<GlobalItemOverride>(it.value.inputStream).getOrElse { ex ->
+ logger.error("Failed to load global item override at ${it.key}", ex)
+ null
+ }
+ }
+
+ val byGuiClass = overrideResources.flatMap { override -> override.screen.toSet().map { it to override } }
+ .groupBy { it.first }
+ val guiClasses = byGuiClass.entries
+ .mapNotNull {
+ val key = it.key
+ val guiClassResource =
+ manager.getResource(Identifier.of(key.namespace, "filters/screen/${key.path}.json"))
+ .getOrNull()
+ ?: return@mapNotNull runNull {
+ logger.error("Failed to locate screen filter at $key")
+ }
+ val screenFilter =
+ Firmament.tryDecodeJsonFromStream<ScreenFilter>(guiClassResource.inputStream)
+ .getOrElse { ex ->
+ logger.error("Failed to load screen filter at $key", ex)
+ return@mapNotNull null
+ }
+ ItemOverrideCollection(screenFilter, it.value.map { it.second })
+ }
+ logger.info("Loaded ${overrideResources.size} global item overrides")
+ return CustomGuiTextureOverride(guiClasses)
+ }
+
+ var guiClassOverrides = CustomGuiTextureOverride(listOf())
+
+ var matchingOverrides: Set<ItemOverrideCollection> = setOf()
+
+ @Subscribe
+ fun onOpenGui(event: ScreenChangeEvent) {
+ val newTitle = event.new?.title ?: Text.empty()
+ matchingOverrides = guiClassOverrides.classes
+ .filterTo(mutableSetOf()) { it.screenFilter.title.matches(newTitle) }
+ }
+
+ val overrideCache =
+ WeakCache.memoize<ItemStack, ItemModels, Optional<BakedModel>>("CustomGlobalTextureModelOverrides") { stack, models ->
+ matchingOverrides
+ .firstNotNullOfOrNull {
+ it.overrides
+ .asSequence()
+ .filter { it.predicate.test(stack) }
+ .map { models.getModel(it.model) }
+ .firstOrNull()
+ }
+ .intoOptional()
+ }
+
+ @JvmStatic
+ fun replaceGlobalModel(
+ models: ItemModels,
+ stack: ItemStack,
+ ): BakedModel? {
+ return overrideCache.invoke(stack, models).getOrNull()
+ }
}
diff --git a/src/main/kotlin/features/texturepack/ModelOverrideData.kt b/src/main/kotlin/features/texturepack/ModelOverrideData.kt
index 1585bd7..29d9192 100644
--- a/src/main/kotlin/features/texturepack/ModelOverrideData.kt
+++ b/src/main/kotlin/features/texturepack/ModelOverrideData.kt
@@ -1,7 +1,15 @@
-
package moe.nea.firmament.features.texturepack
+import net.minecraft.client.render.model.json.ModelOverride
+
interface ModelOverrideData {
- fun getFirmamentOverrides(): Array<FirmamentModelPredicate>?
- fun setFirmamentOverrides(overrides: Array<FirmamentModelPredicate>?)
+ companion object {
+
+ @JvmStatic
+ @Suppress("CAST_NEVER_SUCCEEDS")
+ fun cast(override: ModelOverride) = override as ModelOverrideData
+ }
+
+ fun getFirmamentOverrides(): Array<FirmamentModelPredicate>?
+ fun setFirmamentOverrides(overrides: Array<FirmamentModelPredicate>?)
}
diff --git a/src/main/kotlin/repo/HypixelStaticData.kt b/src/main/kotlin/repo/HypixelStaticData.kt
index 727a962..181aa70 100644
--- a/src/main/kotlin/repo/HypixelStaticData.kt
+++ b/src/main/kotlin/repo/HypixelStaticData.kt
@@ -6,6 +6,7 @@ import org.apache.logging.log4j.LogManager
import org.lwjgl.glfw.GLFW
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
+import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.serialization.SerialName
@@ -74,6 +75,7 @@ object HypixelStaticData {
while (true) {
logger.info("Updating NEU prices")
updatePrices()
+ delay(10.minutes)
}
}
}
diff --git a/src/main/resources/firmament.accesswidener b/src/main/resources/firmament.accesswidener
index 91be071..c542fc8 100644
--- a/src/main/resources/firmament.accesswidener
+++ b/src/main/resources/firmament.accesswidener
@@ -6,6 +6,7 @@ accessible field net/minecraft/client/gui/hud/InGameHud SCOREBOARD_ENTRY_COMPARA
accessible field net/minecraft/client/render/item/HeldItemRenderer itemRenderer Lnet/minecraft/client/render/item/ItemRenderer;
accessible field net/minecraft/client/render/item/ItemModels missingModelSupplier Ljava/util/function/Supplier;
+mutable field net/minecraft/client/render/model/json/ModelOverrideList conditionTypes [Lnet/minecraft/util/Identifier;
accessible class net/minecraft/client/render/model/json/ModelOverride$Deserializer
accessible class net/minecraft/client/render/model/json/ModelOverrideList$BakedOverride