Skip to content

Commit

Permalink
changed leaves to inherit leavesblock, added textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
lilypuree committed Feb 10, 2020
1 parent 1c75040 commit ab6c889
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 187 deletions.
184 changes: 94 additions & 90 deletions src/main/java/lilypuree/forest_tree/blocks/LeavesSlabBlock.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package lilypuree.forest_tree.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.SlabBlock;
import net.minecraft.block.*;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.pathfinding.PathType;
import net.minecraft.state.*;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.SlabType;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
Expand All @@ -22,45 +27,21 @@

import java.util.Random;

public class LeavesSlabBlock extends SlabBlock implements IShearable, ILeafBlock{
public static final IntegerProperty DISTANCE = BlockStateProperties.DISTANCE_1_7;
public static final BooleanProperty PERSISTENT = BlockStateProperties.PERSISTENT;
public class LeavesSlabBlock extends LeavesBlock implements IWaterLoggable {
public static final EnumProperty<SlabType> TYPE = BlockStateProperties.SLAB_TYPE;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape BOTTOM_SHAPE = Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D);
protected static final VoxelShape TOP_SHAPE = Block.makeCuboidShape(0.0D, 8.0D, 0.0D, 16.0D, 16.0D, 16.0D);

public LeavesSlabBlock(Block.Properties properties) {
super(properties);
this.setDefaultState(super.getDefaultState().with(DISTANCE, 7).with(PERSISTENT, Boolean.FALSE));
}

@Override
public boolean ticksRandomly(BlockState state) {
return state.get(DISTANCE) == 7 && !state.get(PERSISTENT);
}

@Override
public void randomTick(BlockState block, ServerWorld worldIn, BlockPos pos, Random randomIn) {
if (!block.get(PERSISTENT) && block.get(DISTANCE) == 7) {
spawnDrops(block, worldIn, pos);
worldIn.removeBlock(pos, false);
}
}

@Override
public void tick(BlockState block, ServerWorld worldIn, BlockPos pos, Random random) {
worldIn.setBlockState(pos, updateDistance(block, worldIn, pos), 3);
}

@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
stateIn = super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
int i = getDistance(facingState) + 1;
if (i != 1 || stateIn.get(DISTANCE) != i) {
worldIn.getPendingBlockTicks().scheduleTick(currentPos, this, 1);
}

return stateIn;
this.setDefaultState(super.getDefaultState().with(TYPE, SlabType.BOTTOM).with(WATERLOGGED, Boolean.FALSE));
}

public int getOpacity(BlockState state, IBlockReader worldIn, BlockPos pos) {
if(state.get(TYPE) != SlabType.DOUBLE){
return 0;
}
return 1;
}

Expand All @@ -69,75 +50,98 @@ public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, Blo
return true;
}

protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(new IProperty[]{TYPE, WATERLOGGED});
}

public boolean func_220074_n(BlockState state) {
return state.get(TYPE) != SlabType.DOUBLE;
}

