implement snow and snow layer

That makes snowy biomes in pre flattening versions much nicer to see
This commit is contained in:
Moritz Zwerger 2023-10-08 22:32:20 +02:00
parent 29a00ca413
commit d68f2b08d4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 131 additions and 7 deletions

View File

@ -28,6 +28,8 @@ import de.bixilon.minosoft.data.registries.blocks.types.fluid.water.WaterFluidBl
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.SlimeBlock
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.snow.PowderSnowBlock
import de.bixilon.minosoft.data.registries.blocks.types.pvp.CobwebBlock
import de.bixilon.minosoft.data.registries.blocks.types.snow.SnowBlock
import de.bixilon.minosoft.data.registries.blocks.types.snow.SnowLayerBlock
import de.bixilon.minosoft.data.registries.blocks.types.stone.RockBlock
import de.bixilon.minosoft.data.registries.blocks.types.wood.*
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
@ -68,6 +70,8 @@ object BlockFactories : DefaultFactory<BlockFactory<*>>(
Cherry.Leaves,
Azalea.Leaves,
FloweringAzalea.Leaves,
SnowBlock, SnowLayerBlock,
) {
fun build(name: ResourceLocation, registries: Registries, settings: BlockSettings): Block? {

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.dirt.SnowyBlock
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.snow.SnowLayerBlock
@Deprecated("Fallback data")
object BlockProperties {
@ -63,7 +64,7 @@ object BlockProperties {
val MULTIPART_UP = EnumProperty("up", MultipartDirections).register()
val MULTIPART_DOWN = EnumProperty("down", MultipartDirections).register()
val SNOW_LAYERS = IntProperty("layers").register()
val SNOW_LAYERS = SnowLayerBlock.LAYERS.register()
val FENCE_IN_WALL = BooleanProperty("in_wall").register()
val SCAFFOLDING_BOTTOM = BooleanProperty("bottom").register()
val TRIPWIRE_DISARMED = BooleanProperty("disarmed").register()

View File

@ -29,8 +29,8 @@ import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape.Compa
class BlockStateSettings(
val properties: Map<BlockProperty<*>, Any>?,
val luminance: Int,
val collisionShape: AbstractVoxelShape?,
val outlineShape: AbstractVoxelShape?,
var collisionShape: AbstractVoxelShape?,
var outlineShape: AbstractVoxelShape?,
val lightProperties: LightProperties,
@Deprecated("pixlyzer") val solidRenderer: Boolean,
) {

View File

@ -14,12 +14,12 @@
package de.bixilon.minosoft.data.registries.blocks.types.dirt
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks
import de.bixilon.minosoft.data.registries.blocks.properties.list.MapPropertyList
import de.bixilon.minosoft.data.registries.blocks.properties.primitives.BooleanProperty
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.snow.AbstractSnowBlock
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.models.block.state.DirectBlockModel
@ -52,7 +52,7 @@ abstract class SnowyBlock(identifier: ResourceLocation, settings: BlockSettings)
override fun pick(neighbours: Array<BlockState?>): BlockRender? {
val above = neighbours[Directions.O_UP] ?: return normal
if (above.block == MinecraftBlocks.SNOW || above.block == MinecraftBlocks.SNOW_BLOCK) return snowy
if (above.block is AbstractSnowBlock) return snowy
return normal
}

View File

@ -14,8 +14,10 @@
package de.bixilon.minosoft.data.registries.blocks.types.properties.shape.collision.fixed
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.minosoft.data.entities.block.BlockEntity
import de.bixilon.minosoft.data.registries.blocks.shapes.collision.context.CollisionContext
import de.bixilon.minosoft.data.registries.blocks.state.AdvancedBlockState
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.properties.shape.collision.CollidableBlock
import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape
@ -25,7 +27,9 @@ import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape
*/
interface FixedCollidable : CollidableBlock {
fun getCollisionShape(blockState: BlockState): AbstractVoxelShape?
fun getCollisionShape(state: BlockState): AbstractVoxelShape? {
return state.nullCast<AdvancedBlockState>()?.collisionShape
}
override fun getCollisionShape(context: CollisionContext, blockPosition: Vec3i, state: BlockState, blockEntity: BlockEntity?): AbstractVoxelShape? {
return getCollisionShape(state)

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape
interface StatelessCollidable : FixedCollidable {
val collisionShape: AbstractVoxelShape
override fun getCollisionShape(blockState: BlockState): AbstractVoxelShape {
override fun getCollisionShape(state: BlockState): AbstractVoxelShape {
return collisionShape
}
}

View File

@ -0,0 +1,16 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.blocks.types.snow
interface AbstractSnowBlock

View File

@ -0,0 +1,39 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.blocks.types.snow
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.legacy.FlatteningRenamedModel
import de.bixilon.minosoft.data.registries.blocks.types.properties.item.BlockWithItem
import de.bixilon.minosoft.data.registries.blocks.types.properties.shape.special.FullOpaqueBlock
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.shovel.ShovelRequirement
import de.bixilon.minosoft.data.registries.registries.Registries
class SnowBlock(identifier: ResourceLocation = Companion.identifier, settings: BlockSettings) : Block(identifier, settings), FullOpaqueBlock, FlatteningRenamedModel, ShovelRequirement, BlockWithItem<Item>, AbstractSnowBlock {
override val item: Item = this::item.inject(identifier)
override val hardness get() = 0.2f
override val legacyModelName get() = minecraft("snow")
companion object : BlockFactory<SnowBlock> {
override val identifier = minecraft("snow_block")
override fun build(registries: Registries, settings: BlockSettings) = SnowBlock(settings = settings)
}
}

View File

@ -0,0 +1,60 @@
/*
* Minosoft
* Copyright (C) 2020-2023 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.blocks.types.snow
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.blocks.factory.BlockFactory
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.primitives.IntProperty
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.AdvancedBlockState
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.builder.BlockStateBuilder
import de.bixilon.minosoft.data.registries.blocks.state.builder.BlockStateSettings
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.legacy.FlatteningRenamedModel
import de.bixilon.minosoft.data.registries.blocks.types.properties.item.BlockWithItem
import de.bixilon.minosoft.data.registries.blocks.types.properties.shape.collision.fixed.FixedCollidable
import de.bixilon.minosoft.data.registries.blocks.types.properties.shape.outline.OutlinedBlock
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.shovel.ShovelRequirement
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.shapes.voxel.VoxelShape
class SnowLayerBlock(identifier: ResourceLocation = Companion.identifier, settings: BlockSettings) : Block(identifier, settings), FixedCollidable, OutlinedBlock, FlatteningRenamedModel, ShovelRequirement, BlockWithItem<Item>, AbstractSnowBlock, BlockStateBuilder {
override val item: Item = this::item.inject(identifier)
override val hardness get() = 0.1f
override val legacyModelName get() = minecraft("snow_layer")
override fun buildState(settings: BlockStateSettings): BlockState {
val layer = settings.properties?.get(BlockProperties.SNOW_LAYERS)?.toInt() ?: return BlockState(this, settings)
settings.collisionShape = VoxelShape(0.0, 0.0, 0.0, 1.0, (layer - 1) * LAYER_HEIGHT, 1.0)
settings.outlineShape = VoxelShape(0.0, 0.0, 0.0, 1.0, layer * LAYER_HEIGHT, 1.0)
return AdvancedBlockState(this, settings)
}
companion object : BlockFactory<SnowLayerBlock> {
override val identifier = minecraft("snow")
private const val LAYER_COUNT = 8
private const val LAYER_HEIGHT = 1.0 / LAYER_COUNT
val LAYERS = IntProperty("layers", 1..LAYER_COUNT)
override fun build(registries: Registries, settings: BlockSettings) = SnowLayerBlock(settings = settings)
}
}