Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadoo-Gazoono committed Feb 2, 2024
2 parents c3bd921 + e6ab00b commit 796b008
Show file tree
Hide file tree
Showing 124 changed files with 7,413 additions and 471 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,8 +1,17 @@
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 {
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
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.registry.FoundationTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;

public class IronFenceBlock extends FenceBlock {
public class IronFenceBlock extends WallBlock {
public IronFenceBlock(Properties properties) {
super(properties);
}

@Override
public boolean connectsTo(BlockState blockState, boolean bl, Direction direction) {
Block block = blockState.getBlock();
boolean bl2 = this.isSameFence(blockState);
boolean bl3 = block instanceof FenceGateBlock && FenceGateBlock.connectsToDirection(blockState, direction);
return !isExceptionForConnection(blockState) && bl || bl2 || bl3;
boolean bl2 = block instanceof FenceGateBlock && FenceGateBlock.connectsToDirection(blockState, direction);
return blockState.is(FoundationTags.FoundationBlockTags.METAL_FENCES) || !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 boolean isSameFence(BlockState blockState) {
return blockState.is(BlockTags.FENCES) && blockState.is(FoundationTags.FoundationBlockTags.METAL_FENCES) == this.defaultBlockState().is(FoundationTags.FoundationBlockTags.METAL_FENCES);
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.starfish_studios.foundation.block;

import com.starfish_studios.foundation.block.properties.FoundationBlockStateProperties;
import com.starfish_studios.foundation.registry.FoundationTags;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected void playSound(@Nullable Player player, Level level, BlockPos blockPos

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (player.getItemInHand(interactionHand).is(ItemTags.AXES)) {
if (player.getItemInHand(interactionHand).is(FoundationTags.FoundationItemTags.HAMMERS)) {
if (blockHitResult.getLocation().z - (double)blockPos.getZ() > 0.5 && blockState.getValue(FACING) == Direction.NORTH) {
if (blockHitResult.getLocation().z - (double)blockPos.getZ() < 0.75) {
blockState = blockState.cycle(LAYER_ONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;

public class FoundationBlockStateProperties {
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);
public static final EnumProperty<LayerNumber> LAYERS = EnumProperty.create("layer", LayerNumber.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.starfish_studios.foundation.block.properties;

import net.minecraft.util.StringRepresentable;

public enum FrameStickDirection implements StringRepresentable {
LEFT("left"),
VERTICAL("vertical"),
HORIZONTAL("horizontal"),
RIGHT("right"),
NONE("none");

private final String name;

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

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

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ else if (stack.is(FoundationTags.FoundationItemTags.COLUMNS)) {
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.layer2").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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class FoundationBlocks {
// endregion


public static final Block IRON_FENCE = register("iron_fence", new WallBlock(FabricBlockSettings.copy((Blocks.IRON_BARS)).noOcclusion()));
public static final Block IRON_FENCE = register("iron_fence", new IronFenceBlock(FabricBlockSettings.copy((Blocks.IRON_BARS)).noOcclusion()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FoundationCreativeModeTab {
public static final CreativeModeTab ITEM_GROUP = register("item_group", FabricItemGroup.builder().icon(FOUNDATION::getDefaultInstance).title(Component.translatable("itemGroup.foundation.tab")).displayItems((featureFlagSet, output) -> {

// output.accept(STONE_LAYER);
output.accept(HAMMER);

output.accept(POLISHED_STONE);
output.accept(POLISHED_STONE_STAIRS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class FoundationItems {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface FoundationTags {
// region BLOCK TAGS
interface FoundationBlockTags {
TagKey<Block> METAL_FENCES = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "metal_fences"));
TagKey<Block> HEDGES = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "hedges"));
TagKey<Block> STONE_BALUSTRADES = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "stone_balustrades"));

TagKey<Block> STONE_FENCES = TagKey.create(Registries.BLOCK, new ResourceLocation(MOD_ID, "stone_fences"));
Expand All @@ -29,6 +30,7 @@ interface FoundationItemTags {
TagKey<Item> PALLETS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "pallets"));
TagKey<Item> COLUMNS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "columns"));
TagKey<Item> LAYERS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "layers"));
TagKey<Item> HAMMERS = TagKey.create(Registries.ITEM, new ResourceLocation(MOD_ID, "hammers"));
}

}
Loading

0 comments on commit 796b008

Please sign in to comment.