From 27557903d5e470926ffdf7b62a65e16580ef73df Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:11:26 +0800 Subject: [PATCH] time to release --- .../imtoggle/quickswitch/mixin/ModConfigPageMixin.java | 2 +- src/main/kotlin/me/imtoggle/quickswitch/QuickSwitch.kt | 9 +++++++-- .../me/imtoggle/quickswitch/config/KeyBindEntry.kt | 2 +- .../me/imtoggle/quickswitch/element/ItemTypeElement.kt | 2 +- .../me/imtoggle/quickswitch/{ => element}/Selector.kt | 4 ++-- .../me/imtoggle/quickswitch/{ => util}/ItemTypes.kt | 7 +++++-- 6 files changed, 17 insertions(+), 9 deletions(-) rename src/main/kotlin/me/imtoggle/quickswitch/{ => element}/Selector.kt (82%) rename src/main/kotlin/me/imtoggle/quickswitch/{ => util}/ItemTypes.kt (82%) diff --git a/src/main/java/me/imtoggle/quickswitch/mixin/ModConfigPageMixin.java b/src/main/java/me/imtoggle/quickswitch/mixin/ModConfigPageMixin.java index 6fcbcc1..5d13e81 100644 --- a/src/main/java/me/imtoggle/quickswitch/mixin/ModConfigPageMixin.java +++ b/src/main/java/me/imtoggle/quickswitch/mixin/ModConfigPageMixin.java @@ -3,8 +3,8 @@ import cc.polyfrost.oneconfig.config.elements.OptionPage; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; import cc.polyfrost.oneconfig.utils.InputHandler; -import me.imtoggle.quickswitch.Selector; import me.imtoggle.quickswitch.config.ModConfig; +import me.imtoggle.quickswitch.element.Selector; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/kotlin/me/imtoggle/quickswitch/QuickSwitch.kt b/src/main/kotlin/me/imtoggle/quickswitch/QuickSwitch.kt index 9343ccd..5e43776 100644 --- a/src/main/kotlin/me/imtoggle/quickswitch/QuickSwitch.kt +++ b/src/main/kotlin/me/imtoggle/quickswitch/QuickSwitch.kt @@ -32,14 +32,19 @@ object QuickSwitch { } fun switchTo(type: Any): Boolean { - val index = mc.thePlayer. inventory.mainInventory + val hotbar = mc.thePlayer. inventory.mainInventory .slice(0..8) .withIndex() - .filter { (_, itemStack) -> + val index = if (type is Int) { + hotbar.firstOrNull { (_, itemStack) -> itemStack == null }?.index + } else { + hotbar.filter { (_, itemStack) -> itemStack != null && itemStack.item.isFrom(type) }.maxByOrNull { (_, itemStack) -> itemStack.stackSize }?.index + } + index?.let { switchQueue = it return true diff --git a/src/main/kotlin/me/imtoggle/quickswitch/config/KeyBindEntry.kt b/src/main/kotlin/me/imtoggle/quickswitch/config/KeyBindEntry.kt index e82cfeb..dba8275 100644 --- a/src/main/kotlin/me/imtoggle/quickswitch/config/KeyBindEntry.kt +++ b/src/main/kotlin/me/imtoggle/quickswitch/config/KeyBindEntry.kt @@ -3,7 +3,7 @@ package me.imtoggle.quickswitch.config import cc.polyfrost.oneconfig.config.annotations.Exclude import cc.polyfrost.oneconfig.config.core.OneKeyBind import cc.polyfrost.oneconfig.libs.universal.UKeyboard -import me.imtoggle.quickswitch.ItemTypes +import me.imtoggle.quickswitch.util.ItemTypes import me.imtoggle.quickswitch.MainRenderer import me.imtoggle.quickswitch.QuickSwitch import me.imtoggle.quickswitch.element.KeyBindElement diff --git a/src/main/kotlin/me/imtoggle/quickswitch/element/ItemTypeElement.kt b/src/main/kotlin/me/imtoggle/quickswitch/element/ItemTypeElement.kt index 3015601..9b3d979 100644 --- a/src/main/kotlin/me/imtoggle/quickswitch/element/ItemTypeElement.kt +++ b/src/main/kotlin/me/imtoggle/quickswitch/element/ItemTypeElement.kt @@ -8,7 +8,7 @@ import cc.polyfrost.oneconfig.libs.universal.UResolution import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.color.ColorPalette import cc.polyfrost.oneconfig.utils.dsl.mc -import me.imtoggle.quickswitch.ItemTypes +import me.imtoggle.quickswitch.util.ItemTypes import me.imtoggle.quickswitch.MainRenderer import me.imtoggle.quickswitch.util.EaseOutQuart import net.minecraft.client.renderer.GlStateManager diff --git a/src/main/kotlin/me/imtoggle/quickswitch/Selector.kt b/src/main/kotlin/me/imtoggle/quickswitch/element/Selector.kt similarity index 82% rename from src/main/kotlin/me/imtoggle/quickswitch/Selector.kt rename to src/main/kotlin/me/imtoggle/quickswitch/element/Selector.kt index 6f2010b..c88aedb 100644 --- a/src/main/kotlin/me/imtoggle/quickswitch/Selector.kt +++ b/src/main/kotlin/me/imtoggle/quickswitch/element/Selector.kt @@ -1,7 +1,7 @@ -package me.imtoggle.quickswitch +package me.imtoggle.quickswitch.element import cc.polyfrost.oneconfig.utils.InputHandler -import me.imtoggle.quickswitch.element.ItemTypeElement +import me.imtoggle.quickswitch.util.ItemTypes object Selector { diff --git a/src/main/kotlin/me/imtoggle/quickswitch/ItemTypes.kt b/src/main/kotlin/me/imtoggle/quickswitch/util/ItemTypes.kt similarity index 82% rename from src/main/kotlin/me/imtoggle/quickswitch/ItemTypes.kt rename to src/main/kotlin/me/imtoggle/quickswitch/util/ItemTypes.kt index 1bb43c0..c4d44a9 100644 --- a/src/main/kotlin/me/imtoggle/quickswitch/ItemTypes.kt +++ b/src/main/kotlin/me/imtoggle/quickswitch/util/ItemTypes.kt @@ -1,4 +1,4 @@ -package me.imtoggle.quickswitch +package me.imtoggle.quickswitch.util import net.minecraft.init.* import net.minecraft.item.* @@ -16,9 +16,12 @@ enum class ItemTypes(val type: Any, val renderItem: Item) { Egg(ItemEgg::class.java, Items.egg), Snowball(ItemSnowball::class.java, Items.snowball), EnderPearl(ItemEnderPearl::class.java, Items.ender_pearl), + Fireball(ItemFireball::class.java, Items.fire_charge), + Food(ItemFood::class.java, Items.golden_apple), Bucket(Items.bucket, Items.bucket), WaterBucket(Items.water_bucket, Items.water_bucket), - LavaBucket(Items.lava_bucket, Items.lava_bucket); + LavaBucket(Items.lava_bucket, Items.lava_bucket), + NONE(0, Item.getItemFromBlock(Blocks.barrier)); companion object { fun getRenderItem(index: Int): Item {