From 040dbca01439e6fd6afbb911beb09d73d2ee0d1e Mon Sep 17 00:00:00 2001 From: nea Date: Sat, 30 Sep 2023 00:09:40 +0200 Subject: [PATCH] Add item rarity backgrounds --- TODO.txt | 3 - .../nea/firmament/mixins/MixinInGameHud.java | 11 ++- .../firmament/events/HotbarItemRenderEvent.kt | 20 +++++ .../nea/firmament/features/FeatureManager.kt | 2 + .../features/inventory/ItemRarityCosmetics.kt | 80 ++++++++++++++++++ src/main/kotlin/moe/nea/firmament/util/MC.kt | 1 + .../assets/firmament/lang/en_us.json | 3 + .../gui/sprites/item_rarity_background.png | Bin 0 -> 5061 bytes .../item_rarity_background.png.license | 3 + 9 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/moe/nea/firmament/events/HotbarItemRenderEvent.kt create mode 100644 src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt create mode 100644 src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png create mode 100644 src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png.license diff --git a/TODO.txt b/TODO.txt index 8897bcf..53af8fe 100644 --- a/TODO.txt +++ b/TODO.txt @@ -38,8 +38,6 @@ Priority 2: - biome wands - dirt wand - block zapper -- slot binding -- uuid locking (allow items with that uuid to be moved around but not dropped/sold) Priority 3: - Item rarity halo @@ -68,5 +66,4 @@ Dungeons (planned in another mod): Custom animations for certain skyblock items. (vibrating drills for breaking, custom animations for right click and spell casting weapons) -better explosions client side inventory sorting diff --git a/src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java b/src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java index 1aac8ad..826d4e2 100644 --- a/src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java +++ b/src/main/java/moe/nea/firmament/mixins/MixinInGameHud.java @@ -6,9 +6,12 @@ package moe.nea.firmament.mixins; +import moe.nea.firmament.events.HotbarItemRenderEvent; import moe.nea.firmament.events.HudRenderEvent; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,8 +19,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(InGameHud.class) public class MixinInGameHud { - @Inject(method = "render", at = @At(value = "INVOKE",target = "Lnet/minecraft/client/network/ClientPlayerEntity;getSleepTimer()I")) + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getSleepTimer()I")) public void renderCallBack(DrawContext context, float tickDelta, CallbackInfo ci) { HudRenderEvent.Companion.publish(new HudRenderEvent(context, tickDelta)); } + + @Inject(method = "renderHotbarItem", at = @At("HEAD")) + public void onRenderHotbarItem(DrawContext context, int x, int y, float tickDelta, PlayerEntity player, ItemStack stack, int seed,CallbackInfo ci) { + if (stack != null) + HotbarItemRenderEvent.Companion.publish(new HotbarItemRenderEvent(stack, context, x, y, tickDelta)); + } } diff --git a/src/main/kotlin/moe/nea/firmament/events/HotbarItemRenderEvent.kt b/src/main/kotlin/moe/nea/firmament/events/HotbarItemRenderEvent.kt new file mode 100644 index 0000000..59660ce --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/events/HotbarItemRenderEvent.kt @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.events + +import net.minecraft.client.gui.DrawContext +import net.minecraft.item.ItemStack + +data class HotbarItemRenderEvent( + val item: ItemStack, + val context: DrawContext, + val x: Int, + val y: Int, + val tickDelta: Float, +) : FirmamentEvent() { + companion object : FirmamentEventBus() +} diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt index 72f1056..b9d343c 100644 --- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt +++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt @@ -18,6 +18,7 @@ import moe.nea.firmament.features.debug.PowerUserTools import moe.nea.firmament.features.fixes.CompatibliltyFeatures import moe.nea.firmament.features.fixes.Fixes import moe.nea.firmament.features.inventory.CraftingOverlay +import moe.nea.firmament.features.inventory.ItemRarityCosmetics import moe.nea.firmament.features.inventory.PriceData import moe.nea.firmament.features.inventory.SaveCursorPosition import moe.nea.firmament.features.inventory.SlotLocking @@ -59,6 +60,7 @@ object FeatureManager : DataHolder(serializer(), "feature loadFeature(CustomSkyBlockTextures) loadFeature(PriceData) loadFeature(Fixes) + loadFeature(ItemRarityCosmetics) if (Firmament.DEBUG) { loadFeature(DeveloperFeatures) loadFeature(DebugView) diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt new file mode 100644 index 0000000..2017b40 --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/ItemRarityCosmetics.kt @@ -0,0 +1,80 @@ +/* + * SPDX-FileCopyrightText: 2023 Linnea Gräf + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.features.inventory + +import java.awt.Color +import net.minecraft.client.gui.DrawContext +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtElement +import net.minecraft.util.Formatting +import net.minecraft.util.Identifier +import moe.nea.firmament.events.HotbarItemRenderEvent +import moe.nea.firmament.events.SlotRenderEvents +import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.gui.config.ManagedConfig +import moe.nea.firmament.util.MC + +object ItemRarityCosmetics : FirmamentFeature { + override val identifier: String + get() = "item-rarity-cosmetics" + + object TConfig : ManagedConfig(identifier) { + val showItemRarityBackground by toggle("background") { false } + val showItemRarityInHotbar by toggle("background-hotbar") { false } + } + + override val config: ManagedConfig + get() = TConfig + + private val rarityToColor = mapOf( + "COMMON" to Formatting.WHITE, + "UNCOMMON" to Formatting.GREEN, + "RARE" to Formatting.DARK_BLUE, + "EPIC" to Formatting.DARK_PURPLE, + "LEGENDARY" to Formatting.GOLD, + "LEGENJERRY" to Formatting.GOLD, + "MYTHIC" to Formatting.LIGHT_PURPLE, + "DIVINE" to Formatting.BLUE, + "SPECIAL" to Formatting.DARK_RED, + "SUPREME" to Formatting.DARK_RED, + ).mapValues { + val c = Color(it.value.colorValue!!) + Triple(c.red / 255F, c.green / 255F, c.blue / 255F) + } + private val ItemStack.skyblockLoreRarityColor: Triple? + get() { + val lore = + getOrCreateSubNbt(ItemStack.DISPLAY_KEY).getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt()) + val entry = lore.getString(lore.size - 1) + return rarityToColor.entries.find { (k, v) -> k in entry }?.value + } + + + fun drawItemStackRarity(drawContext: DrawContext, x: Int, y: Int, item: ItemStack) { + val (r, g, b) = item.skyblockLoreRarityColor ?: return + drawContext.drawSprite( + x, y, + 0, + 16, 16, + MC.guiAtlasManager.getSprite(Identifier("firmament:item_rarity_background")), + r, g, b, 1F + ) + } + + override fun onLoad() { + HotbarItemRenderEvent.subscribe { + if (!TConfig.showItemRarityInHotbar) return@subscribe + val stack = it.item + drawItemStackRarity(it.context, it.x, it.y, stack) + } + SlotRenderEvents.Before.subscribe { + if (!TConfig.showItemRarityBackground) return@subscribe + val stack = it.slot.stack ?: return@subscribe + drawItemStackRarity(it.context, it.slot.x, it.slot.y, stack) + } + } +} diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index e8611a6..50462f7 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -46,6 +46,7 @@ object MC { inline val soundManager get() = MinecraftClient.getInstance().soundManager inline val player get() = MinecraftClient.getInstance().player inline val camera get() = MinecraftClient.getInstance().cameraEntity + inline val guiAtlasManager get() = MinecraftClient.getInstance().guiAtlasManager inline val world get() = MinecraftClient.getInstance().world inline var screen get() = MinecraftClient.getInstance().currentScreen diff --git a/src/main/resources/assets/firmament/lang/en_us.json b/src/main/resources/assets/firmament/lang/en_us.json index 82bfb13..ddf459b 100644 --- a/src/main/resources/assets/firmament/lang/en_us.json +++ b/src/main/resources/assets/firmament/lang/en_us.json @@ -91,6 +91,9 @@ "firmament.config.chat-links.allow-all-hosts": "Allow all Image Hosts", "firmament.config.chat-links.allowed-hosts": "Allowed Image Hosts", "firmament.config.chat-links.position": "Chat Image Preview", + "firmament.config.item-rarity-cosmetics": "Item Rarity Cosmetics", + "firmament.config.item-rarity-cosmetics.background": "Slot Background Rarity", + "firmament.config.item-rarity-cosmetics.background-hotbar": "Hotbar Background Rarity", "firmament.hud.edit": "Edit %s", "firmament.keybinding.external": "External", "firmament.config.slot-locking": "Slot Locking", diff --git a/src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png b/src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png new file mode 100644 index 0000000000000000000000000000000000000000..c7192c3ce2d553bfb8c63468331608e9e725401e GIT binary patch literal 5061 zcmeHLYitzP6`nQmBL+KQnNm{GG~h#*|G zxF;M7hwmmTK(`PSw-Bx(&NV|WaV;Pgfc_AaYF7zS1N9LoHK4cgc3JK!b?Wbc{JEn1 zBaqh>F?N3j`c^^xb0{pxwNSqdMSrL;?%N>SSB3KnniyGFb7ys{*WD71bP^MH5yUoV zpR8@AoAofXhvR{fW;vObWL9#6z|k@<5GBNehsudM=yMf{>)7;s;c@D^&Pdg#4gh|? z9t?JdgF$!NG-7%J6GZM?Upp9ReZFzU3t!&$)ZI(V*MEH^G}1n}dC5y#_mk0z(;L5A zz2>o96_MqKYL~SCFRZMUbwHjyt`@f1kpdx-(?-F$v;-Rbu^cL`;qLGmDx+g z@Tt-0GgR5gQGBwd|MtV%m+bxi`=g7m(%)Ee;PIfzkX-XJV``` zH{AA%C;nKE_q?<1Sl^o$PW|waKb5;9+wU}X?+fmDy76q^%1ak}FI@Ns_wcn{#4CRD zchzU}Yaw`V*P}gFPozy&jid)@hJro0WZGFse?u;f)IMyv6&%-70rJwbzb4(f79hKQ z5jv6%;$FRVr-`@hY>%ot`&3CI8#Yw>b21Plv4z~ZWFnQ3a{qCXv)ZO8aD;G1HTATm8!5NVi4(DOh+P9^r=kI3*ZlL z4yC<}hxR6u-kCizR`Vc`6eo1u9+~J+8hg8N#uzYF+&qX=*6NuQ_C}jxuuY2V$+Tk> zIB(WqnmUC`510uDqp4n;z)2v@!2Fn5cuS8>J8Rb5>=wtInG=EGrub)}CvA7YfQm%q zkf9FPgN8!^(w?uZ8LFdD_R3MPE#$X_|AW>~)ZvI>P~y_0ZFr&IGbzhM5eIZF*`TH{B4` zlX#1TY^O1TBtU|sd6Dta0>@8-?!{&X0?y`iGO5#|sq!XZL=ZT762-AMor*gR_Oi%e z3^*3qaSF_i9&C}FJZhLx!$<_kspLG>9D(hmAq#~dt;1+j={h=@uGiD7Oc(63=^}=v z$ATlI`(m_v@Lu%ou%{=!q?F`+wK$?bMFg^bjK2^lnqHD{i{RcKOs zQ7VohdlbWUQmyue z_zJ?)Imq1WoE5xlHagpj?d1W7QM5#{lI<{-mwj~6Vcwf>BEyS3<{{8ERbeTf)kI2? z>S4oZ^*k$Z3@>mWbKngyQILJYr)Z)G%Ov_}Nmv4Q4vK^;;|4DXRpf* zFj10u@zXQWM=LP~sVpU74pThj9STW2PjNmW#!9>tV^rZrn`r+L`D~KEnm|=&HTPISBWb@r5})`w)V-&A8Gt&%p{A(# zdvzk8A6~Pdba&}Jd1c3rGaV=HZ!Rk<6OOp9)Ya8pIe20`pU<~1TD0ijZHsF6ZeFmd w>a#1#esg&*$tMpVeSEC!2MkS*96nz{w4JZs=)a9`0BR!K+#dSg#vObA2d&h9ga7~l literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png.license b/src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png.license new file mode 100644 index 0000000..c01d463 --- /dev/null +++ b/src/main/resources/assets/firmament/textures/gui/sprites/item_rarity_background.png.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Linnea Gräf + +SPDX-License-Identifier: CC0-1.0