2021-02-28 12:33:01 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks.base;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.item.BlockItemUseContext;
|
|
|
|
import net.minecraft.state.DirectionProperty;
|
|
|
|
import net.minecraft.state.StateContainer;
|
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
import net.minecraft.block.AbstractBlock.Properties;
|
|
|
|
|
2021-02-28 12:33:01 +01:00
|
|
|
/**
|
|
|
|
* Wrapper for Fully Direction block states extending from our base blocks. It's not super nice but it'll do.
|
|
|
|
*/
|
|
|
|
public abstract class FullyDirectionalBlock extends BlockBase {
|
2021-02-28 15:47:54 +01:00
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
|
|
|
|
2021-02-28 12:33:01 +01:00
|
|
|
public FullyDirectionalBlock(Properties properties) {
|
|
|
|
super(properties);
|
2021-08-22 17:09:06 +02:00
|
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
2021-02-28 15:47:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection().getOpposite());
|
2021-02-28 15:47:54 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
|
2021-02-28 15:47:54 +01:00
|
|
|
builder.add(FACING);
|
2021-02-28 12:33:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract static class Container extends BlockContainerBase {
|
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
|
|
|
|
|
|
|
public Container(Properties properties) {
|
|
|
|
super(properties);
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
2021-02-28 12:33:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
2021-08-22 17:09:06 +02:00
|
|
|
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection().getOpposite());
|
2021-02-28 12:33:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
|
2021-02-28 12:33:01 +01:00
|
|
|
builder.add(FACING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|