diff options
author | Linnea Gräf <roman.graef@gmail.com> | 2023-12-26 10:24:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-26 10:24:50 +0100 |
commit | df5972b57c2460f43434820fb3970d99df0162b8 (patch) | |
tree | 7107c1829da9fc2a553b7f1fb6ba34ae8e974d5a /src/main/kotlin | |
parent | accf3c3124126db1232f7aee2b25000d6e5d6038 (diff) | |
download | NotEnoughUpdates-df5972b57c2460f43434820fb3970d99df0162b8.tar.gz NotEnoughUpdates-df5972b57c2460f43434820fb3970d99df0162b8.tar.bz2 NotEnoughUpdates-df5972b57c2460f43434820fb3970d99df0162b8.zip |
Add more custom icons to neu custom todos (#956)
Diffstat (limited to 'src/main/kotlin')
2 files changed, 19 insertions, 7 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt index b0dab0f6..922240ed 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoEditor.kt @@ -21,7 +21,6 @@ package io.github.moulberry.notenoughupdates.miscgui.customtodos import io.github.moulberry.moulconfig.common.IItemStack import io.github.moulberry.moulconfig.forge.ForgeItemStack -import io.github.moulberry.moulconfig.gui.CloseEventListener import io.github.moulberry.moulconfig.internal.ClipboardUtils import io.github.moulberry.moulconfig.observer.ObservableList import io.github.moulberry.moulconfig.xml.Bind @@ -30,9 +29,6 @@ import io.github.moulberry.notenoughupdates.util.SBInfo import io.github.moulberry.notenoughupdates.util.Utils import io.github.moulberry.notenoughupdates.util.loadResourceLocation import net.minecraft.client.Minecraft -import net.minecraft.init.Items -import net.minecraft.item.Item -import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation class CustomTodoEditor( @@ -160,8 +156,8 @@ class CustomTodoEditor( @Bind fun getItemStack(): IItemStack { - val item = Item.getByNameOrId(icon) ?: (Items.paper) - return ForgeItemStack.of(ItemStack(item)) + val item = CustomTodoHud.parseItem(icon) + return ForgeItemStack.of(item) } @Bind diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt index 591bcedb..83d162f6 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscgui/customtodos/CustomTodoHud.kt @@ -24,10 +24,14 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.core.util.StringUtils import io.github.moulberry.notenoughupdates.events.SidebarChangeEvent import io.github.moulberry.notenoughupdates.events.TabListChangeEvent +import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.init.Items +import net.minecraft.item.ItemStack import net.minecraft.util.EnumChatFormatting import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.* @NEUAutoSubscribe object CustomTodoHud { @@ -86,6 +90,13 @@ object CustomTodoHud { } } + fun encodeCustomItem(icon: String) = "CUSTOM" + Base64.getEncoder().encodeToString(icon.encodeToByteArray()) + + fun decodeCustomItem(customString: String): String { + require(customString.startsWith("CUSTOM")) + return Base64.getDecoder().decode(customString.substring(6)).decodeToString() + } + @JvmStatic fun processInto(strings: MutableList<String>) { NotEnoughUpdates.INSTANCE.config.hidden.customTodos @@ -94,7 +105,7 @@ object CustomTodoHud { val readyAt = it.readyAtOnCurrentProfile ?: (System.currentTimeMillis() - 1000L) val until = readyAt - System.currentTimeMillis() strings.add( - "CUSTOM" + it.icon + ":§3" + it.label + ": " + + encodeCustomItem(it.icon) + ":§3" + it.label + ": " + if (until <= 0) EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.readyColour].toString() + "Ready" else if (until < 60 * 30 * 1000L) @@ -113,4 +124,9 @@ object CustomTodoHud { } } + fun parseItem(icon: String): ItemStack { + val stack = GuiInvButtonEditor.getStack(icon.uppercase()) + if (stack.metadata == 255 || (stack.item == Items.painting && stack.metadata != 0)) return ItemStack(Items.paper) + return stack + } } |