Skip to content

Commit

Permalink
block chunks redone
Browse files Browse the repository at this point in the history
  • Loading branch information
Synthestra committed Dec 23, 2024
1 parent c9acb45 commit 5c88625
Show file tree
Hide file tree
Showing 89 changed files with 721 additions and 1,675 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ public BalustradeBlock(Properties properties) {

@Override
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (!player.getItemInHand(hand).is(ModItemTags.HAMMERS)) return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
if (!stack.is(ModItemTags.HAMMERS)) return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;

if (hitResult.getLocation().y - (double)pos.getY() > 0.5D) {
boolean half = hitResult.getLocation().y - (double)pos.getY() > 0.5D;
if (half) {
level.setBlockAndUpdate(pos, state.cycle(TOP));
} else if (hitResult.getLocation().y - (double)pos.getY() < 0.5D) {
} else {
level.setBlockAndUpdate(pos, state.cycle(BOTTOM));
}
level.playSound(player, pos, state.getSoundType().getPlaceSound(), player.getSoundSource(), 1.0F, 1.0F);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
package com.starfish_studios.building_but_better.block;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.netty.buffer.ByteBuf;
import com.starfish_studios.building_but_better.block.properties.BBBBlockStateProperties;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.util.ByIdMap;
import net.minecraft.util.StringRepresentable;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.component.FireworkExplosion;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
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.IntegerProperty;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import java.util.function.IntFunction;

public class BlockBlock extends AbstractBlockBlock implements Equipable {
public static final MapCodec<BlockBlock> CODEC = RecordCodecBuilder.mapCodec(
(instance) -> instance.group(BlockBlock.Types.CODEC.fieldOf("type")
.forGetter(e -> e.type),propertiesCodec())
.apply(instance, BlockBlock::new));
@Override
protected MapCodec<BlockBlock> codec() {
return CODEC;
}

public static final int MAX = RotationSegment.getMaxSegmentIndex();
public class BlockBlock extends Block implements Equipable {
public static final int MAX = 3;
private static final int ROTATIONS = MAX + 1;
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final IntegerProperty ROTATION = BBBBlockStateProperties.ROTATION_4;
protected static final VoxelShape SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 8.0, 12.0);

public BlockBlock(Types type, Properties properties) {
super(type, properties);
public BlockBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0));
}

Expand All @@ -53,14 +36,9 @@ public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, Block
return SHAPE;
}

@Override
public VoxelShape getOcclusionShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
return Shapes.empty();
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
return this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(blockPlaceContext.getRotation()));
return this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(blockPlaceContext.getRotation()) % 4);
}

@Override
Expand All @@ -78,38 +56,9 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(ROTATION);
}


