Skip to content

Commit

Permalink
Big Door progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadoo-Gazoono committed Feb 2, 2024
1 parent af5ac18 commit c3bd921
Show file tree
Hide file tree
Showing 23 changed files with 674 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private static void registerScreens() {
private static void registerBlockRenderLayers() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderType.cutout(),
FoundationBlocks.IRON_FENCE,
FoundationBlocks.TALL_OAK_DOOR,
FoundationBlocks.ROPE,
FoundationBlocks.BRAZIER,
FoundationBlocks.URN
Expand Down
167 changes: 167 additions & 0 deletions src/main/java/com/starfish_studios/foundation/block/BigDoorBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.registry.FoundationBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
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.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
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.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class BigDoorBlock extends Block {
public static final DirectionProperty FACING;
public static final BooleanProperty OPEN;
public static final BooleanProperty POWERED;
public static final IntegerProperty X_POS;
public static final IntegerProperty Y_POS;
public static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D);

//protected static final VoxelShape SOUTH_AABB;
//protected static final VoxelShape NORTH_AABB;
//protected static final VoxelShape WEST_AABB;
//protected static final VoxelShape EAST_AABB;
//private final BlockSetType type;


@Override
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return SHAPE;
}

public BigDoorBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(X_POS,0).setValue(Y_POS, 0).setValue(OPEN, Boolean.FALSE));
}

public void setPlacedBy(Level level, BlockPos blockPos, BlockState blockState, LivingEntity livingEntity, ItemStack itemStack) {
super.setPlacedBy(level, blockPos, blockState, livingEntity, itemStack);
if (!level.isClientSide){
for (int i = 0; i < 4; i ++){
for (int j = 0; j < 2; j++) {
level.setBlock(blockPos
.above(i)
.relative(blockState.getValue(FACING).getCounterClockWise(), j),
blockState.setValue(X_POS, j).setValue(Y_POS, i)
,3);
}
}
}
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
return super.getStateForPlacement(blockPlaceContext).setValue(FACING, blockPlaceContext.getHorizontalDirection().getOpposite());
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING,OPEN,X_POS, Y_POS);
}

@Override
public void playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) {
super.playerWillDestroy(level, blockPos, blockState, player);
boolean open = blockState.getValue(OPEN).booleanValue();
if (!open) {
BlockPos startPos = getClosedStartPos(blockPos, level, blockState);
BlockPos innerPos = startPos.relative(blockState.getValue(FACING).getCounterClockWise());
placeAirColumn(level, innerPos);
placeAirColumn(level, startPos);
}
else{
BlockPos startPos = getOpenStartPos(blockPos, level, blockState);
BlockPos innerPos = startPos.relative(blockState.getValue(FACING).getOpposite());
placeAirColumn(level, innerPos);
placeAirColumn(level, startPos);
}

}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
boolean open = blockState.getValue(OPEN).booleanValue();
BlockPos startPos = open ? getOpenStartPos(blockPos, level, blockState) : getClosedStartPos(blockPos, level, blockState);
if (!open) {
placeAirColumn(level, startPos.relative(blockState.getValue(FACING).getCounterClockWise()));
placeDoorColumn(blockState, level, startPos, 0, true);
placeDoorColumn(blockState, level, startPos.relative(blockState.getValue(FACING).getOpposite()), 1, true);
System.out.println("opening");
return InteractionResult.SUCCESS;

}
else{
placeAirColumn(level, startPos.relative(blockState.getValue(FACING).getOpposite()));
placeDoorColumn(blockState, level, startPos, 0, false);
placeDoorColumn(blockState, level, startPos.relative(blockState.getValue(FACING).getCounterClockWise()), 1, false);

System.out.println("closing");
return InteractionResult.SUCCESS;
}

//return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
}

private void placeDoorColumn(BlockState blockState, Level level, BlockPos pos, int xPos, boolean open){
for (int i = 0; i < 4; i ++){
level.setBlock(pos.below(i), FoundationBlocks.BIG_DOOR.defaultBlockState()
.setValue(Y_POS, 3-i)
.setValue(X_POS, xPos)
.setValue(OPEN, open)
.setValue(FACING, blockState.getValue(FACING)), 3);
}
}

