fix some bugs, inventory enhancements

This commit is contained in:
Bixilon 2021-10-07 23:28:22 +02:00
parent 3a1ece26e8
commit a85ec4c68e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 78 additions and 5 deletions

View File

@ -70,7 +70,7 @@ abstract class Entity(
var rotation: EntityRotation,
) : PhysicsEntity {
protected val random = Random
val equipment: MutableMap<EquipmentSlots, ItemStack> = mutableMapOf()
open val equipment: MutableMap<EquipmentSlots, ItemStack> = mutableMapOf()
val activeStatusEffects: MutableMap<StatusEffect, StatusEffectInstance> = synchronizedMapOf()
val attributes: MutableMap<ResourceLocation, MutableMap<UUID, StatusEffectAttributeInstance>> = synchronizedMapOf()

View File

@ -32,6 +32,9 @@ class InventorySlots {
companion object : ValuesEnum<EquipmentSlots> {
override val VALUES = values()
override val NAME_MAP: Map<String, EquipmentSlots> = KUtil.getEnumValues(VALUES)
val ARMOR_SLOTS = arrayOf(FEET, LEGS, CHEST, HEAD)
}
}
}

View File

@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
import de.bixilon.minosoft.data.inventory.InventorySlots
import de.bixilon.minosoft.data.inventory.ItemStack
import de.bixilon.minosoft.data.physics.PhysicsConstants
import de.bixilon.minosoft.data.registries.AABB
import de.bixilon.minosoft.data.registries.blocks.DefaultBlocks
@ -201,6 +202,9 @@ class LocalPlayerEntity(
val reachDistance: Double
get() = (gamemode == Gamemodes.CREATIVE).decide(5.0, 4.5)
override val equipment: MutableMap<InventorySlots.EquipmentSlots, ItemStack>
get() = inventory.equipment
private fun sendMovementPackets() {
if (Minosoft.config.config.game.camera.disableMovementSending) {
return

View File

@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.BlockUsages
import de.bixilon.minosoft.data.registries.inventory.CreativeModeTab
import de.bixilon.minosoft.data.registries.items.armor.ArmorItem
import de.bixilon.minosoft.data.registries.items.armor.DyeableArmorItem
import de.bixilon.minosoft.data.registries.items.armor.HorseArmorItem
import de.bixilon.minosoft.data.registries.items.tools.*
import de.bixilon.minosoft.data.registries.registries.Registries
@ -76,6 +77,7 @@ open class Item(
"ShovelItem" -> ShovelItem(resourceLocation, registries, data)
"PickaxeItem" -> PickaxeItem(resourceLocation, registries, data)
"HoeItem" -> HoeItem(resourceLocation, registries, data)
"DyeableArmorItem" -> DyeableArmorItem(resourceLocation, registries, data)
// "Item" -> Item(resourceLocation, data)
// else -> TODO("Can not find item class: ${data["class"].asString}")
else -> Item(resourceLocation, registries, data)

View File

@ -0,0 +1,25 @@
/*
* Minosoft
* Copyright (C) 2021 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.registries.items.armor
import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
open class DyeableArmorItem(
resourceLocation: ResourceLocation,
registries: Registries,
data: Map<String, Any>,
) : ArmorItem(resourceLocation, registries, data) {
// ToDo
}

View File

@ -34,4 +34,8 @@ open class Container(
}
}
}
operator fun get(slotId: Int): ItemStack? {
return slots[slotId]
}
}

View File

@ -13,10 +13,12 @@
package de.bixilon.minosoft.data.registries.other.containers
import de.bixilon.minosoft.data.inventory.InventorySlots
import de.bixilon.minosoft.data.inventory.ItemStack
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
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,
ContainerType(
@ -24,7 +26,31 @@ class PlayerInventory(connection: PlayConnection) : Container(
),
) {
val equipment: MutableMap<InventorySlots.EquipmentSlots, ItemStack>
get() {
val equipment: MutableMap<InventorySlots.EquipmentSlots, ItemStack> = mutableMapOf()
for (slot in InventorySlots.EquipmentSlots.ARMOR_SLOTS) {
equipment[slot] = this[slot] ?: continue
}
return equipment
}
fun getHotbarSlot(hotbarSlot: Int = connection.player.selectedHotbarSlot): ItemStack? {
check(hotbarSlot in 0..9) { "Hotbar slot out of bounds!" }
return slots[hotbarSlot + 36] // ToDo
}
operator fun get(slot: InventorySlots.EquipmentSlots): ItemStack? {
return this[when (slot) {
InventorySlots.EquipmentSlots.HEAD -> 5
InventorySlots.EquipmentSlots.CHEST -> 6
InventorySlots.EquipmentSlots.LEGS -> 7
InventorySlots.EquipmentSlots.FEET -> 8
InventorySlots.EquipmentSlots.MAIN_HAND -> connection.player.selectedHotbarSlot + 36
InventorySlots.EquipmentSlots.OFF_HAND -> 45
}]
}
}

View File

@ -32,7 +32,7 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
private val hunger = HotbarHungerElement(hudRenderer)
private val protection = HotbarProtectionElement(hudRenderer)
private val topLeft = RowLayout(hudRenderer, HorizontalAlignments.LEFT, 1) // contains health, armor, etc
private val topLeft = RowLayout(hudRenderer, HorizontalAlignments.LEFT, 1) // contains health, protection, etc
private val topRight = RowLayout(hudRenderer, HorizontalAlignments.RIGHT, 1) // contains hunger, air
private var renderElements = setOf(

View File

@ -86,6 +86,10 @@ class HotbarExperienceBarElement(hudRenderer: HUDRenderer) : Element(hudRenderer
}
}
override fun onParentChange() {
silentApply()
}
companion object {
private val SIZE = Vec2i(182, 5)
}

View File

@ -40,8 +40,8 @@ class HotbarProtectionElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
for (i in 0 until 10) {
val atlasElement = when {
protectionLeft <= 0.0f -> emptyProtection
protectionLeft < 1.0f -> halfProtection
protectionLeft < 1.0f -> emptyProtection
protectionLeft < 2.0f -> halfProtection
else -> fullProtection
}
@ -49,12 +49,16 @@ class HotbarProtectionElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
image.render(offset + Vec2i(i * ARMOR_SIZE.x, 0), z, consumer)
protectionLeft -= 1.0f
protectionLeft -= 2.0f
}
return 1
}
override fun onParentChange() {
silentApply()
}
override fun silentApply() {
val protection = hudRenderer.connection.player.protectionLevel // ToDo: Check for equipment change
@ -67,6 +71,7 @@ class HotbarProtectionElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
} else {
SIZE
}
this.protection = protection
cacheUpToDate = false
}