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 | |
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')
3 files changed, 21 insertions, 12 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index ca244303..cf111078 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.overlays; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; +import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodo; import io.github.moulberry.notenoughupdates.miscgui.customtodos.CustomTodoHud; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.util.ItemUtils; @@ -174,11 +175,7 @@ public class TimersOverlay extends TextTabOverlay { String clean = Utils.cleanColour(line); String beforeColon = clean.split(":")[0]; if (beforeColon.startsWith("CUSTOM")) { - var item = Item.getByNameOrId(beforeColon.substring(6)); - if (item == null) { - item = Items.paper; - } - icon = new ItemStack(item); + icon = CustomTodoHud.INSTANCE.parseItem(CustomTodoHud.INSTANCE.decodeCustomItem(beforeColon)); } else switch (beforeColon) { case "Cakes": 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 + } } |