Skip to content

Commit

Permalink
[~+] Tons of recipes + Beam Stairs/Slabs, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Feb 8, 2024
1 parent 85365a7 commit 7b7f200
Show file tree
Hide file tree
Showing 259 changed files with 13,314 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.starfish_studios.foundation.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
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.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.*;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class FacingSlabBlock extends Block implements SimpleWaterloggedBlock {
public static final EnumProperty<SlabType> TYPE = BlockStateProperties.SLAB_TYPE;
public static final DirectionProperty FACING = BlockStateProperties.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;


public static final VoxelShape SLAB_BOTTOM_UP = Block.box(0, 0, 0, 16, 8, 16);
public static final VoxelShape SLAB_BOTTOM_DOWN = Block.box(0, 8, 0, 16, 16, 16);
public static final VoxelShape SLAB_BOTTOM_NORTH = Block.box(0, 0, 8, 16, 16, 16);
public static final VoxelShape SLAB_BOTTOM_EAST = Block.box(0, 0, 0, 8, 16, 16);
public static final VoxelShape SLAB_BOTTOM_SOUTH = Block.box(0, 0, 0, 16, 16, 8);
public static final VoxelShape SLAB_BOTTOM_WEST = Block.box(8, 0, 0, 16, 16, 16);

public static final VoxelShape SLAB_TOP_UP = Block.box(0, 8, 0, 16, 16, 16);
public static final VoxelShape SLAB_TOP_DOWN = Block.box(0, 0, 0, 16, 8, 16);
public static final VoxelShape SLAB_TOP_NORTH = Block.box(0, 0, 8, 16, 16, 16);
public static final VoxelShape SLAB_TOP_EAST = Block.box(8, 0, 0, 16, 16, 16);
public static final VoxelShape SLAB_TOP_SOUTH = Block.box(0, 0, 0, 16, 16, 8);
public static final VoxelShape SLAB_TOP_WEST = Block.box(0, 0, 0, 8, 16, 16);

public static final VoxelShape SLAB_DOUBLE = Block.box(0, 0, 0, 16, 16, 16);


public FacingSlabBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(TYPE, SlabType.BOTTOM)
.setValue(FACING, Direction.UP)
.setValue(WATERLOGGED, false));
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
return switch (state.getValue(TYPE)) {
case BOTTOM -> switch (state.getValue(FACING)) {
case NORTH -> SLAB_BOTTOM_NORTH;
case SOUTH -> SLAB_BOTTOM_SOUTH;
case EAST -> SLAB_BOTTOM_EAST;
case WEST -> SLAB_BOTTOM_WEST;
case UP -> SLAB_BOTTOM_UP;
case DOWN -> SLAB_BOTTOM_DOWN;
};
case TOP -> switch (state.getValue(FACING)) {
case NORTH -> SLAB_TOP_NORTH;
case SOUTH -> SLAB_TOP_SOUTH;
case EAST -> SLAB_TOP_EAST;
case WEST -> SLAB_TOP_WEST;
case UP -> SLAB_TOP_UP;
case DOWN -> SLAB_TOP_DOWN;
};
case DOUBLE -> SLAB_DOUBLE;
};
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction direction = context.getClickedFace();
BlockState blockState = context.getLevel().getBlockState(context.getClickedPos());
if (blockState.is(this)) {
return blockState.setValue(TYPE, SlabType.DOUBLE).setValue(WATERLOGGED, false);
} else {
FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
return this.defaultBlockState().setValue(FACING, direction).setValue(TYPE, SlabType.BOTTOM).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}

@Override
public boolean canBeReplaced(BlockState blockState, BlockPlaceContext blockPlaceContext) {
ItemStack itemStack = blockPlaceContext.getItemInHand();
SlabType slabType = blockState.getValue(TYPE);
if (slabType != SlabType.DOUBLE && itemStack.is(this.asItem())) {
if (blockPlaceContext.replacingClickedOnBlock()) {
boolean bl = blockPlaceContext.getClickLocation().y - (double)blockPlaceContext.getClickedPos().getY() > 0.5;
Direction direction = blockPlaceContext.getClickedFace();
if (slabType == SlabType.BOTTOM) {
return direction == Direction.UP || bl && direction.getAxis().isHorizontal();
} else {
return direction == Direction.DOWN || !bl && direction.getAxis().isHorizontal();
}
} else {
return true;
}
} else {
return false;
}
}

@Override
public FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}

@Override
public boolean placeLiquid(LevelAccessor levelAccessor, BlockPos blockPos, BlockState blockState, FluidState fluidState) {
return blockState.getValue(TYPE) != SlabType.DOUBLE && SimpleWaterloggedBlock.super.placeLiquid(levelAccessor, blockPos, blockState, fluidState);
}

@Override
public boolean canPlaceLiquid(BlockGetter blockGetter, BlockPos blockPos, BlockState blockState, Fluid fluid) {
return blockState.getValue(TYPE) != SlabType.DOUBLE && SimpleWaterloggedBlock.super.canPlaceLiquid(blockGetter, blockPos, blockState, fluid);
}

