Skip to content

Commit

Permalink
[~+] Plantable Urns, Stone Frames, yada yada
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed May 23, 2024
1 parent 16d0d3a commit c3a87f0
Show file tree
Hide file tree
Showing 453 changed files with 14,030 additions and 21,963 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/starfish_studios/bbb/block/FrameBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.jetbrains.annotations.Nullable;

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

public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
Expand Down Expand Up @@ -63,13 +63,15 @@ public FrameBlock(Properties properties) {
.setValue(BOTTOM, true)
.setValue(LEFT, true)
.setValue(RIGHT, true)
.setValue(SIDES, true)
.setValue(CORNERS, true)
.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(BBBTags.BBBItemTags.HAMMERS)) {
// TODO: This cycles through the frame center options, rotating it sort of like an Item Frame
// region FRAME CENTER CYCLING
if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.NONE) {
blockState = blockState.setValue(FRAME_CENTER, FrameStickDirection.VERTICAL);
} else if (blockState.getValue(FRAME_CENTER) == FrameStickDirection.VERTICAL) {
Expand All @@ -84,6 +86,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
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;
// endregion
} else return InteractionResult.PASS;
}

Expand Down Expand Up @@ -141,7 +144,7 @@ public FluidState getFluidState(BlockState state) {

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

@Override
Expand Down Expand Up @@ -219,6 +222,6 @@ public boolean validConnection(BlockState state) {
state.isFaceSturdy(null, null, Direction.WEST)) {
return true;
}
return state.is(BBBTags.BBBBlockTags.FRAMES);
return state.is(BBBTags.BBBBlockTags.FRAMES) || state.is(BBBTags.BBBBlockTags.STONE_FRAMES);
}
}
33 changes: 31 additions & 2 deletions src/main/java/com/starfish_studios/bbb/block/UrnBlock.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package com.starfish_studios.bbb.block;

import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
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.ItemStack;
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.block.Block;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -11,12 +20,14 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
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;

public class UrnBlock extends Block implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty SOILED = BooleanProperty.create("soiled");

public static VoxelShape SHAPE = Shapes.or(
Block.box(2, 0, 2, 14, 2, 14),
Expand All @@ -27,9 +38,27 @@ public class UrnBlock extends Block implements SimpleWaterloggedBlock {

public UrnBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false));
this.registerDefaultState(this.stateDefinition.any()
.setValue(WATERLOGGED, false)
.setValue(SOILED, false));
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (player.getItemInHand(interactionHand).getItem() == Items.DIRT && !blockState.getValue(SOILED)) {
level.playSound(player, blockPos, SoundEvents.GRAVEL_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
level.setBlock(blockPos, blockState.setValue(SOILED, true), 3);
return InteractionResult.SUCCESS;
} else if (blockState.getValue(SOILED) && player.getItemInHand(interactionHand).is(ItemTags.SHOVELS)) {
level.playSound(player, blockPos, SoundEvents.GRAVEL_BREAK, SoundSource.BLOCKS, 1.0F, 1.0F);
popResource(level, blockPos, new ItemStack(Items.DIRT));
level.setBlock(blockPos, blockState.setValue(SOILED, false), 3);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}


@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
Expand All @@ -48,6 +77,6 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
builder.add(WATERLOGGED, SOILED);
}
}
53 changes: 30 additions & 23 deletions src/main/java/com/starfish_studios/bbb/event/BlockUseEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.starfish_studios.bbb.event;

import com.starfish_studios.bbb.block.FrameBlock;
import com.starfish_studios.bbb.block.MouldingBlock;
import com.starfish_studios.bbb.block.StoneFenceBlock;
import com.starfish_studios.bbb.block.properties.FrameStickDirection;
Expand All @@ -13,57 +14,63 @@
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.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.BlockHitResult;

import static com.starfish_studios.bbb.block.FrameBlock.FRAME_CENTER;

