Skip to content

Commit

Permalink
[~+] Added more Frame stick states, added Hammer tool, added Hedges.
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Feb 1, 2024
1 parent af5ac18 commit d2f61cd
Show file tree
Hide file tree
Showing 226 changed files with 15,679 additions and 472 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/starfish_studios/foundation/Foundation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.starfish_studios.foundation;

import com.google.common.reflect.Reflection;
import com.starfish_studios.foundation.event.FoundationBlockUseEvent;
import com.starfish_studios.foundation.registry.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
Expand All @@ -14,8 +13,6 @@ public class Foundation implements ModInitializer {

@Override
public void onInitialize() {

FoundationBlockUseEvent.EVENT.register(new FoundationBlockUseEvent());
Reflection.initialize(
FoundationCreativeModeTab.class,
FoundationSoundEvents.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,85 @@
package com.starfish_studios.foundation;

import com.starfish_studios.foundation.registry.FoundationBlocks;
import com.starfish_studios.foundation.registry.FoundationItems;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.world.level.ItemLike;

import java.awt.*;
import java.util.Objects;

@Environment(EnvType.CLIENT)
public class FoundationClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
FoundationVanillaIntegration.Client.clientInit();

ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
BiomeColors.getAverageFoliageColor(pos, world) : -1, Objects.requireNonNull(
FoundationBlocks.OAK_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
6396257 : -1, Objects.requireNonNull(
FoundationBlocks.SPRUCE_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
8431445 : -1, Objects.requireNonNull(
FoundationBlocks.BIRCH_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
BiomeColors.getAverageFoliageColor(pos, world) : -1, Objects.requireNonNull(
FoundationBlocks.JUNGLE_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
BiomeColors.getAverageFoliageColor(pos, world) : -1, Objects.requireNonNull(
FoundationBlocks.ACACIA_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
BiomeColors.getAverageFoliageColor(pos, world) : -1, Objects.requireNonNull(
FoundationBlocks.DARK_OAK_HEDGE
));
ColorProviderRegistry.BLOCK.register((block, pos, world, layer) -> world != null && pos != null ?
BiomeColors.getAverageFoliageColor(pos, world) : -1, Objects.requireNonNull(
FoundationBlocks.MANGROVE_HEDGE
));

ColorProviderRegistry.ITEM.register((stack, layer) -> {
ItemLike item = stack.getItem();
if (item == FoundationItems.OAK_HEDGE.asItem()) {
return 4764952;
}
return -1;
}, FoundationItems.OAK_HEDGE, FoundationItems.JUNGLE_HEDGE, FoundationItems.ACACIA_HEDGE, FoundationItems.DARK_OAK_HEDGE);
ColorProviderRegistry.ITEM.register((stack, layer) -> {
ItemLike item = stack.getItem();
if (item == FoundationItems.SPRUCE_HEDGE.asItem()) {
return 6396257;
}
return -1;
}, FoundationItems.SPRUCE_HEDGE);
ColorProviderRegistry.ITEM.register((stack, layer) -> {
ItemLike item = stack.getItem();
if (item == FoundationItems.BIRCH_HEDGE.asItem()) {
return 8431445;
}
return -1;
}, FoundationItems.BIRCH_HEDGE);
ColorProviderRegistry.ITEM.register((stack, layer) -> {
ItemLike item = stack.getItem();
if (item == FoundationItems.MANGROVE_HEDGE.asItem()) {
return 9619016;
}
return -1;
}, FoundationItems.MANGROVE_HEDGE);



}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ private static void registerBlockRenderLayers() {
FoundationBlocks.TALL_OAK_DOOR,
FoundationBlocks.ROPE,
FoundationBlocks.BRAZIER,
FoundationBlocks.URN
FoundationBlocks.URN,
FoundationBlocks.OAK_HEDGE,
FoundationBlocks.SPRUCE_HEDGE,
FoundationBlocks.BIRCH_HEDGE,
FoundationBlocks.JUNGLE_HEDGE,
FoundationBlocks.ACACIA_HEDGE,
FoundationBlocks.DARK_OAK_HEDGE,
FoundationBlocks.MANGROVE_HEDGE,
FoundationBlocks.CHERRY_HEDGE
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.starfish_studios.foundation.Foundation;
import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.ItemTags;
Expand Down Expand Up @@ -57,7 +58,7 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
}

public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (player.getItemInHand(interactionHand).is(ItemTags.PICKAXES)) {
if (player.getItemInHand(interactionHand).is(FoundationTags.FoundationItemTags.HAMMERS)) {
if (blockState.getValue(FACING) == Direction.UP) {
if (blockHitResult.getLocation().y - blockPos.getY() < 0.25) {
blockState = blockState.cycle(LAYER_ONE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
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.registry.FoundationItems;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
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.*;
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.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.pathfinder.PathComputationType;
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;

public class FrameBlock extends Block implements SimpleWaterloggedBlock {
public static final BooleanProperty SIDES = BooleanProperty.create("sides");
public static final BooleanProperty MIDDLE = BooleanProperty.create("middle");
public static final EnumProperty<FrameStickDirection> FRAME_CENTER = FoundationBlockStateProperties.FRAME_CENTER;

public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
Expand Down Expand Up @@ -56,7 +64,35 @@ public FrameBlock(Properties properties) {
.setValue(LEFT, true)
.setValue(RIGHT, true)
.setValue(SIDES, true)
.setValue(MIDDLE, false));
.setValue(FRAME_CENTER, FrameStickDirection.NONE));
}

@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(FRAME_CENTER) == FrameStickDirection.NONE) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.VERTICAL);
} else if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.VERTICAL) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.RIGHT);
} else if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.RIGHT) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.HORIZONTAL);
} else if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.HORIZONTAL) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.LEFT);
} else if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.LEFT) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.VERTICAL);
}
level.setBlock(blockPos, blockState, 3);
level.playSound(player, blockPos, Blocks.SCAFFOLDING.getSoundType(level.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
return InteractionResult.SUCCESS;
} else return InteractionResult.PASS;
}

