Skip to content

Commit

Permalink
Edits to block models and raft blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Jan 18, 2025
1 parent b4f4e38 commit d3425c5
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 142 deletions.
62 changes: 35 additions & 27 deletions src/main/kotlin/dev/hybridlabs/aquatic/block/RaftBlock.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package dev.hybridlabs.aquatic.block

import net.minecraft.block.*
import net.minecraft.entity.ai.pathing.NavigationType
import net.minecraft.fluid.FluidState
import net.minecraft.fluid.Fluids
import net.minecraft.item.ItemPlacementContext
import net.minecraft.state.StateManager
import net.minecraft.state.property.DirectionProperty
import net.minecraft.state.property.Properties
import net.minecraft.util.BlockRotation
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.util.shape.VoxelShape
Expand All @@ -16,16 +15,20 @@ import net.minecraft.world.WorldAccess
import net.minecraft.world.WorldView

@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
class RaftBlock(settings: Settings) : Block(settings) {
class RaftBlock(settings: Settings) : Block(settings), Waterloggable {
init {
defaultState = defaultState.with(Properties.WATERLOGGED, true)
defaultState = defaultState.with(Properties.WATERLOGGED, false)
}

override fun getPlacementState(ctx: ItemPlacementContext): BlockState? {
val waterlogged = ctx.world.getFluidState(ctx.blockPos).fluid == Fluids.WATER
return defaultState
.with(Properties.WATERLOGGED, waterlogged)
.with(FACING, ctx.horizontalPlayerFacing.rotateYClockwise())
override fun getPlacementState(context: ItemPlacementContext): BlockState? {
val world = context.world
val pos = context.blockPos
val fluidState = world.getFluidState(pos)
return super.getPlacementState(context)?.with(Properties.WATERLOGGED, fluidState.fluid == Fluids.WATER)
}

override fun canPathfindThrough(state: BlockState, world: BlockView, pos: BlockPos, type: NavigationType): Boolean {
return false
}

override fun getFluidState(state: BlockState): FluidState {
Expand All @@ -40,19 +43,21 @@ class RaftBlock(settings: Settings) : Block(settings) {
pos: BlockPos,
neighborPos: BlockPos
): BlockState {
return if (canPlaceAt(state, world, pos)) super.getStateForNeighborUpdate(
state,
direction,
neighborState,
world,
pos,
neighborPos
)
else Blocks.AIR.defaultState
if (state.get(Properties.WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world))
}

if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.defaultState
}

return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos)
}

override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
builder.add(Properties.WATERLOGGED, FACING)
super.appendProperties(
builder.add(Properties.WATERLOGGED)
)
}

override fun getOutlineShape(
Expand All @@ -65,18 +70,21 @@ class RaftBlock(settings: Settings) : Block(settings) {
}

override fun canPlaceAt(state: BlockState, world: WorldView, pos: BlockPos): Boolean {
val placedOn = world.getBlockState(pos)
val isAirAbove = world.getBlockState(pos.up()).isAir && world.getBlockState(pos.up(2)).isAir
val fluidStateAbove = world.getFluidState(pos.up())
if (fluidStateAbove.fluid != Fluids.EMPTY) {
return false
}

return placedOn.fluidState.isOf(Fluids.WATER) && isAirAbove
}
val stateBelow = world.getBlockState(pos.down())
if (stateBelow.block == this) {
return false
}

override fun rotate(state: BlockState, rotation: BlockRotation): BlockState {
return state.with(FACING, rotation.rotate(state.get(FACING) as Direction)) as BlockState
val fluidState = world.getFluidState(pos)
return fluidState.fluid == Fluids.WATER || sideCoversSmallSquare(world, pos.down(), Direction.UP)
}

companion object {
val FACING: DirectionProperty = HorizontalFacingBlock.FACING
private val SHAPE: VoxelShape = createCuboidShape(0.0, 12.0, 0.0, 16.0, 16.0, 16.0)
private val SHAPE: VoxelShape = createCuboidShape(1.0, 12.0, 1.0, 15.0, 16.0, 15.0)
}
}
15 changes: 2 additions & 13 deletions src/main/resources/assets/hybrid-aquatic/blockstates/raft.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{
"variants": {
"facing=east": {
"model": "hybrid-aquatic:models/block/raft.json",
"y": 90
},
"facing=west": {
"model": "hybrid-aquatic:models/block/raft.json",
"y": 90
},
"facing=north": {
"model": "hybrid-aquatic:models/block/raft.json"
},
"facing=south": {
"model": "hybrid-aquatic:models/block/raft.json"
"": {
"model": "hybrid-aquatic:block/raft"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"credit": "Made with Blockbench",
"texture_size": [32, 32],
"textures": {
"1": "hybrid-aquatic:block/jungle_lily_pad"
"1": "hybrid-aquatic:block/jungle_lily_pad",
"particle": "hybrid-aquatic:block/jungle_lily_pad"
},
"elements": [
{
Expand Down Expand Up @@ -70,5 +71,40 @@
"down": {"uv": [7.5, 0, 0, 0], "texture": "#1"}
}
}
]
],
"display": {
"thirdperson_righthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, -2],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, 45, 0],
"translation": [0, 2.5, -2],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"translation": [0, -2, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 225, 0],
"translation": [0, -2, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, -1, 0],
"scale": [0.25, 0.25, 0.25]
},
"gui": {
"rotation": [30, 225, 0],
"translation": [0, -3.5, 0],
"scale": [0.625, 0.625, 0.625]
},
"fixed": {
"rotation": [-90, 0, 0],
"translation": [0, 0, 6.5]
}
}
}
Loading

0 comments on commit d3425c5

Please sign in to comment.