public enum Types implements StringRepresentable
{
STONE(0,"stone"),
BLACKSTONE(1, "blackstone"),
DEEPSLATE(2, "deepslate"),
NETHER_BRICK(3, "nether_brick"),
SANDSTONE(4, "sandstone"),
RED_SANDSTONE(5, "red_sandstone"),
QUARTZ(6, "quartz");

public static final IntFunction<Types> BY_ID = ByIdMap.continuous(Types::getId, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
public static final Codec<Types> CODEC = StringRepresentable.fromValues(Types::values);
private final int id;
private final String name;

Types(final int id, final String name) {
this.id = id;
this.name = name;
}

public int getId() {
return this.id;
}

public static Types byId(int id) {
return BY_ID.apply(id);
}

public String getSerializedName() {
return this.name;
}
@Override
public EquipmentSlot getEquipmentSlot() {
return EquipmentSlot.HEAD;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
}

if (stack.is(Items.FLINT_AND_STEEL) && !state.getValue(LIT)) {
//stack.hurtAndBreak(1, player, (playerEntity) -> { playerEntity.broadcastBreakEvent(interactionHand); });
stack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
level.playSound(null, pos, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.random.nextFloat() * 0.4F + 0.8F);
level.setBlock(pos, state.setValue(LIT, true), 11);
return ItemInteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -200,40 +201,36 @@ public void attack(BlockState blockState, Level level, BlockPos blockPos, Player
}
}

public static InteractionResult use(@Nullable Entity entity, BlockState blockState, Level level, BlockPos blockPos) {

return InteractionResult.PASS;
}

public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (!level.isClientSide && player.getItemInHand(hand).is(Items.SHEARS)) {
@Override
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (!level.isClientSide && stack.is(Items.SHEARS)) {
LatticePlantType plantType = state.getValue(PLANT_TYPE);
if (state.getValue(BERRIES)) {
level.setBlock(pos, state.setValue(PLANT_TYPE, LatticePlantType.NONE), 3);
return CaveVines.use(null, state, level, pos);
return CaveVines.use(null, state, level, pos) == InteractionResult.SUCCESS ? ItemInteractionResult.SUCCESS : ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} else if (PLANT_TYPE_TO_ITEM.containsKey(plantType)) {
Item item = PLANT_TYPE_TO_ITEM.get(plantType);
if (item != null) {
level.setBlock(pos, state.setValue(PLANT_TYPE, LatticePlantType.NONE), 3);
popResource(level, pos, new ItemStack(item));
level.playSound(null, pos, SoundEvents.VINE_BREAK, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
}
}
}
if (state.getValue(PLANT_TYPE) == LatticePlantType.NONE) {
ItemStack itemStack = player.getItemInHand(hand);
if (PLANT_TYPE_TO_ITEM.containsValue(itemStack.getItem())) {
if (PLANT_TYPE_TO_ITEM.containsValue(stack.getItem())) {
for (Map.Entry<LatticePlantType, Item> entry : PLANT_TYPE_TO_ITEM.entrySet()) {
if (entry.getValue() == itemStack.getItem()) {
if (entry.getValue() == stack.getItem()) {
level.setBlock(pos, state.setValue(PLANT_TYPE, entry.getKey()), 3);
level.playSound(null, pos, entry.getKey() == LatticePlantType.VINES ? SoundEvents.VINE_PLACE : SoundEvents.GRASS_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
}
}
}
}
return CaveVines.use(null, state, level, pos);
//return CaveVines.use(null, state, level, pos);
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.ItemInteractionResult;
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;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
if (state.getValue(LAYERS) > 1) {
level.setBlock(pos, state.setValue(LAYERS, state.getValue(LAYERS) - 1), 3);
Block.popResource(level, pos, this.asItem().getDefaultInstance());
//stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(hand));
stack.hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
level.playSound(player, pos, level.getBlockState(pos).getBlock().defaultBlockState().getSoundType().getBreakSound(), player.getSoundSource(), 1.0F, 1.0F);
return ItemInteractionResult.SUCCESS;
} else if (state.getValue(LAYERS) == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.DyeColor;
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.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand All @@ -20,16 +15,7 @@

import java.util.Map;

public class WallBlockBlock extends AbstractBlockBlock {
public static final MapCodec<WallBlockBlock> CODEC = RecordCodecBuilder.mapCodec(
(instance) -> instance.group(BlockBlock.Types.CODEC.fieldOf("type")
.forGetter(e -> e.type),propertiesCodec())
.apply(instance, WallBlockBlock::new));
@Override
protected MapCodec<WallBlockBlock> codec() {
return CODEC;
}

public class WallBlockBlock extends Block {

public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
private static final Map<Direction, VoxelShape> AABBS = Maps.newEnumMap(ImmutableMap.of(
Expand All @@ -38,29 +24,21 @@ protected MapCodec<WallBlockBlock> codec() {
Direction.EAST, Block.box(0.0, 4.0, 4.0, 8.0, 12.0, 12.0),
Direction.WEST, Block.box(8.0, 4.0, 4.0, 16.0, 12.0, 12.0)));

public WallBlockBlock(BlockBlock.Types type, Properties properties) {
super(type, properties);
public WallBlockBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
}

@Override
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return AABBS.get(blockState.getValue(FACING));
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
Direction dir = blockPlaceContext.getClickedFace();
if (dir.getAxis().isVertical()) return null;
return this.defaultBlockState().setValue(FACING, dir);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
BlockState blockState = this.defaultBlockState();
Level blockGetter = blockPlaceContext.getLevel();
BlockPos blockPos = blockPlaceContext.getClickedPos();
for (Direction direction : blockPlaceContext.getNearestLookingDirections()) {
if (!direction.getAxis().isHorizontal()) continue;
Direction direction2 = direction.getOpposite();
blockState = blockState.setValue(FACING, direction2);
if (blockGetter.getBlockState(blockPos.relative(direction)).canBeReplaced(blockPlaceContext)) continue;
return blockState;
}
return null;
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext) {
return AABBS.get(blockState.getValue(FACING));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public class BBBBlockStateProperties {
public static final BooleanProperty LAYER_2 = BooleanProperty.create("layer_2");
public static final BooleanProperty LAYER_3 = BooleanProperty.create("layer_3");
public static final BooleanProperty LAYER_4 = BooleanProperty.create("layer_4");
public static final IntegerProperty ROTATION_4 = IntegerProperty.create("rotation", 0, 3);
}
Loading

0 comments on commit 5c88625

Please sign in to comment.