@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);
}
}

public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
Expand Down Expand Up @@ -115,7 +151,7 @@ public FluidState getFluidState(BlockState state) {

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED, TOP, BOTTOM, LEFT, RIGHT, SIDES, MIDDLE);
builder.add(FACING, WATERLOGGED, TOP, BOTTOM, LEFT, RIGHT, SIDES, FRAME_CENTER);
}

@Override
Expand Down
139 changes: 139 additions & 0 deletions src/main/java/com/starfish_studios/foundation/block/HedgeBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.starfish_studios.foundation.block;

import com.google.common.collect.ImmutableMap;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.WallSide;
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.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.Iterator;
import java.util.Map;

public class HedgeBlock extends WallBlock {

private final Map<BlockState, VoxelShape> shapeByIndex;
private final Map<BlockState, VoxelShape> collisionShapeByIndex;

public HedgeBlock(Properties properties) {
super(properties);
this.shapeByIndex = this.makeShapes(4.0F, 3.0F, 16.0F, 0.0F, 16.0F, 16.0F);
this.collisionShapeByIndex = this.makeShapes(4.0F, 3.0F, 24.0F, 0.0F, 24.0F, 24.0F);
}

private Map<BlockState, VoxelShape> makeShapes(float f, float g, float h, float i, float j, float k) {
float l = 8.0F - f;
float m = 8.0F + f;
float n = 8.0F - g;
float o = 8.0F + g;
VoxelShape voxelShape = Block.box(l, 0.0, l, m, h, m);
VoxelShape voxelShape2 = Block.box(n, i, 0.0, o, j, o);
VoxelShape voxelShape3 = Block.box(n, i, n, o, j, 16.0);
VoxelShape voxelShape4 = Block.box(0.0, i, n, o, j, o);
VoxelShape voxelShape5 = Block.box(n, i, n, 16.0, j, o);
VoxelShape voxelShape6 = Block.box(n, i, 0.0, o, k, o);
VoxelShape voxelShape7 = Block.box(n, i, n, o, k, 16.0);
VoxelShape voxelShape8 = Block.box(0.0, i, n, o, k, o);
VoxelShape voxelShape9 = Block.box(n, i, n, 16.0, k, o);
ImmutableMap.Builder<BlockState, VoxelShape> builder = ImmutableMap.builder();

for (Boolean boolean_ : UP.getPossibleValues()) {

for (WallSide wallSide : EAST_WALL.getPossibleValues()) {

for (WallSide wallSide2 : NORTH_WALL.getPossibleValues()) {

for (WallSide wallSide3 : WEST_WALL.getPossibleValues()) {

for (WallSide wallSide4 : SOUTH_WALL.getPossibleValues()) {
VoxelShape voxelShape10 = Shapes.empty();
voxelShape10 = applyWallShape(voxelShape10, wallSide, voxelShape5, voxelShape9);
voxelShape10 = applyWallShape(voxelShape10, wallSide3, voxelShape4, voxelShape8);
voxelShape10 = applyWallShape(voxelShape10, wallSide2, voxelShape2, voxelShape6);
voxelShape10 = applyWallShape(voxelShape10, wallSide4, voxelShape3, voxelShape7);
if (boolean_) {
voxelShape10 = Shapes.or(voxelShape10, voxelShape);
}

BlockState blockState = this.defaultBlockState().setValue(UP, boolean_).setValue(EAST_WALL, wallSide).setValue(WEST_WALL, wallSide3).setValue(NORTH_WALL, wallSide2).setValue(SOUTH_WALL, wallSide4);
builder.put(blockState.setValue(WATERLOGGED, false), voxelShape10);
builder.put(blockState.setValue(WATERLOGGED, true), voxelShape10);
}
}
}
}
}

return builder.build();
}

public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return this.shapeByIndex.get(blockState);
}

