diff options
author | nea <nea@nea.moe> | 2023-05-18 01:07:35 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-18 01:07:35 +0200 |
commit | 3ebe3e80b929b03ad0bcb0c76cec6b3285fe08bd (patch) | |
tree | 76ec3fb6387365320eb4805642a12d35e3ef9d65 /src/main/kotlin/moe/nea/firmament/rei | |
parent | 13f2b320c34abff8cbe1daa196a2e5e8f3f79188 (diff) | |
download | Firmament-3ebe3e80b929b03ad0bcb0c76cec6b3285fe08bd.tar.gz Firmament-3ebe3e80b929b03ad0bcb0c76cec6b3285fe08bd.tar.bz2 Firmament-3ebe3e80b929b03ad0bcb0c76cec6b3285fe08bd.zip |
Make recipes with higher stack counts properly display
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/rei')
6 files changed, 59 insertions, 51 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt b/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt index 992b104..05ea769 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/FirmamentReiPlugin.kt @@ -1,6 +1,5 @@ package moe.nea.firmament.rei -import io.github.moulberry.repo.data.NEUItem import me.shedaniel.rei.api.client.plugins.REIClientPlugin import me.shedaniel.rei.api.client.registry.category.CategoryRegistry import me.shedaniel.rei.api.client.registry.display.DisplayRegistry @@ -23,7 +22,7 @@ import moe.nea.firmament.util.SkyblockId class FirmamentReiPlugin : REIClientPlugin { companion object { - fun EntryStack<NEUItem>.asItemEntry(): EntryStack<ItemStack> { + fun EntryStack<SBItemStack>.asItemEntry(): EntryStack<ItemStack> { return EntryStack.of(VanillaEntryTypes.ITEM, value.asItemStack()) } @@ -67,7 +66,7 @@ class FirmamentReiPlugin : REIClientPlugin { override fun registerEntries(registry: EntryRegistry) { RepoManager.neuRepo.items?.items?.values?.forEach { if (!it.isVanilla) - registry.addEntry(EntryStack.of(SBItemEntryDefinition, it)) + registry.addEntry(SBItemEntryDefinition.getEntry(it)) } } } diff --git a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt index 8253c96..a6a62e6 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntryRenderer.kt @@ -1,6 +1,5 @@ package moe.nea.firmament.rei -import io.github.moulberry.repo.data.NEUItem import me.shedaniel.math.Rectangle import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer import me.shedaniel.rei.api.client.gui.widgets.Tooltip @@ -9,9 +8,9 @@ import me.shedaniel.rei.api.common.entry.EntryStack import net.minecraft.client.util.math.MatrixStack import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry -object NEUItemEntryRenderer : EntryRenderer<NEUItem> { +object NEUItemEntryRenderer : EntryRenderer<SBItemStack> { override fun render( - entry: EntryStack<NEUItem>, + entry: EntryStack<SBItemStack>, matrices: MatrixStack, bounds: Rectangle, mouseX: Int, @@ -24,7 +23,7 @@ object NEUItemEntryRenderer : EntryRenderer<NEUItem> { matrices.pop() } - override fun getTooltip(entry: EntryStack<NEUItem>, tooltipContext: TooltipContext): Tooltip? { + override fun getTooltip(entry: EntryStack<SBItemStack>, tooltipContext: TooltipContext): Tooltip? { return entry.asItemEntry().getTooltip(tooltipContext, false) } diff --git a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt index 15731cb..3e9d543 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/NEUItemEntrySerializer.kt @@ -1,25 +1,28 @@ package moe.nea.firmament.rei -import io.github.moulberry.repo.data.NEUItem import me.shedaniel.rei.api.common.entry.EntrySerializer import me.shedaniel.rei.api.common.entry.EntryStack import net.minecraft.nbt.NbtCompound import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.SkyblockId -object NEUItemEntrySerializer : EntrySerializer<NEUItem?> { +object NEUItemEntrySerializer : EntrySerializer<SBItemStack> { const val SKYBLOCK_ID_ENTRY = "SKYBLOCK_ID" + const val SKYBLOCK_ITEM_COUNT = "SKYBLOCK_ITEM_COUNT" override fun supportSaving(): Boolean = true override fun supportReading(): Boolean = true - override fun read(tag: NbtCompound): NEUItem? { - return RepoManager.getNEUItem(SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY))) + override fun read(tag: NbtCompound): SBItemStack { + val id = SkyblockId(tag.getString(SKYBLOCK_ID_ENTRY)) + val count = if (tag.contains(SKYBLOCK_ITEM_COUNT)) tag.getInt(SKYBLOCK_ITEM_COUNT) else 1 + return SBItemStack(id, RepoManager.getNEUItem(id), count) } - override fun save(entry: EntryStack<NEUItem?>, value: NEUItem?): NbtCompound { + override fun save(entry: EntryStack<SBItemStack>, value: SBItemStack): NbtCompound { return NbtCompound().apply { - putString(SKYBLOCK_ID_ENTRY, value?.skyblockItemId ?: "null") + putString(SKYBLOCK_ID_ENTRY, value.skyblockId.neuItem) + putInt(SKYBLOCK_ITEM_COUNT, value.stackSize) } } } diff --git a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt index f8dbce7..29f993c 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt @@ -16,70 +16,79 @@ import net.minecraft.text.Text import net.minecraft.util.Identifier import moe.nea.firmament.rei.FirmamentReiPlugin.Companion.asItemEntry import moe.nea.firmament.repo.ItemCache.asItemStack -import moe.nea.firmament.repo.ItemCache.getIdentifier import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.SkyblockId - -// TODO: allow stackable entries -object SBItemEntryDefinition : EntryDefinition<NEUItem> { - override fun equals(o1: NEUItem?, o2: NEUItem?, context: ComparisonContext?): Boolean { - return o1 === o2 +import moe.nea.firmament.util.skyblockId + +// TODO: add in extra data like pet info, into this structure +data class SBItemStack( + val skyblockId: SkyblockId, + val neuItem: NEUItem?, + val stackSize: Int, +) + +object SBItemEntryDefinition : EntryDefinition<SBItemStack> { + override fun equals(o1: SBItemStack, o2: SBItemStack, context: ComparisonContext): Boolean { + return o1.skyblockId == o2.skyblockId } - override fun cheatsAs(entry: EntryStack<NEUItem>?, value: NEUItem?): ItemStack { - return value.asItemStack() + override fun cheatsAs(entry: EntryStack<SBItemStack>?, value: SBItemStack): ItemStack { + return value.neuItem.asItemStack() } - override fun getValueType(): Class<NEUItem> = NEUItem::class.java - override fun getType(): EntryType<NEUItem> = EntryType.deferred(FirmamentReiPlugin.SKYBLOCK_ITEM_TYPE_ID) + override fun getValueType(): Class<SBItemStack> = SBItemStack::class.java + override fun getType(): EntryType<SBItemStack> = EntryType.deferred(FirmamentReiPlugin.SKYBLOCK_ITEM_TYPE_ID) - override fun getRenderer(): EntryRenderer<NEUItem> = NEUItemEntryRenderer + override fun getRenderer(): EntryRenderer<SBItemStack> = NEUItemEntryRenderer - override fun getSerializer(): EntrySerializer<NEUItem?> { + override fun getSerializer(): EntrySerializer<SBItemStack> { return NEUItemEntrySerializer } - override fun getTagsFor(entry: EntryStack<NEUItem>?, value: NEUItem?): Stream<out TagKey<*>>? { + override fun getTagsFor(entry: EntryStack<SBItemStack>?, value: SBItemStack?): Stream<out TagKey<*>>? { return Stream.empty() } - override fun asFormattedText(entry: EntryStack<NEUItem>, value: NEUItem): Text { + override fun asFormattedText(entry: EntryStack<SBItemStack>, value: SBItemStack): Text { return VanillaEntryTypes.ITEM.definition.asFormattedText(entry.asItemEntry(), value.asItemStack()) } - override fun hash(entry: EntryStack<NEUItem>, value: NEUItem?, context: ComparisonContext): Long { + override fun hash(entry: EntryStack<SBItemStack>, value: SBItemStack, context: ComparisonContext): Long { // Repo items are immutable, and get replaced entirely when loaded from disk - return System.identityHashCode(value) * 31L + return value.skyblockId.hashCode() * 31L } - override fun wildcard(entry: EntryStack<NEUItem>?, value: NEUItem?): NEUItem? { - return value + override fun wildcard(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { + return value.copy(stackSize = 1) } - override fun normalize(entry: EntryStack<NEUItem>?, value: NEUItem?): NEUItem? { - return value + override fun normalize(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { + return value.copy(stackSize = 1) } - override fun copy(entry: EntryStack<NEUItem>?, value: NEUItem?): NEUItem? { + override fun copy(entry: EntryStack<SBItemStack>?, value: SBItemStack): SBItemStack { return value } - override fun isEmpty(entry: EntryStack<NEUItem>?, value: NEUItem?): Boolean { - return false + override fun isEmpty(entry: EntryStack<SBItemStack>?, value: SBItemStack): Boolean { + return value.stackSize == 0 } - override fun getIdentifier(entry: EntryStack<NEUItem>?, value: NEUItem?): Identifier { - return value?.getIdentifier() ?: Identifier.of("skyblockitem", "null")!! + override fun getIdentifier(entry: EntryStack<SBItemStack>?, value: SBItemStack): Identifier { + return value.skyblockId.identifier } - fun getEntry(neuItem: NEUItem?): EntryStack<NEUItem> = - EntryStack.of(this, neuItem) + fun getEntry(sbItemStack: SBItemStack): EntryStack<SBItemStack> = + EntryStack.of(this, sbItemStack) + + fun getEntry(neuItem: NEUItem?, count: Int = 1): EntryStack<SBItemStack> = + getEntry(SBItemStack(neuItem?.skyblockId ?: SkyblockId.NULL, neuItem, 1)) - fun getEntry(skyblockId: SkyblockId?): EntryStack<NEUItem> = - EntryStack.of(this, skyblockId?.let { RepoManager.getNEUItem(it) }) + fun getEntry(skyblockId: SkyblockId, count: Int = 1): EntryStack<SBItemStack> = + getEntry(SBItemStack(skyblockId, RepoManager.getNEUItem(skyblockId), count)) - fun getEntry(ingredient: NEUIngredient?): EntryStack<NEUItem> = - getEntry(ingredient?.itemId?.let { SkyblockId(it) }) + fun getEntry(ingredient: NEUIngredient): EntryStack<SBItemStack> = + getEntry(SkyblockId(ingredient.itemId), count = ingredient.amount) } diff --git a/src/main/kotlin/moe/nea/firmament/rei/SkyblockCraftingRecipeDynamicGenerator.kt b/src/main/kotlin/moe/nea/firmament/rei/SkyblockCraftingRecipeDynamicGenerator.kt index c806ea0..f12063e 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SkyblockCraftingRecipeDynamicGenerator.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SkyblockCraftingRecipeDynamicGenerator.kt @@ -27,7 +27,7 @@ inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(noinline map object : DynamicDisplayGenerator<D> { override fun getRecipeFor(entry: EntryStack<*>): Optional<List<D>> { if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue<NEUItem>() + val item = entry.castValue<SBItemStack>() val recipes = RepoManager.getRecipesFor(item.skyblockId) val craftingRecipes = recipes.filterIsInstance<T>() return Optional.of(craftingRecipes.map(mapper)) @@ -43,7 +43,7 @@ inline fun <D : Display, reified T : NEURecipe> neuDisplayGenerator(noinline map override fun getUsageFor(entry: EntryStack<*>): Optional<List<D>> { if (entry.type != SBItemEntryDefinition.type) return Optional.empty() - val item = entry.castValue<NEUItem>() + val item = entry.castValue<SBItemStack>() val recipes = RepoManager.getUsagesFor(item.skyblockId) val craftingRecipes = recipes.filterIsInstance<T>() return Optional.of(craftingRecipes.map(mapper)) diff --git a/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt b/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt index c874fc3..75c8698 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SkyblockItemIdFocusedStackProvider.kt @@ -4,11 +4,10 @@ import dev.architectury.event.CompoundEventResult import me.shedaniel.math.Point import me.shedaniel.rei.api.client.registry.screen.FocusedStackProvider import me.shedaniel.rei.api.common.entry.EntryStack -import moe.nea.firmament.mixins.accessor.AccessorHandledScreen -import moe.nea.firmament.repo.RepoManager -import moe.nea.firmament.util.skyBlockId import net.minecraft.client.gui.screen.Screen import net.minecraft.client.gui.screen.ingame.HandledScreen +import moe.nea.firmament.mixins.accessor.AccessorHandledScreen +import moe.nea.firmament.util.skyBlockId object SkyblockItemIdFocusedStackProvider : FocusedStackProvider { override fun provide(screen: Screen?, mouse: Point?): CompoundEventResult<EntryStack<*>> { @@ -17,8 +16,7 @@ object SkyblockItemIdFocusedStackProvider : FocusedStackProvider { val focusedSlot = screen.focusedSlot_NEU ?: return CompoundEventResult.pass() val item = focusedSlot.stack ?: return CompoundEventResult.pass() val skyblockId = item.skyBlockId ?: return CompoundEventResult.pass() - val neuItem = RepoManager.getNEUItem(skyblockId) ?: return CompoundEventResult.interrupt(false, null) - return CompoundEventResult.interruptTrue(EntryStack.of(SBItemEntryDefinition, neuItem)) + return CompoundEventResult.interruptTrue(SBItemEntryDefinition.getEntry(skyblockId)) } override fun getPriority(): Double = 1_000_000.0 |