Skip to content

Commit

Permalink
[~] Big Door tweaks, Ladder variant implementation (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Feb 3, 2024
1 parent af8ff98 commit e313541
Show file tree
Hide file tree
Showing 131 changed files with 495 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ private static void registerBlockRenderLayers() {
FoundationBlocks.IRON_FENCE,
FoundationBlocks.ROPE,
FoundationBlocks.BRAZIER,
FoundationBlocks.URN
FoundationBlocks.URN,
FoundationBlocks.OAK_LADDER
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.starfish_studios.foundation.registry.FoundationBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvent;
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.LivingEntity;
Expand All @@ -18,6 +22,7 @@
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.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

Expand All @@ -30,6 +35,11 @@ public class BigDoorBlock extends Block {
public static final EnumProperty<DoorHingeSide> HINGE;
public static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D);

protected static final VoxelShape NORTH_AABB = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D);
protected static final VoxelShape SOUTH_AABB = Block.box(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D);
protected static final VoxelShape WEST_AABB = Block.box(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
protected static final VoxelShape EAST_AABB = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);

//protected static final VoxelShape SOUTH_AABB;
//protected static final VoxelShape NORTH_AABB;
//protected static final VoxelShape WEST_AABB;
Expand All @@ -39,7 +49,44 @@ public class BigDoorBlock extends Block {

@Override
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return SHAPE;
if (blockState.getValue(HINGE) == DoorHingeSide.LEFT) {
if (blockState.getValue(OPEN)) {
return switch (blockState.getValue(FACING)) {
case NORTH -> WEST_AABB;
case SOUTH -> EAST_AABB;
case WEST -> NORTH_AABB;
case EAST -> SOUTH_AABB;
default -> { throw new IllegalStateException("Unexpected value: " + blockState.getValue(FACING)); }
};
} else {
return switch (blockState.getValue(FACING)) {
case NORTH -> NORTH_AABB;
case SOUTH -> SOUTH_AABB;
case WEST -> EAST_AABB;
case EAST -> WEST_AABB;
default -> { throw new IllegalStateException("Unexpected value: " + blockState.getValue(FACING)); }
};
}
} else if (blockState.getValue(HINGE) == DoorHingeSide.RIGHT) {
if (blockState.getValue(OPEN)) {
return switch (blockState.getValue(FACING)) {
case NORTH -> EAST_AABB;
case SOUTH -> WEST_AABB;
case WEST -> SOUTH_AABB;
case EAST -> NORTH_AABB;
default -> { throw new IllegalStateException("Unexpected value: " + blockState.getValue(FACING)); }
};
} else {
return switch (blockState.getValue(FACING)) {
case NORTH -> NORTH_AABB;
case SOUTH -> SOUTH_AABB;
case WEST -> EAST_AABB;
case EAST -> WEST_AABB;
default -> { throw new IllegalStateException("Unexpected value: " + blockState.getValue(FACING)); }
};
}
}
return Shapes.block();
}

public BigDoorBlock(Properties properties) {
Expand Down Expand Up @@ -117,7 +164,7 @@ public DoorHingeSide getHingeSide(BlockPlaceContext context, BlockPos leftPos, B

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

@Override
Expand Down Expand Up @@ -150,6 +197,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
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);
level.playSound(player, blockPos, this.getOpenSound(), SoundSource.BLOCKS, 1.0F, 0.6F);
return InteractionResult.SUCCESS;
}
else{
Expand All @@ -158,6 +206,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
placeAirColumn(level, startPos.relative(blockState.getValue(FACING).getClockWise()));
placeDoorColumn(blockState, level, startPos, 0, true);
placeDoorColumn(blockState, level, startPos.relative(blockState.getValue(FACING).getOpposite()), 1, true);
level.playSound(player, blockPos, this.getOpenSound(), SoundSource.BLOCKS, 1.0F, 0.6F);
return InteractionResult.SUCCESS;
}
}
Expand All @@ -168,6 +217,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
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);
level.playSound(player, blockPos, this.getCloseSound(), SoundSource.BLOCKS, 1.0F, 0.6F);
return InteractionResult.SUCCESS;
}
else{
Expand All @@ -176,11 +226,20 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
placeAirColumn(level, startPos.relative(blockState.getValue(FACING).getOpposite()));
placeDoorColumn(blockState, level, startPos, 1, false);
placeDoorColumn(blockState, level, startPos.relative(blockState.getValue(FACING).getClockWise()), 0, false);
level.playSound(player, blockPos, this.getCloseSound(), SoundSource.BLOCKS, 1.0F, 0.6F);
return InteractionResult.SUCCESS;
}
}
}

