add some block entities

This commit is contained in:
Bixilon 2021-04-17 00:53:24 +02:00
parent 1f2d74b1f3
commit 97011d84c5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
11 changed files with 206 additions and 4 deletions

View File

@ -0,0 +1,34 @@
/*
* 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.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
class BlastBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
override fun updateNBT(nbt: CompoundTag) {
}
companion object : BlockEntityFactory<BlastBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:blast_furnace")
override fun build(connection: PlayConnection): BlastBlockEntity {
return BlastBlockEntity(connection)
}
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.entities.block
import de.bixilon.minosoft.data.inventory.ItemStack
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
import de.bixilon.minosoft.util.nbt.tag.NBTTag
class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
val items: Array<ItemStack?> = arrayOfNulls(RenderConstants.CAMPFIRE_ITEMS)
override fun updateNBT(nbt: CompoundTag) {
val itemArray = nbt.getListTag("Items")?.getValue<NBTTag>() as List<NBTTag>? ?: return
for (slot in itemArray) {
check(slot is CompoundTag)
val itemStack = ItemStack(connection.mapping.itemRegistry.get(slot.getStringTag("id").value)!!, connection.version)
itemStack.itemCount = slot.getNumberTag("Count").asInt
items[slot.getNumberTag("Slot").asInt] = itemStack
}
}
companion object : BlockEntityFactory<CampfireBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:campfire")
override fun build(connection: PlayConnection): CampfireBlockEntity {
return CampfireBlockEntity(connection)
}
}
}

View File

@ -22,7 +22,12 @@ object DefaultBlockEntityMetaDataFactory {
init { init {
val entityFactories: List<BlockEntityFactory<out BlockEntity>> = listOf( val entityFactories: List<BlockEntityFactory<out BlockEntity>> = listOf(
BedBlockEntity BedBlockEntity,
HopperBlockEntity,
SignBlockEntity,
BlastBlockEntity,
FurnaceBlockEntity,
CampfireBlockEntity,
) )
val ret: MutableMap<ResourceLocation, BlockEntityFactory<out BlockEntity>> = mutableMapOf() val ret: MutableMap<ResourceLocation, BlockEntityFactory<out BlockEntity>> = mutableMapOf()

View File

@ -0,0 +1,34 @@
/*
* 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.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
class FurnaceBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
override fun updateNBT(nbt: CompoundTag) {
}
companion object : BlockEntityFactory<FurnaceBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:furnace")
override fun build(connection: PlayConnection): FurnaceBlockEntity {
return FurnaceBlockEntity(connection)
}
}
}

View File

@ -0,0 +1,34 @@
/*
* 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.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
class HopperBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
override fun updateNBT(nbt: CompoundTag) {
}
companion object : BlockEntityFactory<HopperBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:hopper")
override fun build(connection: PlayConnection): HopperBlockEntity {
return HopperBlockEntity(connection)
}
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
class SignBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
var lines: Array<ChatComponent> = Array(RenderConstants.SIGN_LINES) { ChatComponent.valueOf(raw = "") }
override fun updateNBT(nbt: CompoundTag) {
for (i in 0 until RenderConstants.SIGN_LINES) {
val tag = nbt.getStringTag("Text$i") ?: continue
lines[i] = ChatComponent.valueOf(translator = connection.version.localeManager, raw = tag.value)
}
}
companion object : BlockEntityFactory<SignBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:sign")
override fun build(connection: PlayConnection): SignBlockEntity {
return SignBlockEntity(connection)
}
}
}

View File

@ -32,6 +32,10 @@ open class Registry<T : RegistryItem>(
return resourceLocationMap[resourceLocation] ?: parentRegistry?.get(resourceLocation) return resourceLocationMap[resourceLocation] ?: parentRegistry?.get(resourceLocation)
} }
open fun get(resourceLocation: String): T? {
return get(ResourceLocation.getPathResourceLocation(resourceLocation))
}
open fun get(id: Int): T { open fun get(id: Int): T {
return idValueMap[id] ?: parentRegistry?.get(id)!! return idValueMap[id] ?: parentRegistry?.get(id)!!
} }

View File

@ -68,4 +68,7 @@ object RenderConstants {
val PIXEL_UV_PIXEL_ADD = Vec2(0, 0.1f) val PIXEL_UV_PIXEL_ADD = Vec2(0, 0.1f)
const val SIGN_LINES = 4
const val CAMPFIRE_ITEMS = 4
} }

View File

@ -41,6 +41,6 @@ class ClientSettingsC2SPacket(private val locale: String = "en_US", private val
} }
override fun log() { override fun log() {
Log.protocol(String.format("[OUT] Sending settings (locale=%s, renderDistance=%d)", locale, renderDistance)) Log.protocol("[OUT] Sending settings (locale=$locale, renderDistance=$renderDistance)")
} }
} }

View File

@ -137,6 +137,6 @@ class PacketChunkData() : PlayS2CPacket() {
} }
override fun log() { override fun log() {
Log.protocol(String.format("[IN] Chunk packet received (position=%s)", chunkPosition)) Log.protocol("[IN] Chunk packet received (chunkPosition=$chunkPosition)")
} }
} }

View File

@ -63,7 +63,7 @@ public class PlayInByteBuffer extends InByteBuffer {
int x = (int) (raw >> 38); int x = (int) (raw >> 38);
if (this.versionId < V_18W43A) { if (this.versionId < V_18W43A) {
int y = (int) ((raw >> 26) & 0xFFF); int y = (int) ((raw >> 26) & 0xFFF);
int z = (int) (raw & 0x3FFFFFF); int z = (int) (raw << 38 >> 38);
return new Vec3i(x, y, z); return new Vec3i(x, y, z);
} }
int y = (int) (raw << 52 >> 52); int y = (int) (raw << 52 >> 52);