wip processing containers

This commit is contained in:
Bixilon 2022-05-03 12:24:34 +02:00
parent 67d6d8fb14
commit c94d50a52b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
14 changed files with 433 additions and 12 deletions

View File

@ -220,6 +220,8 @@ open class Container(
revision++
}
open fun readProperty(property: Int, value: Int) = Unit
companion object : ContainerFactory<Container> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:container".toResourceLocation()

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* 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.
*
@ -17,6 +17,5 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation
@Deprecated("Will be removed")
object DefaultInventoryTypes {
val CHEST = "minecraft:chest".toResourceLocation()
val HORSE = "minecraft:EntityHorse".toResourceLocation()
}

View File

@ -0,0 +1,17 @@
/*
* 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.slots
@Deprecated("ToDo")
object FuelSlotType : SlotType

View File

@ -26,13 +26,13 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class CraftingContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : Container(connection, type, title) {
override val sections: Array<IntRange> = arrayOf(0..0, 1 until 1 + CRAFTING_SLOTS, 1 + CRAFTING_SLOTS until 1 + CRAFTING_SLOTS + SLOTS_PER_ROW * ROWS)
override val sections: Array<IntRange> = arrayOf(0..0, 1 until 1 + CRAFTING_SLOTS, 1 + CRAFTING_SLOTS until 1 + CRAFTING_SLOTS + PlayerInventory.MAIN_SLOTS)
override fun getSlotType(slotId: Int): SlotType? {
if (slotId == 0) {
return RemoveOnlySlotType
}
if (slotId in 1 until 1 + CRAFTING_SLOTS + SLOTS_PER_ROW * ROWS) {
if (slotId in 1 until 1 + CRAFTING_SLOTS + PlayerInventory.MAIN_SLOTS) {
return DefaultSlotType
}
return null
@ -45,7 +45,7 @@ class CraftingContainer(connection: PlayConnection, type: ContainerType, title:
if (slotId in 1 until 1 + CRAFTING_SLOTS) {
return 1
}
if (slotId in 1 + CRAFTING_SLOTS until 1 + CRAFTING_SLOTS + SLOTS_PER_ROW * ROWS) {
if (slotId in 1 + CRAFTING_SLOTS until 1 + CRAFTING_SLOTS + PlayerInventory.MAIN_SLOTS) {
return 2
}
return null
@ -55,15 +55,13 @@ class CraftingContainer(connection: PlayConnection, type: ContainerType, title:
if (slot == SlotSwapContainerAction.SwapTargets.OFFHAND) {
return null // ToDo: It is possible to press F in vanilla, but there is no slot for it
}
return 1 + CRAFTING_SLOTS + SLOTS_PER_ROW * 3 + slot.ordinal
return 1 + CRAFTING_SLOTS + PlayerInventory.MAIN_SLOTS_PER_ROW * 3 + slot.ordinal
}
companion object : ContainerFactory<CraftingContainer> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:crafting".toResourceLocation()
const val CRAFTING_SLOTS = 3 * 3
const val SLOTS_PER_ROW = 9
const val ROWS = 4
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): CraftingContainer {
return CraftingContainer(connection, type, title)

View File

@ -150,9 +150,13 @@ class PlayerInventory(connection: PlayConnection) : Container(connection = conne
resourceLocation = RESOURCE_LOCATION,
factory = this,
)
const val HOTBAR_OFFSET = 36
const val MAIN_SLOTS_PER_ROW = 9
const val MAIN_ROWS = 4
const val MAIN_SLOTS = MAIN_SLOTS_PER_ROW * MAIN_ROWS
const val HOTBAR_OFFSET = (MAIN_ROWS - 1) * MAIN_SLOTS_PER_ROW
const val ARMOR_OFFSET = 5
const val HOTBAR_SLOTS = 9
const val HOTBAR_SLOTS = MAIN_SLOTS_PER_ROW
const val OFFHAND_SLOT = 45
private val SECTIONS = arrayOf(

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
import de.bixilon.minosoft.data.container.Container
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?) : Container(connection, type, title)

View File

@ -0,0 +1,33 @@
/*
* 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.types.CraftingContainer
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.other.containers.ContainerFactory
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
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class BlastFurnaceContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : SmeltingContainer(connection, type, title) {
companion object : ContainerFactory<CraftingContainer> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:blast_furnace".toResourceLocation()
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): CraftingContainer {
return CraftingContainer(connection, type, title)
}
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.types.CraftingContainer
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.other.containers.ContainerFactory
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
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class FurnaceContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : SmeltingContainer(connection, type, title) {
companion object : ContainerFactory<CraftingContainer> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:furnace".toResourceLocation()
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): CraftingContainer {
return CraftingContainer(connection, type, title)
}
}
}

View File

@ -0,0 +1,91 @@
/*
* 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.click.SlotSwapContainerAction
import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.FuelSlotType
import de.bixilon.minosoft.data.container.slots.RemoveOnlySlotType
import de.bixilon.minosoft.data.container.slots.SlotType
import de.bixilon.minosoft.data.container.types.CraftingContainer
import de.bixilon.minosoft.data.container.types.PlayerInventory
import de.bixilon.minosoft.data.container.types.processing.ProcessingContainer
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) {
var processTime: Int = 0
private set
get() = minOf(field, maxProcessTime)
var maxProcessTime: Int = 200
private set
var fuel: Int = 0
private set
get() = minOf(field, maxFuel)
var maxFuel: Int = 0
private set
override fun getSlotType(slotId: Int): SlotType? {
if (slotId == 0) {
return DefaultSlotType // ToDo: only smeltable items
}
if (slotId == 1) {
return FuelSlotType
}
if (slotId == 2) {
return RemoveOnlySlotType
}
if (slotId in SMELTING_SLOTS until +SMELTING_SLOTS + PlayerInventory.MAIN_SLOTS) {
return DefaultSlotType
}
return null
}
override fun getSection(slotId: Int): Int? {
if (slotId == 2) {
return 0
}
if (slotId == 0 || slotId == 1) {
return 1
}
if (slotId in SMELTING_SLOTS until SMELTING_SLOTS + CraftingContainer.CRAFTING_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
}
return SMELTING_SLOTS + PlayerInventory.MAIN_SLOTS_PER_ROW * 3 + slot.ordinal
}
override fun readProperty(property: Int, value: Int) {
when (property) {
0 -> this.fuel = maxOf(value, 0)
1 -> this.maxFuel = maxOf(value, 0)
2 -> this.processTime = maxOf(value, 0)
3 -> this.maxProcessTime = maxOf(value, 0)
else -> super.readProperty(property, value)
}
}
companion object {
const val SMELTING_SLOTS = 3
}
}

View File

@ -0,0 +1,33 @@
/*
* 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.types.CraftingContainer
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.other.containers.ContainerFactory
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
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class SmokerContainer(connection: PlayConnection, type: ContainerType, title: ChatComponent?) : SmeltingContainer(connection, type, title) {
companion object : ContainerFactory<CraftingContainer> {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:smoker".toResourceLocation()
override fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent?): CraftingContainer {
return CraftingContainer(connection, type, title)
}
}
}

View File

@ -20,6 +20,5 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
interface ContainerFactory<T : Container> : CompanionResourceLocation {
fun build(connection: PlayConnection, type: ContainerType, title: ChatComponent? = null): T
}

View File

@ -16,6 +16,9 @@ package de.bixilon.minosoft.data.registries.other.containers
import de.bixilon.minosoft.data.container.types.CraftingContainer
import de.bixilon.minosoft.data.container.types.PlayerInventory
import de.bixilon.minosoft.data.container.types.generic.*
import de.bixilon.minosoft.data.container.types.processing.smelting.BlastFurnaceContainer
import de.bixilon.minosoft.data.container.types.processing.smelting.FurnaceContainer
import de.bixilon.minosoft.data.container.types.processing.smelting.SmokerContainer
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
object DefaultContainerFactories : DefaultFactory<ContainerFactory<*>>(
@ -29,4 +32,8 @@ object DefaultContainerFactories : DefaultFactory<ContainerFactory<*>>(
Generic9x6Container,
CraftingContainer,
BlastFurnaceContainer,
FurnaceContainer,
SmokerContainer,
)

View File

@ -12,6 +12,7 @@
*/
package de.bixilon.minosoft.protocol.packets.s2c.play.container
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
@ -21,10 +22,14 @@ import de.bixilon.minosoft.util.logging.LogMessageType
@LoadPacket
class ContainerPropertiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val containerId: Byte = buffer.readByte()
val containerId = buffer.readUnsignedByte()
val property = buffer.readUnsignedShort()
val value = buffer.readUnsignedShort()
override fun handle(connection: PlayConnection) {
connection.player.containers[containerId]?.readProperty(property, value)
}
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Container properties (containerId=$containerId, property=$property, value=$value)" }
}

