70 lines
2.6 KiB
Java
70 lines
2.6 KiB
Java
package com.cursedcauldron.wildbackport.common.blocks;
|
|
|
|
import com.cursedcauldron.wildbackport.common.registry.WBBlocks;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public class MangroveRootsBlock extends Block implements SimpleWaterloggedBlock {
|
|
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
|
|
public MangroveRootsBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false)
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public boolean
|
|
skipRendering(BlockState state, BlockState stateFrom, Direction direction) {
|
|
return stateFrom.is(WBBlocks.MANGROVE_ROOTS.get())
|
|
&& direction.getAxis() == Direction.Axis.Y;
|
|
}
|
|
|
|
@Override
|
|
@Nullable
|
|
@SuppressWarnings("ConstantConditions")
|
|
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
|
return super.getStateForPlacement(ctx).setValue(
|
|
WATERLOGGED,
|
|
ctx.getLevel().getFluidState(ctx.getClickedPos()).getType() == Fluids.WATER
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(
|
|
BlockState state,
|
|
Direction direction,
|
|
BlockState newState,
|
|
LevelAccessor level,
|
|
BlockPos pos,
|
|
BlockPos newPos
|
|
) {
|
|
if (state.getValue(WATERLOGGED))
|
|
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
|
return super.updateShape(state, direction, newState, level, pos, newPos);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(BlockState state) {
|
|
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false)
|
|
: super.getFluidState(state);
|
|
}
|
|
|
|
@Override
|
|
protected void
|
|
createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(WATERLOGGED);
|
|
}
|
|
} |