-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[~+] Tweaks, organization, Layer blocks
- Loading branch information
1 parent
a8f986c
commit af5ac18
Showing
115 changed files
with
2,461 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 106 additions & 43 deletions
149
src/main/java/com/starfish_studios/foundation/block/ColumnBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,135 @@ | ||
package com.starfish_studios.foundation.block; | ||
|
||
import com.starfish_studios.foundation.block.properties.ColumnType; | ||
import com.starfish_studios.foundation.Foundation; | ||
import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.tags.ItemTags; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.DirectionalBlock; | ||
import net.minecraft.world.level.block.SimpleWaterloggedBlock; | ||
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.EnumProperty; | ||
import org.jetbrains.annotations.Nullable; | ||
import net.minecraft.world.level.block.state.properties.*; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.shapes.CollisionContext; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
|
||
public class ColumnBlock extends Block { | ||
public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS; | ||
public static final EnumProperty<ColumnType> TYPE = FoundationBlockStateProperties.COLUMN_TYPE; | ||
public class ColumnBlock extends Block implements SimpleWaterloggedBlock { | ||
public static final BooleanProperty LAYER_ONE = FoundationBlockStateProperties.LAYER_ONE; | ||
public static final BooleanProperty LAYER_TWO = FoundationBlockStateProperties.LAYER_TWO; | ||
public static final BooleanProperty LAYER_THREE = FoundationBlockStateProperties.LAYER_THREE; | ||
public static final BooleanProperty LAYER_FOUR = FoundationBlockStateProperties.LAYER_FOUR; | ||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; | ||
public static final DirectionProperty FACING = DirectionalBlock.FACING; | ||
|
||
public ColumnBlock(Properties properties) { | ||
super(properties); | ||
this.registerDefaultState(this.stateDefinition.any() | ||
.setValue(TYPE, ColumnType.NONE)); | ||
.setValue(WATERLOGGED, false) | ||
.setValue(FACING, Direction.UP) | ||
.setValue(LAYER_ONE, true) | ||
.setValue(LAYER_TWO, false) | ||
.setValue(LAYER_THREE, false) | ||
.setValue(LAYER_FOUR, true)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext context) { | ||
Level level = context.getLevel(); | ||
BlockPos pos = context.getClickedPos(); | ||
Direction.Axis axis = context.getClickedFace().getAxis(); | ||
Direction[] var2 = context.getNearestLookingDirections(); | ||
|
||
BlockState state = this.defaultBlockState().setValue(AXIS, axis); | ||
state = state.setValue(TYPE, getType(state, getRelativeTop(level, pos, axis), getRelativeBottom(level, pos, axis))); | ||
return state; | ||
for (Direction direction : var2) { | ||
BlockState blockState; | ||
if (direction.getAxis() == Direction.Axis.Y) { | ||
blockState = this.defaultBlockState().setValue(FACING, context.getNearestLookingVerticalDirection().getOpposite()); | ||
} else { | ||
blockState = this.defaultBlockState().setValue(FACING, direction.getOpposite()); | ||
} | ||
return blockState; | ||
} | ||
return null; | ||
} | ||
|
||
@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(AXIS); | ||
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 InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { | ||
if (player.getItemInHand(interactionHand).is(ItemTags.PICKAXES)) { | ||
if (blockState.getValue(FACING) == Direction.UP) { | ||
if (blockHitResult.getLocation().y - blockPos.getY() < 0.25) { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} else if (blockHitResult.getLocation().y - blockPos.getY() < 0.5) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else if (blockHitResult.getLocation().y - blockPos.getY() < 0.75) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} | ||
} else if (blockState.getValue(FACING) == Direction.DOWN) { | ||
if (blockHitResult.getLocation().y - blockPos.getY() < 0.25) { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} else if (blockHitResult.getLocation().y - blockPos.getY() < 0.5) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else if (blockHitResult.getLocation().y - blockPos.getY() < 0.75) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} | ||
} else if (blockState.getValue(FACING) == Direction.NORTH) { | ||
if (blockHitResult.getLocation().z - blockPos.getZ() < 0.25) { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} else if (blockHitResult.getLocation().z - blockPos.getZ() < 0.5) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else if (blockHitResult.getLocation().z - blockPos.getZ() < 0.75) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} | ||
} else if (blockState.getValue(FACING) == Direction.EAST) { | ||
if (blockHitResult.getLocation().x - blockPos.getX() < 0.25) { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} else if (blockHitResult.getLocation().x - blockPos.getX() < 0.5) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else if (blockHitResult.getLocation().x - blockPos.getX() < 0.75) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} | ||
} else if (blockState.getValue(FACING) == Direction.SOUTH) { | ||
if (blockHitResult.getLocation().z - blockPos.getZ() < 0.25) { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} else if (blockHitResult.getLocation().z - blockPos.getZ() < 0.5) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else if (blockHitResult.getLocation().z - blockPos.getZ() < 0.75) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} | ||
} else if (blockState.getValue(FACING) == Direction.WEST) { | ||
if (blockHitResult.getLocation().x - blockPos.getX() < 0.25) { | ||
blockState = blockState.cycle(LAYER_ONE); | ||
} else if (blockHitResult.getLocation().x - blockPos.getX() < 0.5) { | ||
blockState = blockState.cycle(LAYER_TWO); | ||
} else if (blockHitResult.getLocation().x - blockPos.getX() < 0.75) { | ||
blockState = blockState.cycle(LAYER_THREE); | ||
} else { | ||
blockState = blockState.cycle(LAYER_FOUR); | ||
} | ||
} | ||
} else return InteractionResult.PASS; | ||
|
||
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(AXIS) == above.getValue(AXIS); | ||
boolean shape_below_same = below.is(state.getBlock()) && state.getValue(AXIS) == below.getValue(AXIS); | ||
|
||
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; | ||
level.setBlock(blockPos, blockState, 3); | ||
level.playSound(player, blockPos, blockState.getSoundType().getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F); | ||
return InteractionResult.SUCCESS; | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
builder.add(TYPE, AXIS); | ||
builder.add(LAYER_ONE, LAYER_TWO, LAYER_THREE, LAYER_FOUR, WATERLOGGED, FACING); | ||
} | ||
|
||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/starfish_studios/foundation/block/FacingConnectingBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.starfish_studios.foundation.block; | ||
|
||
import com.starfish_studios.foundation.block.properties.ColumnType; | ||
import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
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.EnumProperty; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class FacingConnectingBlock extends Block { | ||
public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS; | ||
public static final EnumProperty<ColumnType> TYPE = FoundationBlockStateProperties.COLUMN_TYPE; | ||
|
||
public FacingConnectingBlock(Properties properties) { | ||
super(properties); | ||
this.registerDefaultState(this.stateDefinition.any() | ||
.setValue(TYPE, ColumnType.NONE)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext context) { | ||
Level level = context.getLevel(); | ||
BlockPos pos = context.getClickedPos(); | ||
Direction.Axis axis = context.getClickedFace().getAxis(); | ||
|
||
BlockState state = this.defaultBlockState().setValue(AXIS, axis); | ||
state = state.setValue(TYPE, getType(state, getRelativeTop(level, pos, axis), getRelativeBottom(level, pos, axis))); | ||
return state; | ||
} | ||
|
||
@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(AXIS); | ||
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(AXIS) == above.getValue(AXIS); | ||
boolean shape_below_same = below.is(state.getBlock()) && state.getValue(AXIS) == below.getValue(AXIS); | ||
|
||
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 | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { | ||
builder.add(TYPE, AXIS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.