fix bugs in fast move container action, fix some tests

This commit is contained in:
Bixilon 2022-11-18 13:06:17 +01:00
parent 3e86c1f48a
commit ee52491b28
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
18 changed files with 252 additions and 86 deletions

View File

@ -108,10 +108,12 @@ class FastMoveContainerActionTest {
)
)
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, slotsOf(0 to null, 58 to ItemStack(AppleTestO.item, count = 64), 56 to ItemStack(AppleTestO.item, count = 64), 54 to ItemStack(AppleTestO.item, count = 64), 57 to ItemStack(AppleTestO.item, count = 64), 62 to ItemStack(AppleTestO.item, count = 4)), null)) // TODO: respect order of changes
connection.assertOnlyPacket(ContainerClickC2SP(9, container.serverRevision, 0, 1, 0, 0, slotsOf(0 to null, 58 to ItemStack(CoalTest0.item, count = 64), 56 to ItemStack(CoalTest0.item, count = 64), 54 to ItemStack(CoalTest0.item, count = 64), 57 to ItemStack(CoalTest0.item, count = 64), 62 to ItemStack(CoalTest0.item, count = 4)), null)) // TODO: respect order of changes
}
@Test(enabled = false)
fun fuelSlot1() {
// TODO: enable test
val connection = createConnection()
val container = createFurnace(connection)

View File

@ -22,6 +22,7 @@ import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
import de.bixilon.kutil.watcher.map.MapDataWatcher.Companion.watchedMap
import de.bixilon.minosoft.data.container.click.ContainerAction
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.SlotType
import de.bixilon.minosoft.data.container.stack.ItemStack
@ -54,7 +55,7 @@ open class Container(
val id: Int?
get() = connection.player.containers.getKey(this)
open val sections: Array<IntRange> = arrayOf()
open val sections: Array<ContainerSection> get() = emptyArray()
init {
this::floatingItem.observe(this) { it?.holder?.container = this }

View File

@ -32,8 +32,4 @@ object ContainerUtil {
return map
}
fun section(offset: Int, count: Int): IntRange {
return offset until offset + count
}
}

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.data.container
import de.bixilon.minosoft.data.container.ContainerUtil.section
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.container.types.PlayerInventory
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
@ -24,13 +24,13 @@ abstract class InventorySynchronizedContainer(
connection: PlayConnection,
type: ContainerType,
title: ChatComponent? = null,
protected var synchronizedSlots: IntRange,
protected var inventorySlots: IntRange = section(PlayerInventory.MAIN_SLOTS_START, PlayerInventory.MAIN_SLOTS),
protected var synchronizedSlots: RangeSection,
protected var inventorySlots: RangeSection = RangeSection(PlayerInventory.MAIN_SLOTS_START, PlayerInventory.MAIN_SLOTS),
) : Container(connection, type, title) {
private val playerInventory = connection.player.inventory
init {
check(synchronizedSlots.last - synchronizedSlots.first == inventorySlots.last - inventorySlots.first) { "Synchronized inventory slots must have the same size!" }
check(synchronizedSlots.count == inventorySlots.count) { "Synchronized inventory slots must have the same size!" }
// ToDo: Add initial slots from inventory
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.data.container.click
import de.bixilon.minosoft.data.container.Container
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.ContainerClickC2SP
@ -33,19 +34,19 @@ class FastMoveContainerAction(
val sourceSection = container.getSection(slot) ?: Int.MAX_VALUE
// loop over all sections and get the lowest slot in the lowest section that fits best
val targets: MutableList<IntArrayList> = mutableListOf()
val targets: MutableList<Pair<ContainerSection, IntArrayList>> = mutableListOf()
for ((index, section) in container.sections.withIndex()) {
if (index == sourceSection) {
// we don't want to swap into the same section, that is just useless
// ToDo: Is this vanilla behavior?
continue
}
if (section.isEmpty()) {
if (section.count == 0) {
continue
}
val list = IntArrayList()
targets += list
for (slot in section) {
targets += Pair(section, list)
for (slot in section.iterator()) {
val content = container.slots[slot]
if (content != null && !source.matches(content)) { // only check slots that are not empty
continue
@ -60,25 +61,31 @@ class FastMoveContainerAction(
}
val maxStack = source.item.item.maxStackSize
val changes: Int2ObjectOpenHashMap<ItemStack> = Int2ObjectOpenHashMap()
sections@ for (list in targets) {
sections@ for ((type, list) in targets) {
for (slot in list.intIterator()) {
val content = container.slots[slot]
if (content == null) {
changes[slot] = source
changes[this.slot] = null
container._set(slot, source)
container._set(this.slot, null)
break@sections
}
val content = container.slots[slot] ?: break // filling will be done one step afterwards
val countToPut = if (source.item._count + content.item._count > maxStack) maxStack - content.item._count else source.item._count
source.item._count -= countToPut
content.item._count += countToPut
changes[slot] = content
changes[this.slot] = source // duplicated
if (source.item._count <= 0) {
break
break@sections
}
}
val putting = if (type.fillReversed) list.reversed().iterator() else list.intIterator()
for (slot in putting) {
val content = container.slots[slot]
if (content != null) {
continue
}
changes[slot] = source
changes[this.slot] = null
container._set(slot, source)
container._set(this.slot, null)
break@sections
}
}
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, this.slot, 1, 0, container.createAction(this), changes, null))

View File

@ -0,0 +1,23 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.sections
interface ContainerSection {
val fillReversed: Boolean get() = false
val count: Int
operator fun contains(slot: Int): Boolean
fun iterator(): IntIterator
}

View File

@ -0,0 +1,21 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.sections
import de.bixilon.minosoft.data.container.types.PlayerInventory
class HotbarSection(val offset: Int) : RangeSection(offset, PlayerInventory.HOTBAR_SLOTS) {
override val fillReversed: Boolean get() = true
override val count: Int get() = PlayerInventory.HOTBAR_SLOTS
}

View File

@ -0,0 +1,21 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.sections
import de.bixilon.minosoft.data.container.types.PlayerInventory
class PassiveInventorySection(val offset: Int) : RangeSection(offset, PlayerInventory.PASSIVE_SLOTS) {
override val count: Int get() = PlayerInventory.PASSIVE_SLOTS
override val fillReversed: Boolean get() = true
}

View File

@ -0,0 +1,28 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.sections
open class RangeSection(offset: Int, count: Int) : ContainerSection {
private val range = offset until offset + count
val first: Int get() = range.first
override val count: Int get() = (range.last + 1) - range.first
override fun contains(slot: Int): Boolean {
return slot in range
}
override fun iterator(): IntIterator {
return range.iterator()
}
}

View File

@ -0,0 +1,28 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.sections
import de.bixilon.minosoft.util.SingleIntIterator
class SingleSlotSection(val slot: Int) : ContainerSection {
override val count: Int get() = 1
override fun iterator(): IntIterator {
return SingleIntIterator(slot)
}
override fun contains(slot: Int): Boolean {
return slot == this.slot
}
}

View File

@ -13,9 +13,12 @@
package de.bixilon.minosoft.data.container.types
import de.bixilon.minosoft.data.container.ContainerUtil.section
import de.bixilon.minosoft.data.container.InventorySynchronizedContainer
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.sections.HotbarSection
import de.bixilon.minosoft.data.container.sections.PassiveInventorySection
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.RemoveOnlySlotType
import de.bixilon.minosoft.data.container.slots.SlotType
@ -27,8 +30,8 @@ import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class CraftingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : InventorySynchronizedContainer(connection, type, title, section(CRAFTING_SLOTS + 1, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<IntRange> get() = SECTIONS
class CraftingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : InventorySynchronizedContainer(connection, type, title, RangeSection(CRAFTING_SLOTS + 1, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<ContainerSection> get() = SECTIONS
override fun getSlotType(slotId: Int): SlotType? {
if (slotId == 0) {
@ -40,19 +43,6 @@ class CraftingContainer(connection: PlayConnection, type: ContainerType, title:
return null
}
override fun getSection(slotId: Int): Int? {
if (slotId == 0) {
return 0
}
if (slotId in 1 until 1 + CRAFTING_SLOTS) {
return 1
}
if (slotId in 1 + CRAFTING_SLOTS until 1 + CRAFTING_SLOTS + PlayerInventory.MAIN_SLOTS) {
return 2
}
return null
}
override fun getSlotSwap(slot: SlotSwapContainerAction.SwapTargets): Int? {
if (slot == SlotSwapContainerAction.SwapTargets.OFFHAND) {
return null // ToDo: It is possible to press F in vanilla, but there is no slot for it
@ -65,10 +55,10 @@ class CraftingContainer(connection: PlayConnection, type: ContainerType, title:
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:crafting".toResourceLocation()
override val ALIASES: Set<ResourceLocation> = setOf("minecraft:crafting_table".toResourceLocation())
const val CRAFTING_SLOTS = 3 * 3
val SECTIONS: Array<IntRange> = arrayOf(
val SECTIONS: Array<ContainerSection> = arrayOf(
// crafting slots are not shift clickable, no section
section(CRAFTING_SLOTS + 1 + PlayerInventory.PASSIVE_SLOTS, PlayerInventory.HOTBAR_SLOTS),
section(CRAFTING_SLOTS + 1, PlayerInventory.PASSIVE_SLOTS),
HotbarSection(CRAFTING_SLOTS + 1 + PlayerInventory.PASSIVE_SLOTS),
PassiveInventorySection(CRAFTING_SLOTS + 1),
)

View File

@ -14,9 +14,12 @@
package de.bixilon.minosoft.data.container.types
import de.bixilon.minosoft.data.container.Container
import de.bixilon.minosoft.data.container.ContainerUtil.section
import de.bixilon.minosoft.data.container.InventorySynchronizedContainer
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.sections.HotbarSection
import de.bixilon.minosoft.data.container.sections.PassiveInventorySection
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.EnchantableSlotType
import de.bixilon.minosoft.data.container.slots.SlotType
@ -31,8 +34,8 @@ import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class EnchantingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : InventorySynchronizedContainer(connection, type, title, section(ENCHANTING_SLOTS, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<IntRange> get() = SECTIONS
class EnchantingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : InventorySynchronizedContainer(connection, type, title, RangeSection(ENCHANTING_SLOTS, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<ContainerSection> get() = SECTIONS
val costs = IntArray(ENCHANTING_OPTIONS) { -1 }
val enchantments: Array<Enchantment?> = arrayOfNulls(ENCHANTING_OPTIONS)
var enchantmentLevels = IntArray(ENCHANTING_OPTIONS) { -1 }
@ -79,10 +82,10 @@ class EnchantingContainer(connection: PlayConnection, type: ContainerType, title
const val ENCHANTING_OPTIONS = 3
private val SECTIONS: Array<IntRange> = arrayOf(
section(0, ENCHANTING_SLOTS),
section(ENCHANTING_SLOTS + PlayerInventory.PASSIVE_SLOTS, PlayerInventory.HOTBAR_SLOTS),
section(ENCHANTING_SLOTS, PlayerInventory.PASSIVE_SLOTS),
private val SECTIONS: Array<ContainerSection> = arrayOf(
RangeSection(0, ENCHANTING_SLOTS),
HotbarSection(ENCHANTING_SLOTS + PlayerInventory.PASSIVE_SLOTS),
PassiveInventorySection(ENCHANTING_SLOTS),
)
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): EnchantingContainer {

View File

@ -19,6 +19,10 @@ import de.bixilon.kutil.watcher.map.MapDataWatcher.Companion.observeMap
import de.bixilon.minosoft.data.container.Container
import de.bixilon.minosoft.data.container.InventorySlots
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.sections.HotbarSection
import de.bixilon.minosoft.data.container.sections.PassiveInventorySection
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.RemoveOnlySlotType
import de.bixilon.minosoft.data.container.slots.SlotType
@ -37,7 +41,7 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
// https://c4k3.github.io/wiki.vg/images/1/13/Inventory-slots.png
class PlayerInventory(connection: PlayConnection) : Container(connection = connection, type = TYPE) {
override val sections: Array<IntRange> get() = SECTIONS
override val sections: Array<ContainerSection> get() = SECTIONS
val equipment: LockMap<InventorySlots.EquipmentSlots, ItemStack> = lockMapOf()
init {
@ -162,10 +166,10 @@ class PlayerInventory(connection: PlayConnection) : Container(connection = conne
const val HOTBAR_SLOTS = MAIN_SLOTS_PER_ROW
const val OFFHAND_SLOT = 45
private val SECTIONS = arrayOf(
ARMOR_OFFSET..ARMOR_OFFSET + 4,
ARMOR_OFFSET + 5 until HOTBAR_OFFSET,
HOTBAR_OFFSET..HOTBAR_OFFSET + HOTBAR_SLOTS,
private val SECTIONS = arrayOf<ContainerSection>(
RangeSection(ARMOR_OFFSET, 4),
PassiveInventorySection(ARMOR_OFFSET + 5),
HotbarSection(HOTBAR_OFFSET),
)
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): PlayerInventory {

View File

@ -13,9 +13,12 @@
package de.bixilon.minosoft.data.container.types.generic
import de.bixilon.minosoft.data.container.ContainerUtil.section
import de.bixilon.minosoft.data.container.InventorySynchronizedContainer
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.ContainerSection
import de.bixilon.minosoft.data.container.sections.HotbarSection
import de.bixilon.minosoft.data.container.sections.PassiveInventorySection
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.SlotType
import de.bixilon.minosoft.data.container.types.PlayerInventory
@ -28,11 +31,11 @@ abstract class GenericContainer(
connection: PlayConnection,
type: ContainerType,
title: ChatComponent?,
) : InventorySynchronizedContainer(connection, type, title, section(rows * SLOTS_PER_ROW, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<IntRange> = arrayOf(
section(0, rows * SLOTS_PER_ROW),
section(rows * SLOTS_PER_ROW + PlayerInventory.PASSIVE_SLOTS, PlayerInventory.HOTBAR_SLOTS),
section(rows * SLOTS_PER_ROW, PlayerInventory.PASSIVE_SLOTS),
) : InventorySynchronizedContainer(connection, type, title, RangeSection(rows * SLOTS_PER_ROW, PlayerInventory.MAIN_SLOTS)) {
override val sections: Array<ContainerSection> = arrayOf(
RangeSection(0, rows * SLOTS_PER_ROW),
HotbarSection(rows * SLOTS_PER_ROW + PlayerInventory.PASSIVE_SLOTS),
PassiveInventorySection(rows * SLOTS_PER_ROW),
)
override fun getSlotType(slotId: Int): SlotType? {

View File

@ -14,8 +14,9 @@
package de.bixilon.minosoft.data.container.types.processing
import de.bixilon.minosoft.data.container.InventorySynchronizedContainer
import de.bixilon.minosoft.data.container.sections.RangeSection
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
abstract class ProcessingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?, synchronizedSlots: IntRange) : InventorySynchronizedContainer(connection, type, title, synchronizedSlots)
abstract class ProcessingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?, synchronizedSlots: RangeSection) : InventorySynchronizedContainer(connection, type, title, synchronizedSlots)

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.data.container.types.processing.smelting
import de.bixilon.minosoft.data.container.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.sections.*
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.FuelSlotType
import de.bixilon.minosoft.data.container.slots.RemoveOnlySlotType
@ -24,7 +25,7 @@ import de.bixilon.minosoft.data.registries.other.containers.ContainerType
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
abstract class SmeltingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : ProcessingContainer(connection, type, title, (SMELTING_SLOTS) until (SMELTING_SLOTS + PlayerInventory.MAIN_SLOTS)) {
abstract class SmeltingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : ProcessingContainer(connection, type, title, RangeSection(SMELTING_SLOTS, PlayerInventory.MAIN_SLOTS)) {
var processTime: Int = 0
private set
get() = minOf(field, maxProcessTime)
@ -37,12 +38,12 @@ abstract class SmeltingContainer(connection: PlayConnection, type: ContainerType
var maxFuel: Int = 0
private set
override val sections: Array<IntRange> get() = SECTIONS
override val sections: Array<ContainerSection> get() = SECTIONS
override fun getSlotType(slotId: Int): SlotType? {
if (slotId == 0) {
return DefaultSlotType // ToDo: only smeltable items (check recipes)
return SmeltingSlot
}
if (slotId == 1) {
return FuelSlotType
@ -56,22 +57,6 @@ abstract class SmeltingContainer(connection: PlayConnection, type: ContainerType
return null
}
override fun getSection(slotId: Int): Int? {
if (slotId == 2) {
return 0
}
if (slotId == 1) {
return 1
}
if (slotId == 0) {
return 2
}
if (slotId in SMELTING_SLOTS until SMELTING_SLOTS + PlayerInventory.MAIN_SLOTS) {
return 3
}
return null
}
override fun getSlotSwap(slot: SlotSwapContainerAction.SwapTargets): Int? {
if (slot == SlotSwapContainerAction.SwapTargets.OFFHAND) {
return null // ToDo: It is possible to press F in vanilla, but there is no slot for it
@ -92,11 +77,12 @@ abstract class SmeltingContainer(connection: PlayConnection, type: ContainerType
companion object {
const val SMELTING_SLOTS = 3
val SECTIONS: Array<IntRange> = arrayOf(
2..2,
1..1,
0..0,
SMELTING_SLOTS..SMELTING_SLOTS + PlayerInventory.MAIN_SLOTS,
val SECTIONS: Array<ContainerSection> = arrayOf(
SingleSlotSection(2),
SingleSlotSection(1),
SingleSlotSection(0),
HotbarSection(SMELTING_SLOTS + PlayerInventory.PASSIVE_SLOTS),
PassiveInventorySection(SMELTING_SLOTS),
)
}
}

View File

@ -0,0 +1,21 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.container.types.processing.smelting
import de.bixilon.minosoft.data.container.slots.SlotType
@Deprecated("TODO: Not yet implemented")
object SmeltingSlot : SlotType {
// ToDo: only smeltable items (check recipes)
}

View File

@ -0,0 +1,31 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.util
@Deprecated("kutil 1.18")
class SingleIntIterator(private val number: Int) : IntIterator() {
private var next = true
override fun hasNext(): Boolean {
return next
}
override fun nextInt(): Int {
if (!next) {
throw IllegalStateException("Already iterated!")
}
next = false
return number
}
}