public class BlockUseEvent implements UseBlockCallback {

@Override
public InteractionResult interact(Player player, Level world, InteractionHand hand, BlockHitResult hitResult) {
public InteractionResult interact(Player player, Level level, InteractionHand hand, BlockHitResult hitResult) {
final BlockPos blockPos = hitResult.getBlockPos();
final boolean isHammer = player.getItemInHand(hand).is(BBBTags.BBBItemTags.HAMMERS);
BlockState blockState = level.getBlockState(blockPos);
BlockHitResult blockHitResult = new BlockHitResult(hitResult.getLocation(), hitResult.getDirection(), blockPos, hitResult.isInside());


//TODO : HAMMER + MOULDINGS
final boolean isMoulding = world.getBlockState(hitResult.getBlockPos()).is(BBBTags.BBBBlockTags.MOULDINGS);
final boolean isMoulding = level.getBlockState(hitResult.getBlockPos()).is(BBBTags.BBBBlockTags.MOULDINGS);
if (isHammer && isMoulding) {
if (world.getBlockState(blockPos).getValue(MouldingBlock.DENTIL)) {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(MouldingBlock.DENTIL, false), 3);
world.playSound(player, blockPos, world.getBlockState(blockPos).getBlock().getSoundType(world.getBlockState(blockPos)).getBreakSound(), player.getSoundSource(), 1.0F, 1.0F);
if (level.getBlockState(blockPos).getValue(MouldingBlock.DENTIL)) {
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(MouldingBlock.DENTIL, false), 3);
level.playSound(player, blockPos, level.getBlockState(blockPos).getBlock().getSoundType(level.getBlockState(blockPos)).getBreakSound(), player.getSoundSource(), 1.0F, 1.0F);
} else {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(MouldingBlock.DENTIL, true), 3);
world.playSound(player, blockPos, world.getBlockState(blockPos).getBlock().getSoundType(world.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(MouldingBlock.DENTIL, true), 3);
level.playSound(player, blockPos, level.getBlockState(blockPos).getBlock().getSoundType(level.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
}
return InteractionResult.SUCCESS;
}

//TODO : HAMMER + STONE FENCES
final boolean isStoneFence = world.getBlockState(hitResult.getBlockPos()).is(BBBTags.BBBBlockTags.STONE_FENCES);
final boolean isStoneFence = level.getBlockState(hitResult.getBlockPos()).is(BBBTags.BBBBlockTags.STONE_FENCES);
if (isHammer && isStoneFence) {
if (!world.getBlockState(blockPos).getValue(StoneFenceBlock.NORTH) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.EAST) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.SOUTH) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.WEST)) {
if (!level.getBlockState(blockPos).getValue(StoneFenceBlock.NORTH) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.EAST) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.SOUTH) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.WEST)) {
return InteractionResult.PASS;
} else if (player.isShiftKeyDown()) {
if (!world.getBlockState(blockPos).getValue(StoneFenceBlock.NORTH) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.EAST) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.SOUTH) &&
!world.getBlockState(blockPos).getValue(StoneFenceBlock.WEST)) {
if (!level.getBlockState(blockPos).getValue(StoneFenceBlock.NORTH) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.EAST) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.SOUTH) &&
!level.getBlockState(blockPos).getValue(StoneFenceBlock.WEST)) {
return InteractionResult.PASS;
} else if (world.getBlockState(blockPos).getValue(StoneFenceBlock.PILLAR)) {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(StoneFenceBlock.PILLAR, false), 3);
} else if (level.getBlockState(blockPos).getValue(StoneFenceBlock.PILLAR)) {
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(StoneFenceBlock.PILLAR, false), 3);
} else {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(StoneFenceBlock.PILLAR, true), 3);
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(StoneFenceBlock.PILLAR, true), 3);
}
} else {
if (world.getBlockState(blockPos).getValue(StoneFenceBlock.SIDE_FILL)) {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(StoneFenceBlock.SIDE_FILL, false), 3);
if (level.getBlockState(blockPos).getValue(StoneFenceBlock.SIDE_FILL)) {
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(StoneFenceBlock.SIDE_FILL, false), 3);
} else {
world.setBlock(blockPos, world.getBlockState(blockPos).setValue(StoneFenceBlock.SIDE_FILL, true), 3);
level.setBlock(blockPos, level.getBlockState(blockPos).setValue(StoneFenceBlock.SIDE_FILL, true), 3);
}
}
world.playSound(player, blockPos, world.getBlockState(blockPos).getBlock().getSoundType(world.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
level.playSound(player, blockPos, level.getBlockState(blockPos).getBlock().getSoundType(level.getBlockState(blockPos)).getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
return InteractionResult.SUCCESS;

}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/starfish_studios/bbb/item/ChiselItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.starfish_studios.bbb.item;

import com.starfish_studios.bbb.registry.BBBTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.UseOnContext;
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.state.BlockState;
import net.minecraft.world.phys.HitResult;

import java.util.Optional;
import java.util.Random;

import static com.starfish_studios.bbb.registry.BBBTags.*;
import static com.starfish_studios.bbb.registry.BBBTags.BBBBlockTags.CHISEL_STONE;

public class ChiselItem extends Item {
private final TagKey<Block> outputBlockTag;

public ChiselItem(Properties properties, TagKey<Block> outputBlockTag) {
super(properties);
this.outputBlockTag = outputBlockTag;
}

@Override
public boolean canAttackBlock(BlockState blockState, Level level, BlockPos blockPos, Player player) {
return !player.isCreative();
}

@Override
public InteractionResult useOn(UseOnContext useOnContext) {
Level level = useOnContext.getLevel();
BlockPos blockPos = useOnContext.getClickedPos();
BlockState blockState = level.getBlockState(blockPos);


return InteractionResult.FAIL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ else if (stack.is(BBBTags.BBBItemTags.LAYERS)) {
} else tooltip.add(Component.literal("[").append(Component.translatable("key.keyboard.left.shift")).append(Component.literal("]")).withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.ITALIC));
}

else if (stack.is(BBBTags.BBBItemTags.FRAMES)) {
else if (stack.is(BBBTags.BBBItemTags.FRAMES) || stack.is(BBBTags.BBBItemTags.STONE_FRAMES)) {
if (Screen.hasShiftDown()) {
tooltip.add(Component.translatable("description.bbb.pencil").withStyle(ChatFormatting.BLUE).append(Component.translatable("description.bbb.frame1").withStyle(ChatFormatting.GRAY)));
tooltip.add(Component.translatable("description.bbb.frame2").withStyle(ChatFormatting.GRAY));
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/starfish_studios/bbb/mixin/BushBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.starfish_studios.bbb.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.starfish_studios.bbb.block.UrnBlock;
import com.starfish_studios.bbb.registry.BBBTags;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BushBlock.class)
public abstract class BushBlockMixin extends Block {
public BushBlockMixin(Properties properties) {
super(properties);
}

@ModifyReturnValue(method = "mayPlaceOn", at = @At("RETURN"))
public boolean mayPlaceOn(boolean original, BlockState state, BlockGetter level, BlockPos pos) {
return !original && state.getBlock() instanceof UrnBlock && state.getValue(UrnBlock.SOILED);
}
}
Loading

0 comments on commit c3a87f0

Please sign in to comment.