View File

@ -1368,5 +1368,184 @@
"start": [96, 10],
"end": [102, 31]
}
},
"minecraft:furnace_container": {
"0": {
"start": [0, 0],
"end": [176, 166],
"texture": "minecraft:textures/gui/container/furnace.png",
"slots": {
"0": {
"start": [56, 17],
"end": [72, 33]
},
"1": {
"start": [56, 53],
"end": [72, 69]
},
"2": {
"start": [112, 31],
"end": [136, 55]
},
"3": {
"start": [8, 84],
"end": [25, 101]
},
"4": {
"start": [26, 84],
"end": [43, 101]
},
"5": {
"start": [44, 84],
"end": [61, 101]
},
"6": {
"start": [62, 84],
"end": [79, 101]
},
"7": {
"start": [80, 84],
"end": [97, 101]
},
"8": {
"start": [98, 84],
"end": [115, 101]
},
"9": {
"start": [116, 84],
"end": [133, 101]
},
"10": {
"start": [134, 84],
"end": [151, 101]
},
"11": {
"start": [152, 84],
"end": [169, 101]
},
"12": {
"start": [8, 102],
"end": [25, 119]
},
"13": {
"start": [26, 102],
"end": [43, 119]
},
"14": {
"start": [44, 102],
"end": [61, 119]
},
"15": {
"start": [62, 102],
"end": [79, 119]
},
"16": {
"start": [80, 102],
"end": [97, 119]
},
"17": {
"start": [98, 102],
"end": [115, 119]
},
"18": {
"start": [116, 102],
"end": [133, 119]
},
"19": {
"start": [134, 102],
"end": [151, 119]
},
"20": {
"start": [152, 102],
"end": [169, 119]
},
"21": {
"start": [8, 120],
"end": [25, 137]
},
"22": {
"start": [26, 120],
"end": [43, 137]
},
"23": {
"start": [44, 120],
"end": [61, 137]
},
"24": {
"start": [62, 120],
"end": [79, 137]
},
"25": {
"start": [80, 120],
"end": [97, 137]
},
"26": {
"start": [98, 120],
"end": [115, 137]
},
"27": {
"start": [116, 120],
"end": [133, 137]
},
"28": {
"start": [134, 120],
"end": [151, 137]
},
"29": {
"start": [152, 120],
"end": [169, 137]
},
"30": {
"start": [8, 142],
"end": [25, 159]
},
"31": {
"start": [26, 142],
"end": [43, 159]
},
"32": {
"start": [44, 142],
"end": [61, 159]
},
"33": {
"start": [62, 142],
"end": [79, 159]
},
"34": {
"start": [80, 142],
"end": [97, 159]
},
"35": {
"start": [98, 142],
"end": [115, 159]
},
"36": {
"start": [116, 142],
"end": [133, 159]
},
"37": {
"start": [134, 142],
"end": [151, 159]
},
"38": {
"start": [152, 142],
"end": [169, 159]
}
}
}
},
"minecraft:furnace_container_fuel": {
"0": {
"start": [176, 0],
"end": [190, 14],
"texture": "minecraft:textures/gui/container/furnace.png"
}
},
"minecraft:furnace_container_process": {
"0": {
"start": [176, 14],
"end": [199, 30],
"texture": "minecraft:textures/gui/container/furnace.png"
}
}
}