package net.tropicraft.core.common.block;

import net.minecraft.block.Block;
import net.minecraft.block.FallingBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.IFluidState;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockTropicraftSand extends FallingBlock {
    public static final BooleanProperty UNDERWATER = BooleanProperty.create("underwater");

    public BlockTropicraftSand(final Properties properties) {
        super(properties);
        this.setDefaultState(this.getDefaultState().with(UNDERWATER, false));
    }

    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(UNDERWATER);
    }

    @Override
    public void onEntityWalk(final World world, final BlockPos pos, final Entity entity) {
        final BlockState state = world.getBlockState(pos);

        // If not black sands
        if (state.getBlock() != TropicraftBlocks.VOLCANIC_SAND.get()) {
            return;
        }

        if (entity instanceof PlayerEntity) {
            final PlayerEntity player = (PlayerEntity)entity;
            final ItemStack stack = player.getItemStackFromSlot(EquipmentSlotType.FEET);

            // If player isn't wearing anything on their feetsies
            if (stack.isEmpty()) {
                player.attackEntityFrom(DamageSource.LAVA, 0.5F);
            }
        } else {
            entity.attackEntityFrom(DamageSource.LAVA, 0.5F);
        }
    }

    @Override
    public BlockState getStateForPlacement(final BlockItemUseContext context) {
        final IFluidState upState = context.getWorld().getFluidState(context.getPos().up());
        boolean waterAbove = false;
        if (!upState.isEmpty()) {
            waterAbove = true;
        }
        return this.getDefaultState().with(UNDERWATER, waterAbove);
    }

    @Override
    public void neighborChanged(final BlockState state, final World world, final BlockPos pos, final Block block, final BlockPos pos2, boolean neighborChanged) {
        final IFluidState upState = world.getFluidState(pos.up());
        if (!upState.isEmpty()) {
            world.setBlockState(pos, state.with(UNDERWATER, true), 2);
        }
        super.neighborChanged(state, world, pos, block, pos2, neighborChanged);
    }
}

@@ -97,28 +97,61 @@
 t.block.
-Falling
+BlockState;%0Aimport net.minecraft.block.
 Block
+s
 ;%0Aimport
@@ -167,34 +167,36 @@
 craft.block.
+Falling
 Block
-State
 ;%0Aimport net
@@ -571,16 +571,53 @@
 Source;%0A
+import net.minecraft.util.Direction;%0A
 import n
@@ -676,21 +676,107 @@
 t.world.
-World
+IBlockReader;%0Aimport net.minecraft.world.World;%0Aimport net.minecraftforge.common.IPlantable
 ;%0A%0Apubli
@@ -1227,32 +1227,268 @@
 DERWATER);%0A    %7D
+%0A    %0A    @Override%0A    public boolean canSustainPlant(BlockState state, IBlockReader world, BlockPos pos, Direction facing, IPlantable plantable) %7B%0A        return Blocks.SAND.canSustainPlant(state, world, pos, facing, plantable);%0A    %7D
 %0A%0A    @Override%0A

Fix tropical sands not supporting sugar cane and other sand crops