-
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.
[~+] Beams, Supports, WIP Wooden Walls, etc.
- Loading branch information
1 parent
70c5207
commit 85365a7
Showing
183 changed files
with
10,269 additions
and
108 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
94 changes: 94 additions & 0 deletions
94
src/main/java/com/starfish_studios/foundation/block/SupportBlock.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,94 @@ | ||
package com.starfish_studios.foundation.block; | ||
|
||
import com.starfish_studios.foundation.registry.FoundationTags; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
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.Level; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.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.*; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
|
||
public class SupportBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock { | ||
|
||
public static final EnumProperty<Half> HALF = BlockStateProperties.HALF; | ||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | ||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; | ||
public static final BooleanProperty SUPPORT = BooleanProperty.create("support"); | ||
public SupportBlock(Properties properties) { | ||
super(properties); | ||
registerDefaultState(stateDefinition.any() | ||
.setValue(FACING, Direction.NORTH) | ||
.setValue(HALF, Half.BOTTOM) | ||
.setValue(WATERLOGGED, false) | ||
.setValue(SUPPORT, true)); | ||
} | ||
@Override | ||
public boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { | ||
if (player.getItemInHand(interactionHand).is(FoundationTags.FoundationItemTags.HAMMERS)) { | ||
if (blockState.getValue(SUPPORT)) { | ||
level.setBlock(blockPos, blockState.setValue(SUPPORT, false), 3); | ||
} else { | ||
level.setBlock(blockPos, blockState.setValue(SUPPORT, true), 3); | ||
} | ||
level.playSound(player, blockPos, Blocks.SCAFFOLDING.getSoundType(level.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F); | ||
return InteractionResult.SUCCESS; | ||
} | ||
return InteractionResult.PASS; | ||
} | ||
|
||
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) { | ||
BlockState blockState = this.defaultBlockState(); | ||
FluidState fluidState = blockPlaceContext.getLevel().getFluidState(blockPlaceContext.getClickedPos()); | ||
Direction direction = blockPlaceContext.getClickedFace(); | ||
if (!blockPlaceContext.replacingClickedOnBlock() && direction.getAxis().isHorizontal()) { | ||
blockState = blockState.setValue(FACING, blockPlaceContext.getHorizontalDirection().getOpposite()).setValue(HALF, blockPlaceContext.getClickLocation().y - (double)blockPlaceContext.getClickedPos().getY() > 0.5 ? Half.TOP : Half.BOTTOM); | ||
} else { | ||
blockState = blockState.setValue(FACING, blockPlaceContext.getHorizontalDirection().getOpposite()).setValue(HALF, direction == Direction.UP ? Half.BOTTOM : Half.TOP); | ||
} | ||
|
||
return blockState.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); | ||
} | ||
|
||
@Override | ||
public BlockState rotate(BlockState state, Rotation rotation) { | ||
return state.setValue(FACING, rotation.rotate(state.getValue(FACING))); | ||
} | ||
|
||
@Override | ||
public BlockState mirror(BlockState state, Mirror mirror) { | ||
return state.rotate(mirror.getRotation(state.getValue(FACING))); | ||
} | ||
|
||
@Override | ||
public FluidState getFluidState(BlockState blockState) { | ||
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState); | ||
} | ||
|
||
@Override | ||
public BlockState updateShape(BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) { | ||
if (blockState.getValue(WATERLOGGED)) { | ||
levelAccessor.scheduleTick(blockPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor)); | ||
} | ||
|
||
return super.updateShape(blockState, direction, blockState2, levelAccessor, blockPos, blockPos2); | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateDefinition) { | ||
stateDefinition.add(FACING, HALF, WATERLOGGED, SUPPORT); | ||
} | ||
} |
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
Oops, something went wrong.