private void placeAirColumn(Level level, BlockPos pos){
for (int i = 0; i < 4; i ++){
level.setBlock(pos.below(i), Blocks.AIR.defaultBlockState(), 3);
}
}

private BlockPos getClosedStartPos(BlockPos pos, Level level, BlockState blockState){
BlockPos startPosition = pos;
while (level.getBlockState(startPosition).is(FoundationBlocks.BIG_DOOR) && level.getBlockState(startPosition).getValue(X_POS) != 0) {
startPosition = startPosition.relative(blockState.getValue(FACING).getClockWise());
}
while (level.getBlockState(startPosition).is(FoundationBlocks.BIG_DOOR) && level.getBlockState(startPosition).getValue(Y_POS) != 3) {
startPosition = startPosition.above();
}
return startPosition;
}

private BlockPos getOpenStartPos(BlockPos pos, Level level, BlockState blockState){
BlockPos startPosition = pos;
while (level.getBlockState(startPosition).is(FoundationBlocks.BIG_DOOR) && level.getBlockState(startPosition).getValue(Y_POS) != 3) {
startPosition = startPosition.above();
}
while (level.getBlockState(startPosition).is(FoundationBlocks.BIG_DOOR) && level.getBlockState(startPosition).getValue(X_POS) != 0) {
startPosition = startPosition.relative(blockState.getValue(FACING));
}
return startPosition;
}

static {
FACING = HorizontalDirectionalBlock.FACING;
OPEN = BlockStateProperties.OPEN;
X_POS = IntegerProperty.create("x_pos",0,2);
POWERED = BlockStateProperties.POWERED;
Y_POS = IntegerProperty.create("y_pos",0,4);
//SOUTH_AABB = Block.box(0.0, 0.0, 0.0, 16.0, 16.0, 3.0);
//NORTH_AABB = Block.box(0.0, 0.0, 13.0, 16.0, 16.0, 16.0);
//WEST_AABB = Block.box(13.0, 0.0, 0.0, 16.0, 16.0, 16.0);
//EAST_AABB = Block.box(0.0, 0.0, 0.0, 3.0, 16.0, 16.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public class FoundationBlocks {

public static final Block STONE_MOULDING = register("stone_moulding", new StairBlock((Blocks.STONE_BRICKS.defaultBlockState()), BlockBehaviour.Properties.copy(Blocks.STONE_BRICKS).noOcclusion()));

public static final Block TALL_OAK_DOOR = register("tall_oak_door", new TallDoorBlock(FabricBlockSettings.copy((Blocks.OAK_PLANKS)).noOcclusion(), BlockSetType.OAK));
//public static final Block TALL_OAK_DOOR = register("tall_oak_door", new TallDoorBlock(FabricBlockSettings.copy((Blocks.OAK_PLANKS)).noOcclusion(), BlockSetType.OAK));

// big doors
public static final Block BIG_DOOR = register("big_door", new BigDoorBlock(FabricBlockSettings.copy((Blocks.OAK_DOOR)).noOcclusion()));


private static Block register(String id, Block block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FoundationCreativeModeTab {

output.accept(IRON_FENCE);

output.accept(TALL_OAK_DOOR);
output.accept(BIG_DOOR);


output.accept(OAK_TRIM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public class FoundationItems {

public static final Item WRENCH = register("wrench", new WrenchItem(new FabricItemSettings().maxCount(1)));

public static final Item TALL_OAK_DOOR = register("tall_oak_door", new TallDoorItem(FoundationBlocks.TALL_OAK_DOOR, new FabricItemSettings()));
//public static final Item TALL_OAK_DOOR = register("tall_oak_door", new TallDoorItem(FoundationBlocks.TALL_OAK_DOOR, new FabricItemSettings()));

public static final Item BIG_DOOR = register("big_door", new BlockItem(FoundationBlocks.BIG_DOOR, new FabricItemSettings()));

private static Item register(String id, Item item) {
return Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(Foundation.MOD_ID, id), item);
Expand Down
Loading

0 comments on commit c3bd921

Please sign in to comment.