fix some tests, fix chests

This commit is contained in:
Moritz Zwerger 2023-10-29 20:01:58 +01:00
parent cc31e405d1
commit 18ef672248
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 22 additions and 16 deletions

View File

@ -56,8 +56,10 @@ class EntityRendererManagerTest {
val entity = renderer.createPig()
assertEquals(renderer.size, 0)
renderer.renderer.connection.world.entities.add(1, null, entity)
renderer.renderer.queue.work()
assertEquals(renderer.size, 1)
renderer.renderer.connection.world.entities.remove(1)
renderer.renderer.queue.work()
assertEquals(renderer.size, 0)
}
@ -70,13 +72,17 @@ class EntityRendererManagerTest {
assertEquals(renderer.size, 0)
renderer.renderer.connection.world.entities.add(1, null, e1)
renderer.renderer.connection.world.entities.add(2, null, e2)
renderer.renderer.queue.work()
assertEquals(renderer.size, 2)
renderer.renderer.connection.world.entities.add(3, null, e3)
renderer.renderer.queue.work()
assertEquals(renderer.size, 3)
renderer.renderer.connection.world.entities.remove(1)
renderer.renderer.queue.work()
assertEquals(renderer.size, 2)
renderer.renderer.connection.world.entities.remove(2)
renderer.renderer.connection.world.entities.remove(3)
renderer.renderer.queue.work()
assertEquals(renderer.size, 0)
}
}

View File

@ -40,5 +40,5 @@ abstract class BlockEntity(
return this.renderer
}
protected open fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<out BlockEntity>? = null
protected open fun createRenderer(context: RenderContext, state: BlockState, position: Vec3i, light: Int): BlockEntityRenderer<out BlockEntity>? = null
}

View File

@ -32,7 +32,7 @@ abstract class MeshedBlockEntity(connection: PlayConnection) : BlockEntity(conne
return renderer
}
override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<*> {
override fun createRenderer(context: RenderContext, state: BlockState, position: Vec3i, light: Int): BlockEntityRenderer<*> {
throw IllegalAccessException()
}

View File

@ -28,15 +28,15 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
open class ChestBlockEntity(connection: PlayConnection) : StorageBlockEntity(connection) {
override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<*>? {
val type: ChestTypes = blockState[BlockProperties.CHEST_TYPE]
override fun createRenderer(context: RenderContext, state: BlockState, position: Vec3i, light: Int): BlockEntityRenderer<*>? {
val type: ChestTypes = state[BlockProperties.CHEST_TYPE]
if (type == ChestTypes.SINGLE) {
return SingleChestRenderer(this, context, blockState, blockPosition, context.models.skeletal[getSingleModel()] ?: return null, light)
return SingleChestRenderer(this, context, state, position, context.models.skeletal[getSingleModel()] ?: return null, light)
}
if (type == ChestTypes.LEFT) {
// only left chest will be rendered (the model is the double chest), reduces drawing overhead
return DoubleChestRenderer(this, context, blockState, blockPosition, context.models.skeletal[getDoubleModel()] ?: return null, light)
return DoubleChestRenderer(this, context, state, position, context.models.skeletal[getDoubleModel()] ?: return null, light)
}
return null

View File

@ -26,9 +26,9 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
class EnderChestBlockEntity(connection: PlayConnection) : StorageBlockEntity(connection) {
override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<out BlockEntity>? {
override fun createRenderer(context: RenderContext, state: BlockState, position: Vec3i, light: Int): BlockEntityRenderer<out BlockEntity>? {
val model = context.models.skeletal[SingleChestRenderer.EnderChest.NAME] ?: return null
return SingleChestRenderer(this, context, blockState, blockPosition, model, light)
return SingleChestRenderer(this, context, state, position, model, light)
}
companion object : BlockEntityFactory<EnderChestBlockEntity> {

View File

@ -27,10 +27,10 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
class ShulkerBoxBlockEntity(connection: PlayConnection) : StorageBlockEntity(connection) {
override fun createRenderer(context: RenderContext, blockState: BlockState, blockPosition: Vec3i, light: Int): BlockEntityRenderer<*>? {
override fun createRenderer(context: RenderContext, state: BlockState, position: Vec3i, light: Int): BlockEntityRenderer<*>? {
// TODO: remove that junk code
val model: BakedSkeletalModel?
val prefix = blockState.block.identifier.path.removeSuffix("shulker_box")
val prefix = state.block.identifier.path.removeSuffix("shulker_box")
if (prefix.endsWith("_")) {
// colored
val color = DyeColors[prefix.removeSuffix("_")]
@ -40,7 +40,7 @@ class ShulkerBoxBlockEntity(connection: PlayConnection) : StorageBlockEntity(con
model = context.models.skeletal[ShulkerBoxRenderer.NAME]
}
if (model == null) return null
return ShulkerBoxRenderer(this, context, blockState, blockPosition, model, light)
return ShulkerBoxRenderer(this, context, state, position, model, light)
}
companion object : BlockEntityFactory<ShulkerBoxBlockEntity> {

View File

@ -32,10 +32,7 @@ interface DoubleChestBlock<T : StorageBlockEntity> : ChestBlock<T> {
if (type == ChestTypes.SINGLE) return ChestBlock.SINGLE
var facing = state[BlockProperties.FACING] // TODO: HORIZONTAL_FACING
if (type == ChestTypes.LEFT) {
facing = facing.rotateY(1)
}
// TODO: verify
facing = facing.rotateY(if (type == ChestTypes.LEFT) 1 else -1)
// TODO: legacy: check if neighbour block is chest
return SHAPES[facing.ordinal - Directions.SIDE_OFFSET]

View File

@ -18,13 +18,16 @@ import de.bixilon.minosoft.data.registries.blocks.entites.BlockEntityType
import de.bixilon.minosoft.data.registries.blocks.factory.BlockFactory
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.properties.item.BlockWithItem
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.item.items.Item
import de.bixilon.minosoft.data.registries.item.items.tool.pickaxe.PickaxeRequirement
import de.bixilon.minosoft.data.registries.registries.Registries
open class EnderChestBlock(identifier: ResourceLocation = this.identifier, settings: BlockSettings) : Block(identifier, settings), ChestBlock<EnderChestBlockEntity>, PickaxeRequirement {
open class EnderChestBlock(identifier: ResourceLocation = this.identifier, settings: BlockSettings) : Block(identifier, settings), ChestBlock<EnderChestBlockEntity>, PickaxeRequirement, BlockWithItem<Item> {
override val blockEntity: BlockEntityType<EnderChestBlockEntity> = this::blockEntity.inject(this)
override val item: Item = this::item.inject(identifier)
override val hardness: Float get() = 22.5f
companion object : BlockFactory<EnderChestBlock> {