@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> stateDefinitionBuilder) {
stateDefinitionBuilder.add(TYPE, FACING, WATERLOGGED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
@Override
public void attack(BlockState blockState, Level level, BlockPos blockPos, Player player) {
if (!level.isClientSide) {
level.setBlock(blockPos, blockState.setValue(FRAME_CENTER, FrameStickDirection.NONE), 3);
level.playSound(null, blockPos, Blocks.SCAFFOLDING.getSoundType(level.getBlockState(blockPos)).getBreakSound(), player.getSoundSource(), 1.0F, 1.0F);
if (blockState.getValue(FRAME_CENTER) != FrameStickDirection.NONE) {
level.setBlock(blockPos, blockState.setValue(FRAME_CENTER, FrameStickDirection.NONE), 3);
level.playSound(null, blockPos, Blocks.SCAFFOLDING.getSoundType(level.getBlockState(blockPos)).getBreakSound(), player.getSoundSource(), 1.0F, 1.0F);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.block.properties.FrameStickDirection;
import com.starfish_studios.foundation.block.properties.LayerNumber;
import com.starfish_studios.foundation.registry.FoundationSoundEvents;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
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.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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.*;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

Expand Down Expand Up @@ -60,6 +72,24 @@ public LayerBlock(Properties properties) {
);
}

@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(LAYERS) > 1) {
level.setBlock(blockPos, blockState.setValue(LAYERS, blockState.getValue(LAYERS) - 1), 3);
Block.popResource(level, blockPos, this.asItem().getDefaultInstance());
player.getItemInHand(interactionHand).hurtAndBreak(1, player, (playerEntity) -> {
playerEntity.broadcastBreakEvent(interactionHand);
});
level.playSound(player, blockPos, FoundationSoundEvents.LAYER_HAMMER, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS;
} else if (blockState.getValue(LAYERS) == 1) {
return InteractionResult.FAIL;
}
}
return InteractionResult.PASS;
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
return switch (state.getValue(LAYERS)) {
Expand Down Expand Up @@ -123,14 +153,28 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
}
return blockState;
}
return blockState.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
if (blockState.is(this)) {
return blockState.setValue(WATERLOGGED, false).setValue(LAYERS, 4);
} else {
return blockState.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}

@Override
public FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}

@Override
public boolean placeLiquid(LevelAccessor levelAccessor, BlockPos blockPos, BlockState blockState, FluidState fluidState) {
return blockState.getValue(LAYERS) != 4 && SimpleWaterloggedBlock.super.placeLiquid(levelAccessor, blockPos, blockState, fluidState);
}

@Override
public boolean canPlaceLiquid(BlockGetter blockGetter, BlockPos blockPos, BlockState blockState, Fluid fluid) {
return blockState.getValue(LAYERS) != 4 && SimpleWaterloggedBlock.super.canPlaceLiquid(blockGetter, blockPos, blockState, fluid);
}

@Override
public BlockState updateShape(BlockState blockState, Direction direction, BlockState blockState2, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) {
if (blockState.getValue(WATERLOGGED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ public DescriptionBlockItem(Block block, Properties properties) {
@Override
public void appendHoverText(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flagIn) {

if (stack.is(FoundationTags.FoundationItemTags.SUPPORTS)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.support2").withStyle(ChatFormatting.GRAY));
} else
tooltip.add(Component.literal("[").withStyle(ChatFormatting.DARK_GRAY).append(Component.translatable("key.keyboard.left.shift").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)).append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY)));
}

if (stack.is(FoundationTags.FoundationItemTags.PALLETS)) {
else if (stack.is(FoundationTags.FoundationItemTags.PALLETS)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.pallet1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pallet2").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.pallet3").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pallet4").withStyle(ChatFormatting.GRAY));
Expand All @@ -38,34 +45,33 @@ public void appendHoverText(ItemStack stack, Level level, List<Component> toolti

else if (stack.is(FoundationTags.FoundationItemTags.LADDERS)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.ladder1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.ladder2").withStyle(ChatFormatting.GRAY));
} else
tooltip.add(Component.literal("[").withStyle(ChatFormatting.DARK_GRAY).append(Component.translatable("key.keyboard.left.shift").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)).append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY)));
}

else if (stack.is(FoundationTags.FoundationItemTags.COLUMNS)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.column1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.column2").withStyle(ChatFormatting.GRAY));
} else
tooltip.add(Component.literal("[").withStyle(ChatFormatting.DARK_GRAY).append(Component.translatable("key.keyboard.left.shift").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)).append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY)));
}

else if (stack.is(FoundationTags.FoundationItemTags.LAYERS)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.layer1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.layer2").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.translatable("description.foundation.layer3").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.layer3").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.layer4").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.layer5").withStyle(ChatFormatting.GRAY)));
} else
tooltip.add(Component.literal("[").withStyle(ChatFormatting.DARK_GRAY).append(Component.translatable("key.keyboard.left.shift").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC)).append(Component.literal("]").withStyle(ChatFormatting.DARK_GRAY)));
}

else if (stack.is(FoundationTags.FoundationItemTags.FRAMES)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.frame1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.hammer_right_click").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.frame2").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.frame3").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.foundation.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.foundation.frame4").withStyle(ChatFormatting.GRAY)));
Expand Down
Loading

0 comments on commit 7b7f200

Please sign in to comment.