public VoxelShape getCollisionShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return this.collisionShapeByIndex.get(blockState);
}

public boolean connectsTo(BlockState blockState, boolean bl, Direction direction) {
Block block = blockState.getBlock();
boolean bl2 = block instanceof FenceGateBlock && FenceGateBlock.connectsToDirection(blockState, direction);
return blockState.is(FoundationTags.FoundationBlockTags.HEDGES) || !isExceptionForConnection(blockState) && bl || bl2;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
LevelReader levelReader = blockPlaceContext.getLevel();
BlockPos blockPos = blockPlaceContext.getClickedPos();
FluidState fluidState = blockPlaceContext.getLevel().getFluidState(blockPlaceContext.getClickedPos());
BlockPos blockPos2 = blockPos.north();
BlockPos blockPos3 = blockPos.east();
BlockPos blockPos4 = blockPos.south();
BlockPos blockPos5 = blockPos.west();
BlockPos blockPos6 = blockPos.above();
BlockState blockState = levelReader.getBlockState(blockPos2);
BlockState blockState2 = levelReader.getBlockState(blockPos3);
BlockState blockState3 = levelReader.getBlockState(blockPos4);
BlockState blockState4 = levelReader.getBlockState(blockPos5);
BlockState blockState5 = levelReader.getBlockState(blockPos6);
boolean bl = this.connectsTo(blockState, blockState.isFaceSturdy(levelReader, blockPos2, Direction.SOUTH), Direction.SOUTH);
boolean bl2 = this.connectsTo(blockState2, blockState2.isFaceSturdy(levelReader, blockPos3, Direction.WEST), Direction.WEST);
boolean bl3 = this.connectsTo(blockState3, blockState3.isFaceSturdy(levelReader, blockPos4, Direction.NORTH), Direction.NORTH);
boolean bl4 = this.connectsTo(blockState4, blockState4.isFaceSturdy(levelReader, blockPos5, Direction.EAST), Direction.EAST);
BlockState blockState6 = this.defaultBlockState().setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
return this.updateShape(levelReader, blockState6, blockPos6, blockState5, bl, bl2, bl3, bl4);
}

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));
}

if (direction == Direction.DOWN) {
return super.updateShape(blockState, direction, blockState2, levelAccessor, blockPos, blockPos2);
} else {
return direction == Direction.UP ? this.topUpdate(levelAccessor, blockState, blockPos2, blockState2) : this.sideUpdate(levelAccessor, blockPos, blockState, blockPos2, blockState2, direction);
}
}

private BlockState sideUpdate(LevelReader levelReader, BlockPos blockPos, BlockState blockState, BlockPos blockPos2, BlockState blockState2, Direction direction) {
Direction direction2 = direction.getOpposite();
boolean bl = direction == Direction.NORTH ? this.connectsTo(blockState2, blockState2.isFaceSturdy(levelReader, blockPos2, direction2), direction2) : isConnected(blockState, NORTH_WALL);
boolean bl2 = direction == Direction.EAST ? this.connectsTo(blockState2, blockState2.isFaceSturdy(levelReader, blockPos2, direction2), direction2) : isConnected(blockState, EAST_WALL);
boolean bl3 = direction == Direction.SOUTH ? this.connectsTo(blockState2, blockState2.isFaceSturdy(levelReader, blockPos2, direction2), direction2) : isConnected(blockState, SOUTH_WALL);
boolean bl4 = direction == Direction.WEST ? this.connectsTo(blockState2, blockState2.isFaceSturdy(levelReader, blockPos2, direction2), direction2) : isConnected(blockState, WEST_WALL);
BlockPos blockPos3 = blockPos.above();
BlockState blockState3 = levelReader.getBlockState(blockPos3);
return this.updateShape(levelReader, blockState, blockPos3, blockState3, bl, bl2, bl3, bl4);
}
}
Loading

0 comments on commit d2f61cd

Please sign in to comment.