fix: Don't hide global overrides for textures with extra attributes ids
This commit is contained in:
@@ -5,28 +5,39 @@ import kotlin.jvm.optionals.getOrNull
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.Identifier
|
||||
import moe.nea.firmament.util.collections.WeakCache
|
||||
import moe.nea.firmament.util.mc.IntrospectableItemModelManager
|
||||
|
||||
// TODO: assert an order on these events
|
||||
data class CustomItemModelEvent(
|
||||
val itemStack: ItemStack,
|
||||
val itemModelManager: IntrospectableItemModelManager,
|
||||
var overrideModel: Identifier? = null,
|
||||
) : FirmamentEvent() {
|
||||
companion object : FirmamentEventBus<CustomItemModelEvent>() {
|
||||
val cache = WeakCache.memoize("ItemModelIdentifier", ::getModelIdentifier0)
|
||||
|
||||
@JvmStatic
|
||||
fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
|
||||
fun getModelIdentifier(itemStack: ItemStack?, itemModelManager: IntrospectableItemModelManager): Identifier? {
|
||||
if (itemStack == null) return null
|
||||
return cache.invoke(itemStack).getOrNull()
|
||||
return cache.invoke(itemStack, itemModelManager).getOrNull()
|
||||
}
|
||||
|
||||
fun getModelIdentifier0(itemStack: ItemStack): Optional<Identifier> {
|
||||
fun getModelIdentifier0(
|
||||
itemStack: ItemStack,
|
||||
itemModelManager: IntrospectableItemModelManager
|
||||
): Optional<Identifier> {
|
||||
// TODO: add an error / warning if the model does not exist
|
||||
return Optional.ofNullable(publish(CustomItemModelEvent(itemStack)).overrideModel)
|
||||
return Optional.ofNullable(publish(CustomItemModelEvent(itemStack, itemModelManager)).overrideModel)
|
||||
}
|
||||
}
|
||||
|
||||
fun overrideIfExists(overrideModel: Identifier) {
|
||||
this.overrideModel = overrideModel
|
||||
if (itemModelManager.hasModel_firmament(overrideModel))
|
||||
this.overrideModel = overrideModel
|
||||
}
|
||||
|
||||
fun overrideIfEmpty(identifier: Identifier) {
|
||||
if (overrideModel == null)
|
||||
overrideModel = identifier
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import moe.nea.firmament.mixins.accessor.AccessorHandledScreen
|
||||
import moe.nea.firmament.util.ClipboardUtils
|
||||
import moe.nea.firmament.util.MC
|
||||
import moe.nea.firmament.util.focusedItemStack
|
||||
import moe.nea.firmament.util.mc.IntrospectableItemModelManager
|
||||
import moe.nea.firmament.util.mc.SNbtFormatter.Companion.toPrettyString
|
||||
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
|
||||
import moe.nea.firmament.util.mc.loreAccordingToNbt
|
||||
@@ -119,7 +120,11 @@ object PowerUserTools : FirmamentFeature {
|
||||
lastCopiedStack =
|
||||
Pair(item, Text.stringifiedTranslatable("firmament.tooltip.copied.skyblockid", sbId.neuItem))
|
||||
} else if (it.matches(TConfig.copyTexturePackId)) {
|
||||
val model = CustomItemModelEvent.getModelIdentifier(item) // TODO: remove global texture overrides, maybe
|
||||
val model = CustomItemModelEvent.getModelIdentifier0(item, object : IntrospectableItemModelManager {
|
||||
override fun hasModel_firmament(identifier: Identifier): Boolean {
|
||||
return true
|
||||
}
|
||||
}).getOrNull() // TODO: remove global texture overrides, maybe
|
||||
if (model == null) {
|
||||
lastCopiedStack = Pair(item, Text.translatable("firmament.tooltip.copied.modelid.fail"))
|
||||
return
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package moe.nea.firmament.util.mc
|
||||
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
interface IntrospectableItemModelManager {
|
||||
fun hasModel_firmament(identifier: Identifier): Boolean
|
||||
}
|
||||
36
src/test/resources/testdata/items/books/feather_falling.snbt
vendored
Normal file
36
src/test/resources/testdata/items/books/feather_falling.snbt
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
components: {
|
||||
"minecraft:attribute_modifiers": {
|
||||
modifiers: [
|
||||
],
|
||||
show_in_tooltip: 0b
|
||||
},
|
||||
"minecraft:custom_data": {
|
||||
enchantments: {
|
||||
feather_falling: 6
|
||||
},
|
||||
id: "ENCHANTED_BOOK",
|
||||
timestamp: 1737123521091L,
|
||||
uuid: "b8128489-9ed0-4a1a-94c0-d3279ffe45ac"
|
||||
},
|
||||
"minecraft:custom_name": '{"extra":[{"color":"blue","text":"Enchanted Book"}],"italic":false,"text":""}',
|
||||
"minecraft:hide_additional_tooltip": {
|
||||
},
|
||||
"minecraft:lore": [
|
||||
'{"extra":[{"color":"blue","text":"Feather Falling VI"}],"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"Increases how high you can fall"}],"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"before taking fall damage by "},{"color":"green","text":"6"},{"color":"gray","text":" and"}],"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"reduces fall damage by "},{"color":"green","text":"30%"},{"color":"gray","text":"."}],"italic":false,"text":""}',
|
||||
'{"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"Applicable on: "},{"color":"blue","text":"Boots"}],"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":""},{"color":"gray","text":"Apply Cost: "},{"color":"dark_aqua","text":"60 Exp Levels"}],"italic":false,"text":""}',
|
||||
'{"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"Use this on an item in an Anvil to"}],"italic":false,"text":""}',
|
||||
'{"extra":[{"color":"gray","text":"apply it!"}],"italic":false,"text":""}',
|
||||
'{"italic":false,"text":""}',
|
||||
'{"extra":[{"bold":true,"color":"blue","text":"RARE"}],"italic":false,"text":""}'
|
||||
]
|
||||
},
|
||||
count: 1,
|
||||
id: "minecraft:enchanted_book"
|
||||
}
|
||||
@@ -76,7 +76,7 @@ object CustomSkyBlockTextures : FirmamentFeature {
|
||||
fun onCustomModelId(it: CustomItemModelEvent) {
|
||||
if (!TConfig.enabled) return
|
||||
val id = it.itemStack.skyBlockId ?: return
|
||||
it.overrideIfExists(Identifier.of("firmskyblock", id.identifier.path))
|
||||
it.overrideIfEmpty(Identifier.of("firmskyblock", id.identifier.path))
|
||||
}
|
||||
|
||||
private val skullTextureCache =
|
||||
|
||||
@@ -17,7 +17,7 @@ class ItemPredicate(
|
||||
val item: Item
|
||||
) : FirmamentModelPredicate {
|
||||
override fun test(stack: ItemStack): Boolean {
|
||||
return stack.item == item
|
||||
return stack.isOf(item)
|
||||
}
|
||||
|
||||
object Parser : FirmamentModelPredicateParser {
|
||||
|
||||
@@ -4,42 +4,40 @@ package moe.nea.firmament.mixins.custommodels;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import moe.nea.firmament.events.CustomItemModelEvent;
|
||||
import moe.nea.firmament.util.mc.IntrospectableItemModelManager;
|
||||
import net.minecraft.client.item.ItemModelManager;
|
||||
import net.minecraft.client.render.item.model.ItemModel;
|
||||
import net.minecraft.client.render.item.model.MissingItemModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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 org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(ItemModelManager.class)
|
||||
public class ReplaceItemModelPatch {
|
||||
public class ReplaceItemModelPatch implements IntrospectableItemModelManager {
|
||||
@Shadow
|
||||
@Final
|
||||
private Function<Identifier, ItemModel> modelGetter;
|
||||
|
||||
@Unique
|
||||
private boolean hasModel(Identifier identifier) {
|
||||
return !(modelGetter.apply(identifier) instanceof MissingItemModel);
|
||||
}
|
||||
|
||||
@WrapOperation(
|
||||
method = "update(Lnet/minecraft/client/render/item/ItemRenderState;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;get(Lnet/minecraft/component/ComponentType;)Ljava/lang/Object;"))
|
||||
private Object replaceItemModelByIdentifier(ItemStack instance, ComponentType componentType, Operation<Object> original) {
|
||||
var override = CustomItemModelEvent.getModelIdentifier(instance);
|
||||
if (override != null && hasModel(override)) {
|
||||
var override = CustomItemModelEvent.getModelIdentifier(instance, this);
|
||||
if (override != null && hasModel_firmament(override)) {
|
||||
return override;
|
||||
}
|
||||
return original.call(instance, componentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasModel_firmament(@NotNull Identifier identifier) {
|
||||
return !(modelGetter.apply(identifier) instanceof MissingItemModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,8 @@ public class SupplyFakeModelPatch {
|
||||
Map<Identifier, ItemAsset> newModels = new HashMap<>(oldModels.contents());
|
||||
var resources = resourceManager.findResources(
|
||||
"models/item",
|
||||
id -> id.getNamespace().equals("firmskyblock")
|
||||
&& id.getPath().endsWith(".json")
|
||||
&& !id.getPath().substring("models/item/".length()).contains("/"));
|
||||
id -> (id.getNamespace().equals("firmskyblock") || id.getNamespace().equals("cittofirmgenerated"))
|
||||
&& id.getPath().endsWith(".json"));
|
||||
for (Map.Entry<Identifier, Resource> model : resources.entrySet()) {
|
||||
var resource = model.getValue();
|
||||
var itemModelId = model.getKey().withPath(it -> it.substring("models/item/".length(), it.length() - ".json".length()));
|
||||
|
||||
Reference in New Issue
Block a user