Skip to content

Commit

Permalink
[~] Column changes..
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Feb 10, 2024
1 parent 4018af3 commit d7d4dac
Show file tree
Hide file tree
Showing 36 changed files with 1,938 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.Foundation;
import com.starfish_studios.foundation.block.properties.ColumnType;
import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -29,32 +30,70 @@ public class ColumnBlock extends Block implements SimpleWaterloggedBlock {
public static final BooleanProperty LAYER_FOUR = FoundationBlockStateProperties.LAYER_FOUR;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final DirectionProperty FACING = DirectionalBlock.FACING;
public static final EnumProperty<ColumnType> TYPE = FoundationBlockStateProperties.COLUMN_TYPE;

public ColumnBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(WATERLOGGED, false)
.setValue(FACING, Direction.UP)
.setValue(TYPE, ColumnType.NONE)
.setValue(LAYER_ONE, true)
.setValue(LAYER_TWO, false)
.setValue(LAYER_THREE, false)
.setValue(LAYER_FOUR, true));
}

@Override
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
if (level.isClientSide) return;

Direction.Axis axis = state.getValue(FACING).getAxis();
ColumnType type = getType(state, getRelativeTop(level, pos, axis), getRelativeBottom(level, pos, axis));
if (state.getValue(TYPE) == type) return;

state = state.setValue(TYPE, type);
level.setBlock(pos, state, 3);
}

public BlockState getRelativeTop(Level level, BlockPos pos, Direction.Axis axis) {
return level.getBlockState(pos.relative(Direction.fromAxisAndDirection(axis, Direction.AxisDirection.POSITIVE)));
}

public BlockState getRelativeBottom(Level level, BlockPos pos, Direction.Axis axis) {
return level.getBlockState(pos.relative(Direction.fromAxisAndDirection(axis, Direction.AxisDirection.NEGATIVE)));
}

public ColumnType getType(BlockState state, BlockState above, BlockState below) {

boolean shape_above_same = above.is(state.getBlock()) && state.getValue(FACING) == above.getValue(FACING);
boolean shape_below_same = below.is(state.getBlock()) && state.getValue(FACING) == below.getValue(FACING);

if (shape_above_same && !shape_below_same) return ColumnType.BOTTOM;
else if (!shape_above_same && shape_below_same) return ColumnType.TOP;
else if (shape_above_same) return ColumnType.MIDDLE;

return ColumnType.NONE;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction[] var2 = context.getNearestLookingDirections();

for (Direction direction : var2) {
Level level = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockState blockState;

if (direction.getAxis() == Direction.Axis.Y) {
blockState = this.defaultBlockState().setValue(FACING, context.getNearestLookingVerticalDirection().getOpposite());
} else {
blockState = this.defaultBlockState().setValue(FACING, direction.getOpposite());
}
blockState = blockState.setValue(TYPE, getType(blockState, getRelativeTop(level, pos, direction.getAxis()), getRelativeBottom(level, pos, direction.getAxis())));
return blockState;
}
return null;
return this.defaultBlockState().setValue(TYPE, ColumnType.NONE);
}

public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
Expand Down Expand Up @@ -129,7 +168,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LAYER_ONE, LAYER_TWO, LAYER_THREE, LAYER_FOUR, WATERLOGGED, FACING);
builder.add(LAYER_ONE, LAYER_TWO, LAYER_THREE, LAYER_FOUR, WATERLOGGED, FACING, TYPE);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class FoundationBlocks {
public static final Block OAK_WALL = register("oak_wall", new WallBlock(FabricBlockSettings.copy((Blocks.OAK_PLANKS))));


public static final Block STONE_COLUMN = register("stone_column", new ColumnBlock(FabricBlockSettings.copy((Blocks.STONE_BRICKS)).noOcclusion()));


// Stone, Sandstone, Red Sandstone, Quartz, Blackstone, Deepslate, Nether Brick
public static final Block STONE_FENCE = register("stone_fence", new StoneFenceBlock(FabricBlockSettings.copy((Blocks.STONE_BRICKS)).noOcclusion()));
public static final Block BLACKSTONE_FENCE = register("blackstone_fence", new StoneFenceBlock(FabricBlockSettings.copy((Blocks.BLACKSTONE)).noOcclusion()));
Expand Down Expand Up @@ -217,7 +220,6 @@ public class FoundationBlocks {
public static final Block POLISHED_STONE = register("polished_stone", new Block(FabricBlockSettings.copy((Blocks.SMOOTH_STONE))));
public static final Block POLISHED_STONE_STAIRS = register("polished_stone_stairs", new StairBlock((Blocks.SMOOTH_STONE.defaultBlockState()), BlockBehaviour.Properties.copy(Blocks.SMOOTH_STONE)));
public static final Block POLISHED_STONE_SLAB = register("polished_stone_slab", new SlabBlock(BlockBehaviour.Properties.copy(Blocks.SMOOTH_STONE)));
public static final Block POLISHED_STONE_COLUMN = register("polished_stone_column", new ColumnBlock(FabricBlockSettings.copy((Blocks.STONE_BRICKS)).noOcclusion()));
public static final Block STONE_TILES = register("stone_tiles", new Block(FabricBlockSettings.copy((Blocks.STONE_BRICKS))));
public static final Block STONE_TILE_STAIRS = register("stone_tile_stairs", new StairBlock((Blocks.STONE_BRICKS.defaultBlockState()), BlockBehaviour.Properties.copy(Blocks.STONE_BRICKS)));
public static final Block STONE_TILE_SLAB = register("stone_tile_slab", new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE_BRICKS)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class FoundationCreativeModeTab {
output.accept(POLISHED_STONE);
output.accept(POLISHED_STONE_STAIRS);
output.accept(POLISHED_STONE_SLAB);
output.accept(POLISHED_STONE_COLUMN);
output.accept(STONE_COLUMN);

output.accept(STONE_TILES);
output.accept(STONE_TILE_STAIRS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class FoundationItems {
public static final Item POLISHED_STONE = register("polished_stone", new BlockItem(FoundationBlocks.POLISHED_STONE, new FabricItemSettings()));
public static final Item POLISHED_STONE_STAIRS = register("polished_stone_stairs", new BlockItem(FoundationBlocks.POLISHED_STONE_STAIRS, new FabricItemSettings()));
public static final Item POLISHED_STONE_SLAB = register("polished_stone_slab", new BlockItem(FoundationBlocks.POLISHED_STONE_SLAB, new FabricItemSettings()));
public static final Item POLISHED_STONE_COLUMN = register("polished_stone_column", new DescriptionBlockItem(FoundationBlocks.POLISHED_STONE_COLUMN, new FabricItemSettings()));
public static final Item STONE_COLUMN = register("stone_column", new DescriptionBlockItem(FoundationBlocks.STONE_COLUMN, new FabricItemSettings()));

public static final Item STONE_TILES = register("stone_tiles", new BlockItem(FoundationBlocks.STONE_TILES, new FabricItemSettings()));
public static final Item STONE_TILE_STAIRS = register("stone_tile_stairs", new BlockItem(FoundationBlocks.STONE_TILE_STAIRS, new FabricItemSettings()));
Expand Down
Loading

0 comments on commit d7d4dac

Please sign in to comment.