Java Code Examples for net.minecraft.init.Blocks#FARMLAND

The following examples show how to use net.minecraft.init.Blocks#FARMLAND . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Return true to set given position as destination
 */
protected boolean shouldMoveTo(World worldIn, BlockPos pos)
{
    Block block = worldIn.getBlockState(pos).getBlock();

    if (block == Blocks.FARMLAND || block == BlockLoader.TOFUFARMLAND)
    {
        pos = pos.up();
        IBlockState iblockstate = worldIn.getBlockState(pos);
        block = iblockstate.getBlock();

        if (block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate) && this.wantsToReapStuff && (this.currentTask == 0 || this.currentTask < 0))
        {
            this.currentTask = 0;
            return true;
        }

        if (iblockstate.getMaterial() == Material.AIR && this.hasFarmItem && (this.currentTask == 1 || this.currentTask < 0))
        {
            this.currentTask = 1;
            return true;
        }
    }

    return false;
}
 
Example 2
Source Project: TofuCraftReload   File: BlockTofuFarmLand.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
    switch (side)
    {
        case UP:
            return true;
        case NORTH:
        case SOUTH:
        case WEST:
        case EAST:
            IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
            Block block = iblockstate.getBlock();
            return !iblockstate.isOpaqueCube() && block != Blocks.FARMLAND && block != Blocks.GRASS_PATH;
        default:
            return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
    }
}
 
Example 3
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 6 votes vote down vote up
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
    if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
    {
        int i = this.getAge(state);
        if (i >= 4 && worldIn.getBlockState(pos.down()).getBlock() == Blocks.FARMLAND &&worldIn.isAirBlock(pos.up()))
	    	  worldIn.setBlockState(pos.up(), this.withAge(0), 2);
        if (i < this.getMaxAge())
        {
        	
            float f = getGrowthChance(this, worldIn, pos);

            if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int)(25.0F / f) + 1) == 0))
            {
                worldIn.setBlockState(pos, this.withAge(i + 1), 2);
                net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
            }
        }
    }
}
 
Example 4
Source Project: EmergingTechnology   File: PlantHelper.java    License: MIT License 6 votes vote down vote up
public static boolean isValidSoil(World world, BlockPos pos) {
    IBlockState soilBlockTarget = world.getBlockState(pos);
    Block block = soilBlockTarget.getBlock();

    if (block.isFertile(world, pos)) {
        return true;
    }

    if (block == ModBlocks.hydroponic) {
        if (soilBlockTarget.getActualState(world, pos).getValue(Hydroponic.HAS_WATER)) {
            return true;
        }
    }

    if (block == Blocks.FARMLAND) {
        if (soilBlockTarget.getActualState(world, pos).getValue(BlockFarmland.MOISTURE) > 0) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 5 votes vote down vote up
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction,
		IPlantable plantable) {
       return state.getBlock() == Blocks.FARMLAND||
       	(this.getAge(state)>=4&&state.getBlock() instanceof BlockHighCrop 
       		&&world.getBlockState(pos.down()).getBlock() == Blocks.FARMLAND);
}
 
Example 6
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 5 votes vote down vote up
public void grow(World worldIn, BlockPos pos, IBlockState state)
{

    int i = this.getAge(state) + this.getBonemealAgeIncrease(worldIn);
    int j = this.getMaxAge();
	if(i>= 4 && worldIn.getBlockState(pos.down()).getBlock() == Blocks.FARMLAND 
			&& worldIn.isAirBlock(pos.up()))
		worldIn.setBlockState(pos.up(), this.withAge(0), 2);
    if (i > j)
    {
        i = j;
    }

    worldIn.setBlockState(pos, this.withAge(i), 2);
}
 
Example 7
Source Project: TofuCraftReload   File: BlockSoybean.java    License: MIT License 4 votes vote down vote up
protected boolean canSustainBush(IBlockState state)
{
    return state.getBlock() == Blocks.FARMLAND || state.getBlock() == BlockLoader.TOFUFARMLAND;
}
 
Example 8
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 4 votes vote down vote up
@Override
protected boolean canSustainBush(IBlockState state)
{
    return state.getBlock() == Blocks.FARMLAND||state.getBlock() instanceof BlockHighCrop;
}
 
Example 9
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 4 votes vote down vote up
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
	IBlockState soil = worldIn.getBlockState(pos.down());
	return super.canPlaceBlockAt(worldIn, pos)&&soil.getBlock() == Blocks.FARMLAND;
}
 
Example 10
@Nullable
protected ItemStack getStateToItemOverride(IBlockState state)
{
    Block block = state.getBlock();

    if (block == Blocks.PISTON_HEAD ||
        block == Blocks.PISTON_EXTENSION ||
        block == Blocks.PORTAL ||
        block == Blocks.END_PORTAL ||
        block == Blocks.END_GATEWAY)
    {
        return ItemStack.EMPTY;
    }
    else if (block == Blocks.FARMLAND)
    {
        return new ItemStack(Blocks.DIRT);
    }
    else if (block == Blocks.GRASS_PATH)
    {
        return new ItemStack(Blocks.GRASS);
    }
    else if (block == Blocks.BROWN_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.BROWN_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.RED_MUSHROOM_BLOCK)
    {
        return new ItemStack(Blocks.RED_MUSHROOM_BLOCK);
    }
    else if (block == Blocks.LAVA)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.LAVA_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block == Blocks.WATER)
    {
        if (state.getValue(BlockLiquid.LEVEL) == 0)
        {
            return new ItemStack(Items.WATER_BUCKET);
        }
        else
        {
            return ItemStack.EMPTY;
        }
    }
    else if (block instanceof BlockDoor && state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockBed && state.getValue(BlockBed.PART) == BlockBed.EnumPartType.HEAD)
    {
        return ItemStack.EMPTY;
    }
    else if (block instanceof BlockDoublePlant && state.getValue(BlockDoublePlant.HALF) == BlockDoublePlant.EnumBlockHalf.UPPER)
    {
        return ItemStack.EMPTY;
    }

    return null;
}
 
Example 11
Source Project: TFC2   File: ModuleFood.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void init(int healAmount, float saturation, Block crops, Block soil)
{
	if(soil == Blocks.FARMLAND)
		soil = TFCBlocks.Farmland;
}
 
Example 12
Source Project: AgriCraft   File: PlayerInteractEventHandler.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void waterPadCreation(PlayerInteractEvent.RightClickBlock event) {
    // Fetch held item.
    final ItemStack stack = event.getItemStack();

    // Check if holding shovel.
    if (!StackHelper.isValid(stack, ItemSpade.class)) {
        return;
    }

    // Fetch world information.
    final BlockPos pos = event.getPos();
    final World world = event.getWorld();
    final IBlockState state = world.getBlockState(pos);

    // Fetch the block at the location.
    final Block block = state.getBlock();

    // Test that clicked block was farmland.
    if (block != Blocks.FARMLAND) {
        return;
    }

    // Deny the event.
    event.setUseBlock(Event.Result.DENY);
    event.setUseItem(Event.Result.DENY);
    event.setResult(Event.Result.DENY);

    // If we are on the client side we are done.
    if (event.getSide().isClient()) {
        return;
    }

    // Fetch the player.
    final EntityPlayer player = event.getEntityPlayer();

    // Create the new block on the server side.
    world.setBlockState(pos, AgriBlocks.getInstance().WATER_PAD.getDefaultState(), 3);

    // Damage player's tool if not in creative.
    if (!player.capabilities.isCreativeMode) {
        stack.damageItem(1, player);
    }
}