private static BlockState updateDistance(BlockState block, IWorld worldIn, BlockPos pos) {
int i = 7;

try (BlockPos.PooledMutable pooledMutable = BlockPos.PooledMutable.retain()) {
for(Direction direction : Direction.values()) {
pooledMutable.setPos(pos).move(direction);
i = Math.min(i, getDistance(worldIn.getBlockState(pooledMutable)) + 1);
if (i == 1) {
break;
}
}
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
SlabType slabtype = state.get(TYPE);
switch(slabtype) {
case DOUBLE:
return VoxelShapes.fullCube();
case TOP:
return TOP_SHAPE;
default:
return BOTTOM_SHAPE;
}

return block.with(DISTANCE, Integer.valueOf(i));
}

private static int getDistance(BlockState neighbor) {
if (BlockTags.LOGS.contains(neighbor.getBlock())) {
return 0;
//partly copied from slabblock
public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState state = super.getStateForPlacement(context);
BlockPos blockpos = context.getPos();
BlockState blockstate = context.getWorld().getBlockState(blockpos);
if (blockstate.getBlock() == this) {
return blockstate.with(TYPE, SlabType.DOUBLE).with(WATERLOGGED, Boolean.valueOf(false));
} else {
return neighbor.getBlock() instanceof LeavesBlock ? neighbor.get(DISTANCE) : 7;
IFluidState ifluidstate = context.getWorld().getFluidState(blockpos);
BlockState blockstate1 = this.getDefaultState().with(TYPE, SlabType.BOTTOM).with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
Direction direction = context.getFace();
return direction != Direction.DOWN && (direction == Direction.UP || !(context.getHitVec().y - (double)blockpos.getY() > 0.5D)) ? blockstate1 : blockstate1.with(TYPE, SlabType.TOP);
}
}

@Override
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (worldIn.isRainingAt(pos.up())) {
if (rand.nextInt(15) == 1) {
BlockPos blockpos = pos.down();
BlockState blockstate = worldIn.getBlockState(blockpos);
if (!blockstate.isSolid() || !blockstate.isSolidSide(worldIn, blockpos, Direction.UP)) {
double d0 = (double)((float)pos.getX() + rand.nextFloat());
double d1 = (double)pos.getY() - 0.05D;
double d2 = (double)((float)pos.getZ() + rand.nextFloat());
worldIn.addParticle(ParticleTypes.DRIPPING_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D);
//copied from SlabBlock.
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) {
ItemStack itemstack = useContext.getItem();
SlabType slabtype = state.get(TYPE);
if (slabtype != SlabType.DOUBLE && itemstack.getItem() == this.asItem()) {
if (useContext.replacingClickedOnBlock()) {
boolean flag = useContext.getHitVec().y - (double)useContext.getPos().getY() > 0.5D;
Direction direction = useContext.getFace();
if (slabtype == SlabType.BOTTOM) {
return direction == Direction.UP || flag && direction.getAxis().isHorizontal();
} else {
return direction == Direction.DOWN || !flag && direction.getAxis().isHorizontal();
}
} else {
return true;
}
} else {
return false;
}
}

public boolean causesSuffocation(BlockState block, IBlockReader blockReader, BlockPos pos) {
return false;
public IFluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(DISTANCE, PERSISTENT);
public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) {
return state.get(TYPE) != SlabType.DOUBLE ? IWaterLoggable.super.receiveFluid(worldIn, pos, state, fluidStateIn) : false;
}

public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState state = super.getStateForPlacement(context);
assert state != null;
return updateDistance(state.with(PERSISTENT, Boolean.valueOf(true)), context.getWorld(), context.getPos());
public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) {
return state.get(TYPE) != SlabType.DOUBLE ? IWaterLoggable.super.canContainFluid(worldIn, pos, state, fluidIn) : false;
}

@Override
public boolean isFoliage(BlockState state, IWorldReader world, BlockPos pos) {
return true;
}

@Override
public boolean isFlammable(BlockState state, IBlockReader world, BlockPos pos, Direction face) {
return true;
}

@Override
public int getFlammability(BlockState state, IBlockReader world, BlockPos pos, Direction face) {
return 60;
/**
* Update the provided state given the provided neighbor facing and neighbor state, returning a new state.
* For example, fences make their connections to the passed in state if possible, and wet concrete powder immediately
* returns its solidified counterpart.
* Note that this method should ideally consider only the specific face passed in.
*/
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (stateIn.get(WATERLOGGED)) {
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
}

public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) {
switch(type) {
case LAND:
return false;
case WATER:
return worldIn.getFluidState(pos).isTagged(FluidTags.WATER);
case AIR:
return false;
default:
return false;
}
}
}
62 changes: 0 additions & 62 deletions src/main/java/lilypuree/forest_tree/blocks/LeavesStairBlock.java

This file was deleted.

Loading

0 comments on commit ab6c889

Please sign in to comment.