Skip to content

Commit

Permalink
[~+] Tweaks, organization, Layer blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Jan 31, 2024
1 parent a8f986c commit af5ac18
Show file tree
Hide file tree
Showing 115 changed files with 2,461 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static void registerScreens() {
private static void registerBlockRenderLayers() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderType.cutout(),
FoundationBlocks.IRON_FENCE,
FoundationBlocks.BIG_OAK_DOOR,
FoundationBlocks.TALL_OAK_DOOR,
FoundationBlocks.ROPE,
FoundationBlocks.BRAZIER,
FoundationBlocks.URN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.block.entity.BrazierBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
Expand All @@ -19,7 +17,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -40,8 +37,6 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class BrazierBlock extends Block implements SimpleWaterloggedBlock {
public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
Expand Down Expand Up @@ -141,12 +136,6 @@ public static void dowse(@Nullable Entity entity, LevelAccessor levelAccessor, B
}
}


BlockEntity blockEntity = levelAccessor.getBlockEntity(blockPos);
if (blockEntity instanceof BrazierBlockEntity) {
((BrazierBlockEntity)blockEntity).dowse();
}

levelAccessor.gameEvent(entity, GameEvent.BLOCK_CHANGE, blockPos);
}

Expand Down
149 changes: 106 additions & 43 deletions src/main/java/com/starfish_studios/foundation/block/ColumnBlock.java
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);
}


}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.registry.FoundationItems;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
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.LevelAccessor;
Expand Down Expand Up @@ -187,6 +189,6 @@ public boolean validConnection(BlockState state) {
|| state.isFaceSturdy(null, null, Direction.DOWN)) {
return true;
}
return state.is(this);
return state.is(FoundationTags.FoundationBlockTags.FRAMES);
}
}
Loading

0 comments on commit af5ac18

Please sign in to comment.