protected SoundEvent getOpenSound() {
return SoundEvents.WOODEN_DOOR_OPEN;
}

protected SoundEvent getCloseSound() {
return SoundEvents.WOODEN_DOOR_CLOSE;
}

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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.block.properties.WoodStyle;
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.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
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.LadderBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.BlockHitResult;

public class FoundationLadderBlock extends LadderBlock {
public static IntegerProperty STYLE = FoundationBlockStateProperties.STYLE;
public FoundationLadderBlock(int defaultStyle, Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any()
.setValue(FACING, Direction.NORTH)
.setValue(WATERLOGGED, false)
.setValue(STYLE, defaultStyle));
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (player.getItemInHand(hand).is(FoundationTags.FoundationItemTags.HAMMERS)) {
level.setBlock(blockPos, state.cycle(STYLE), 3);
level.playSound(null, blockPos, Blocks.SCAFFOLDING.getSoundType(level.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}

protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED, STYLE);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;

public class FoundationBlockStateProperties {
// public static final EnumProperty<WoodStyle> STYLE = EnumProperty.create("style", WoodStyle.class);
public static final IntegerProperty STYLE = IntegerProperty.create("style", 1, 11);
public static final EnumProperty<FrameStickDirection> FRAME_CENTER = EnumProperty.create("center", FrameStickDirection.class);
public static final EnumProperty<ColumnType> COLUMN_TYPE = EnumProperty.create("type", ColumnType.class);
public static final EnumProperty<TallDoorHalf> HALVES = EnumProperty.create("type", TallDoorHalf.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.starfish_studios.foundation.block.properties;

import net.minecraft.util.StringRepresentable;

public enum WoodStyle implements StringRepresentable {
OAK("oak"),
SPRUCE("spruce"),
BIRCH("birch"),
JUNGLE("jungle"),
ACACIA("acacia"),
DARK_OAK("dark_oak"),
MANGROVE("mangrove"),
BAMBOO("bamboo"),
CHERRY("cherry"),
CRIMSON("crimson"),
WARPED("warped");

private final String name;

private WoodStyle(String type) {
this.name = type;
}

public String toString() {
return this.name;
}

public String getSerializedName() {
return this.name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

public class FoundationBlocks {

public static final Block OAK_LADDER = register("oak_ladder", new FoundationLadderBlock(1, BlockBehaviour.Properties.copy(Blocks.LADDER)));


// region LAYERS
public static final Block OAK_LAYER = register("oak_layer", new LayerBlock(FabricBlockSettings.copy((Blocks.OAK_PLANKS))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class FoundationCreativeModeTab {
// output.accept(STONE_LAYER);
output.accept(HAMMER);

output.accept(OAK_LADDER);

output.accept(POLISHED_STONE);
output.accept(POLISHED_STONE_STAIRS);
output.accept(POLISHED_STONE_SLAB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public class FoundationItems {
public static final Item WAXED_OXIDIZED_CUT_COPPER_LAYER = register("waxed_oxidized_cut_copper_layer", new DescriptionBlockItem(FoundationBlocks.WAXED_OXIDIZED_CUT_COPPER_LAYER, new FabricItemSettings()));

// endregion



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


public static final Item POLISHED_STONE = register("polished_stone", new BlockItem(FoundationBlocks.POLISHED_STONE, new FabricItemSettings()));
Expand Down
Loading

0 comments on commit e313541

Please sign in to comment.