Skip to content

Commit

Permalink
Merge pull request #1172 from bijimio/14.1-features
Browse files Browse the repository at this point in the history
Initial attempt to make tall blocks waterloggable, Created Sports Bra Texture.
  • Loading branch information
LtxProgrammer authored Nov 18, 2024
2 parents eba1ab1 + 4277cf0 commit ffb868a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import net.ltxprogrammer.changed.init.ChangedBlocks;
import net.ltxprogrammer.changed.init.ChangedSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
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.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
Expand All @@ -23,22 +29,26 @@
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.DoubleBlockHalf;
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.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

public class CardboardBoxTall extends AbstractCustomShapeTallEntityBlock implements SeatableBlock {
public class CardboardBoxTall extends AbstractCustomShapeTallEntityBlock implements SeatableBlock, SimpleWaterloggedBlock {
public static BooleanProperty OPEN = BlockStateProperties.OPEN;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public CardboardBoxTall() {
super(BlockBehaviour.Properties.of(Material.WOOL).strength(1.0F).isSuffocating(ChangedBlocks::never).isViewBlocking(ChangedBlocks::never)
.sound(SoundType.SCAFFOLDING));
this.registerDefaultState(this.stateDefinition.any().setValue(HALF, DoubleBlockHalf.LOWER).setValue(OPEN, false));
this.registerDefaultState(this.stateDefinition.any().setValue(HALF, DoubleBlockHalf.LOWER).setValue(WATERLOGGED, false).setValue(OPEN, false));
}

protected BlockEntity getBlockEntityForBlock(BlockGetter level, BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -73,9 +83,70 @@ public boolean canEntityDestroy(BlockState state, BlockGetter level, BlockPos po
return super.canEntityDestroy(state, level, pos, entity);
}

public PushReaction getPistonPushReaction(BlockState p_52814_) {
return PushReaction.DESTROY;
}

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

public BlockState updateShape(BlockState state, Direction direction, BlockState dState, LevelAccessor level, BlockPos pos) {
if (state.getValue(WATERLOGGED)) {
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
}

if (isDoubleBlock(state)) {
DoubleBlockHalf half = state.getValue(HALF);
if ((direction.getAxis() != Direction.Axis.Y) || ((half == DoubleBlockHalf.LOWER) != (direction == Direction.UP)) || ((dState.getBlock() == this) && (dState.getValue(HALF) != half))) {
if ((half != DoubleBlockHalf.LOWER) || (direction != Direction.DOWN) || state.canSurvive(level, pos)) {
return state;
}
}

return Blocks.AIR.defaultBlockState();
}

return state;
}

private boolean isDoubleBlock(BlockState state) {
return state.hasProperty(HALF);
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Level level = context.getLevel();
BlockPos pos = context.getClickedPos();
FluidState fluidState = level.getFluidState(pos);
if (pos.getY() < level.getHeight() - 1) {
if (level.getBlockState(pos.above()).canBeReplaced(context)) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite())
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}

return null;
}

@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
if (!isDoubleBlock(state)) {
return true;
}

if (state.getValue(HALF) == DoubleBlockHalf.LOWER) {
return true;
}

BlockState below = level.getBlockState(pos.below());
return below.getBlock() == this && below.getValue(HALF) == DoubleBlockHalf.LOWER;
}

public VoxelShape getInteractionShape(BlockState p_60547_, BlockGetter p_60548_, BlockPos p_60549_) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ffb868a

Please sign in to comment.